Skip to content

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

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -99,7 +99,7 @@ public RuntimeArtifactDto generateGatewayArtifact(List<APIRuntimeArtifactDto> ap
String openApiDefinition = ImportUtils.loadSwaggerFile(extractedFolderPath);
apiProduct.setDefinition(openApiDefinition);
gatewayAPIDTO = TemplateBuilderUtil.retrieveGatewayAPIDto(apiProduct, environment,
tenantDomain, extractedFolderPath);
tenantDomain, extractedFolderPath, openApiDefinition);
} 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 @@ -712,7 +712,7 @@ public static GatewayAPIDTO retrieveGatewayAPIDtoForStreamingAPI(API api, Enviro
}

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

List<ClientCertificateDTO> clientCertificatesDTOListProduction =
Expand All @@ -721,12 +721,29 @@ 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());
APIDefinition parser = OASParserUtil.getOASParser(apiDefinition);
Set<URITemplate> uriTemplates = Collections.emptySet();
if (parser != null) {
uriTemplates = parser.getURITemplates(apiDefinition);
}
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())) {
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 @@ -800,8 +817,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, null);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public VelocityContext getContext() {
String resourceKey =
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