Skip to content

Commit

Permalink
- Fix the filename extension issue
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Nov 5, 2024
1 parent d478f7e commit b8136c5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public OAS3xSpecification() {

@Override
public APISpecType getAPIDefinitionType() throws AppException {
if (this.mapper.getFactory() instanceof YAMLFactory) {
if (mapper.getFactory() instanceof YAMLFactory) {
return APISpecType.OPEN_API_30_YAML;
}
return APISpecType.OPEN_API_30;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Swagger2xSpecification() {

@Override
public APISpecType getAPIDefinitionType() throws AppException {
if (this.mapper.getFactory() instanceof YAMLFactory) {
if (mapper.getFactory() instanceof YAMLFactory) {
return APISpecType.SWAGGER_API_20_YAML;
}
return APISpecType.SWAGGER_API_20;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.axway.apim.api.model.CaCert;
import com.axway.apim.api.model.Image;
import com.axway.apim.api.specification.APISpecification;
import com.axway.apim.api.specification.OAS3xSpecification;
import com.axway.apim.api.specification.Swagger2xSpecification;
import com.axway.apim.api.specification.WSDLSpecification;
import com.axway.apim.lib.EnvironmentProperties;
import com.axway.apim.lib.error.AppException;
Expand All @@ -22,6 +24,7 @@
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -59,18 +62,7 @@ public void saveAPILocally(ObjectMapper mapper, ExportAPI exportAPI, String conf
throw new AppException("Backend API Definition is not available for the API : " + exportAPI.getName() + ", hence use the option -useFEAPIDefinition to export API", ErrorCode.BACKEND_API_DEF_NA);
return;
}
String targetFile = null;
try {
String fileName = Utils.replaceSpecialChars(exportAPI.getName()) + apiDef.getAPIDefinitionType().getFileExtension();
targetFile = localFolder.getCanonicalPath() + "/" + fileName;
if (!(apiDef instanceof WSDLSpecification && EnvironmentProperties.RETAIN_BACKEND_URL) && (!EnvironmentProperties.PRINT_CONFIG_CONSOLE)) {
Object spec = mapper.readValue(apiDef.getApiSpecificationContent(), Object.class);
mapper.writerWithDefaultPrettyPrinter().writeValue(new File(targetFile), spec);
exportAPI.getAPIDefinition().setApiSpecificationFile(fileName);
}
} catch (IOException e) {
throw new AppException("Can't save API-Definition locally to file: " + targetFile, ErrorCode.UNXPECTED_ERROR, e);
}
writeSpec(mapper, apiDef, exportAPI, localFolder);
Image image = exportAPI.getAPIImage();
if (image != null && (!EnvironmentProperties.PRINT_CONFIG_CONSOLE)) {
writeBytesToFile(image.getImageContent(), localFolder + File.separator + image.getBaseFilename());
Expand Down Expand Up @@ -151,6 +143,32 @@ private void storePrivateCerts(File localFolder, List<AuthenticationProfile> aut
}
}

public void writeSpec(ObjectMapper mapper, APISpecification apiDef, ExportAPI exportAPI, File localFolder) throws AppException {
String targetFile = null;
try {
if (!(apiDef instanceof WSDLSpecification && EnvironmentProperties.RETAIN_BACKEND_URL) && (!EnvironmentProperties.PRINT_CONFIG_CONSOLE)) {
String fileName = Utils.replaceSpecialChars(exportAPI.getName());
String fileExtension = apiDef.getAPIDefinitionType().getFileExtension();
if(apiDef instanceof Swagger2xSpecification || apiDef instanceof OAS3xSpecification){
if (mapper.getFactory() instanceof YAMLFactory) {
fileExtension = APISpecification.APISpecType.SWAGGER_API_20_YAML.getFileExtension();
}else {
fileExtension = APISpecification.APISpecType.SWAGGER_API_20.getFileExtension();
}
targetFile = localFolder.getCanonicalPath() + "/" + fileName + fileExtension;
Object spec = mapper.readValue(apiDef.getApiSpecificationContent(), Object.class);
mapper.writerWithDefaultPrettyPrinter().writeValue(new File(targetFile), spec);
}else {
targetFile = localFolder.getCanonicalPath() + "/" + fileName + fileExtension;
writeBytesToFile(apiDef.getApiSpecificationContent(), targetFile);
}
exportAPI.getAPIDefinition().setApiSpecificationFile(fileName);
}
} catch (IOException e) {
throw new AppException("Can't save API-Definition locally to file: " + targetFile, ErrorCode.UNXPECTED_ERROR, e);
}
}


public void writeContent(ObjectMapper mapper, ExportAPI exportAPI, File localFolder, String configFile) throws AppException {
try {
Expand Down

0 comments on commit b8136c5

Please sign in to comment.