Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Methodlevelscope #523

Merged
merged 6 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,8 @@ public APISpecification setFilterConfig(APISpecificationFilter filterConfig) {
this.filterConfig = filterConfig;
return this;
}

public ObjectMapper getMapper() {
return mapper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +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;
}
writeSpec(mapper, apiDef, exportAPI, localFolder);
writeSpec(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 @@ -143,22 +143,23 @@ private void storePrivateCerts(File localFolder, List<AuthenticationProfile> aut
}
}

public void writeSpec(ObjectMapper mapper, APISpecification apiDef, ExportAPI exportAPI, File localFolder) throws AppException {
public void writeSpec(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 (apiDef instanceof Swagger2xSpecification || apiDef instanceof OAS3xSpecification) {
ObjectMapper mapper = apiDef.getMapper();
if (mapper.getFactory() instanceof YAMLFactory) {
fileExtension = APISpecification.APISpecType.SWAGGER_API_20_YAML.getFileExtension();
}else {
fileExtension = APISpecification.APISpecType.SWAGGER_API_20.getFileExtension();
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 {
} else {
targetFile = localFolder.getCanonicalPath() + "/" + fileName + fileExtension;
writeBytesToFile(apiDef.getApiSpecificationContent(), targetFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.axway.apim.api.API;
import com.axway.apim.api.model.*;
import com.axway.apim.config.model.APISecurity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import java.util.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@JsonPropertyOrder({"name", "path", "state", "version", "organization", "apiSpecification", "summary", "descriptionType", "descriptionManual", "vhost", "remoteHost",
"backendBasepath", "image", "inboundProfiles", "outboundProfiles", "securityProfiles", "authenticationProfiles", "tags", "customProperties",
Expand All @@ -16,12 +18,10 @@ public class APIConfig {
public static final String DEFAULT = "_default";
private final API api;
private final String apiDefinition;
private final Map<String, Object> securityProfiles;

public APIConfig(API api, String apiDefinition, Map<String, Object> securityProfiles) {
public APIConfig(API api, String apiDefinition) {
this.api = api;
this.apiDefinition = apiDefinition;
this.securityProfiles = securityProfiles;
}

public Map<String, OutboundProfile> getOutboundProfiles() {
Expand All @@ -46,15 +46,8 @@ public Map<String, OutboundProfile> getOutboundProfiles() {
}


public List<Map<String, Object>> getSecurityProfiles() {
if (securityProfiles.size() == 1) {
List<APISecurity> apiSecurities = (List<APISecurity>) securityProfiles.get("devices");
if (apiSecurities.get(0).getType().equals(DeviceType.passThrough.getName()))
return Collections.emptyList();
}
List<Map<String, Object>> list = new ArrayList<>();
list.add(securityProfiles);
return list;
public List<SecurityProfile> getSecurityProfiles() {
return api.getSecurityProfiles();
}

public String getPath() {
Expand Down
Loading
Loading