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

Add support for resources with mock implementations in API Products #12754

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -102,7 +102,7 @@ public RuntimeArtifactDto generateGatewayArtifact(List<APIRuntimeArtifactDto> ap
ImportUtils.retrieveValidatedSwaggerDefinitionFromArchive(extractedFolderPath);
apiProduct.setDefinition(apiDefinitionValidationResponse.getContent());
gatewayAPIDTO = TemplateBuilderUtil.retrieveGatewayAPIDto(apiProduct, environment,
tenantDomain, extractedFolderPath);
tenantDomain, extractedFolderPath, apiDefinitionValidationResponse);
} else {
APIDTO apidto = ImportUtils.retrievedAPIDto(extractedFolderPath);
API api = APIMappingUtil.fromDTOtoAPI(apidto, apidto.getProvider());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,8 @@ public static GatewayAPIDTO retrieveGatewayAPIDtoForStreamingAPI(API api, Enviro
}

public static GatewayAPIDTO retrieveGatewayAPIDto(APIProduct apiProduct, Environment environment,
String tenantDomain, String extractedFolderPath)
String tenantDomain, String extractedFolderPath,
APIDefinitionValidationResponse apiDefinitionValidationResponse)
throws APIManagementException, XMLStreamException, APITemplateException {

List<ClientCertificateDTO> clientCertificatesDTOListProduction =
Expand All @@ -683,12 +684,33 @@ public static GatewayAPIDTO retrieveGatewayAPIDto(APIProduct apiProduct, Environ
ImportUtils.retrieveClientCertificates(extractedFolderPath, APIConstants.API_KEY_TYPE_SANDBOX);
Map<String, APIDTO> apidtoMap = retrieveAssociatedApis(extractedFolderPath);
Map<String, APIDTO> associatedAPIsMap = convertAPIIdToDto(apidtoMap.values());
Set<URITemplate> uriTemplates = Collections.emptySet();
if (apiDefinitionValidationResponse.isValid()) {
APIDefinition parser = apiDefinitionValidationResponse.getParser();
String definition = apiDefinitionValidationResponse.getJsonContent();
if (parser != null) {
uriTemplates = parser.getURITemplates(definition);
}
}

for (APIProductResource productResource : apiProduct.getProductResources()) {
String apiId = productResource.getApiId();
APIDTO apidto = associatedAPIsMap.get(apiId);
if (apidto != null) {
API api = APIMappingUtil.fromDTOtoAPI(apidto, apidto.getProvider());
productResource.setApiIdentifier(api.getId());
if (APIConstants.IMPLEMENTATION_TYPE_INLINE.equalsIgnoreCase(api.getImplementation())) {
// Sync URITemplate mediation scripts if matches are found
for (URITemplate uriTemplate : uriTemplates) {
URITemplate template = productResource.getUriTemplate();
if (template.getHTTPVerb().equalsIgnoreCase(uriTemplate.getHTTPVerb()) &&
template.getUriTemplate().equals(uriTemplate.getUriTemplate())) {
template.setMediationScript(uriTemplate.getMediationScript());
template.setMediationScripts(uriTemplate.getHTTPVerb(), uriTemplate.getMediationScript());
break;
}
}
}
if (api.isAdvertiseOnly()) {
productResource.setEndpointConfig(APIUtil.generateEndpointConfigForAdvertiseOnlyApi(api));
} else {
Expand Down Expand Up @@ -762,8 +784,9 @@ private static GatewayAPIDTO createAPIGatewayDTOtoPublishAPI(Environment environ
// check the endpoint type
if (!StringUtils.isEmpty(api.getEndpointConfig())) {
JsonObject endpointConfObj = JsonParser.parseString(api.getEndpointConfig()).getAsJsonObject();
if (!APIConstants.ENDPOINT_TYPE_SEQUENCE.equals(
endpointConfObj.get(API_ENDPOINT_CONFIG_PROTOCOL_TYPE).getAsString())) {
if (!APIConstants.ENDPOINT_TYPE_SEQUENCE.equals(endpointConfObj.get(API_ENDPOINT_CONFIG_PROTOCOL_TYPE)
.getAsString()) && !APIConstants.IMPLEMENTATION_TYPE_INLINE.equalsIgnoreCase(
api.getImplementation())) {
addEndpoints(api, apiTemplateBuilder, productAPIDto);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public VelocityContext getContext() {
resource.getApiIdentifier() + ":" + resource.getUriTemplate().getUriTemplate();
if (resourceKey.equals(productResourceKey)) {
resource.getUriTemplate().setHttpVerbs(uriTemplate.getHTTPVerb());
resource.getUriTemplate()
.setMediationScripts(uriTemplate.getHTTPVerb(), uriTemplate.getMediationScript());
}
}
} else {
Expand Down
Loading