From 88bb1d0c00a5c6ced3f1ccc683f54a2fc8a38c13 Mon Sep 17 00:00:00 2001 From: dushani Date: Tue, 25 Jul 2023 13:01:53 +0530 Subject: [PATCH 1/6] fix https://github.com/wso2/api-manager/issues/1831. --- .../wso2/carbon/apimgt/impl/APIConstants.java | 3 + .../apimgt/impl/definitions/OAS2Parser.java | 111 +++++++-- .../apimgt/impl/definitions/OAS3Parser.java | 121 +++++++++- .../impl/definitions/OASParserUtil.java | 211 +++++++++++++++++- 4 files changed, 416 insertions(+), 30 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java index a6a33062ac1b..f3f895b6749c 100755 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java @@ -1570,6 +1570,9 @@ private ConfigParameters() { public static final String SWAGGER_IS_MISSING_MSG = "swagger is missing"; public static final String OPENAPI_IS_MISSING_MSG = "openapi is missing"; public static final String SWAGGER_X_SCOPES_BINDINGS = "x-scopes-bindings"; + public static final String SWAGGER_X_BASIC_AUTH_SCOPES = "x-scopes"; + public static final String SWAGGER_X_BASIC_AUTH_RESOURCE_SCOPES = "x-basic-auth-scopes"; + public static final String OPENAPI_SECURITY_SCHEMA_KEY = "default"; //swagger v1.2 constants public static final String SWAGGER_RESOURCES = "resources"; diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS2Parser.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS2Parser.java index 568a9ff25237..278c602899d0 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS2Parser.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS2Parser.java @@ -43,8 +43,10 @@ import io.swagger.models.RefResponse; import io.swagger.models.Response; import io.swagger.models.Scheme; -import io.swagger.models.SecurityRequirement; import io.swagger.models.Swagger; +import io.swagger.models.auth.ApiKeyAuthDefinition; +import io.swagger.models.auth.BasicAuthDefinition; +import io.swagger.models.auth.In; import io.swagger.models.auth.OAuth2Definition; import io.swagger.models.auth.SecuritySchemeDefinition; import io.swagger.models.parameters.PathParameter; @@ -895,25 +897,11 @@ public String getOASVersion(String oasDefinition) { * @param swaggerData Swagger related data */ private void updateSwaggerSecurityDefinition(Swagger swagger, SwaggerData swaggerData, String authUrl) { + OAuth2Definition oAuth2Definition = new OAuth2Definition().implicit(authUrl); - Set scopes = swaggerData.getScopes(); - if (scopes != null && !scopes.isEmpty()) { - Map scopeBindings = new HashMap<>(); - for (Scope scope : scopes) { - String description = scope.getDescription() != null ? scope.getDescription() : ""; - oAuth2Definition.addScope(scope.getKey(), description); - String roles = (StringUtils.isNotBlank(scope.getRoles()) - && scope.getRoles().trim().split(",").length > 0) ? scope.getRoles() : StringUtils.EMPTY; - scopeBindings.put(scope.getKey(), roles); - } - oAuth2Definition.setVendorExtension(APIConstants.SWAGGER_X_SCOPES_BINDINGS, scopeBindings); - } + OASParserUtil.setScopesFromAPIToSecurityScheme(swaggerData, oAuth2Definition); swagger.addSecurityDefinition(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY, oAuth2Definition); - if (swagger.getSecurity() == null) { - SecurityRequirement securityRequirement = new SecurityRequirement(); - securityRequirement.setRequirements(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY, new ArrayList()); - swagger.addSecurity(securityRequirement); - } + OASParserUtil.addSecurityRequirementToSwagger(swagger, SWAGGER_APIM_DEFAULT_SECURITY); } /** @@ -1328,10 +1316,95 @@ private String updateSwaggerSecurityDefinitionForStore(Swagger swagger, SwaggerD } else { authUrl = (hostsWithSchemes.get(APIConstants.HTTP_PROTOCOL)).concat("/authorize"); } - updateSwaggerSecurityDefinition(swagger, swaggerData, authUrl); + updateSwaggerSecurityDefinitionForStore(swagger, swaggerData, authUrl); return getSwaggerJsonString(swagger); } + + /** + * Update Swagger security definition for dev portal only. + * + * @param swagger Swagger + * @param swaggerData SwaggerData + * @param authUrl Authorization URL + */ + private void updateSwaggerSecurityDefinitionForStore(Swagger swagger, SwaggerData swaggerData, String authUrl) { + + // Get the security defined for the current API. + List secList = swaggerData.getSecurity() != null ? Arrays.asList(swaggerData.getSecurity().split(",")) + : new ArrayList<>(); + if (secList.isEmpty() || secList.contains(APIConstants.DEFAULT_API_SECURITY_OAUTH2)) { + // Add oauth to global security requirement to the OAS definition. + if (log.isDebugEnabled()) { + log.debug("Updating the Swagger definition with default oauth2 security of API: " + swaggerData.getTitle() + + " Version: " + swaggerData.getVersion()); + } + OASParserUtil.addSecurityRequirementToSwagger(swagger, APIConstants.SWAGGER_APIM_DEFAULT_SECURITY); + OAuth2Definition oAuth2Definition = new OAuth2Definition().implicit(authUrl); + OASParserUtil.setScopesFromAPIToSecurityScheme(swaggerData, oAuth2Definition); + swagger.addSecurityDefinition(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY, oAuth2Definition); + } + // If the Basic Auth security is in API, add basic security to the OAS definition. + if (secList.contains(APIConstants.API_SECURITY_BASIC_AUTH)) { + if (log.isDebugEnabled()) { + log.debug("Updating the Swagger definition with basic_auth security of API: " + swaggerData.getTitle() + + " Version: " + swaggerData.getVersion()); + } + OASParserUtil.addSecurityRequirementToSwagger(swagger, APIConstants.API_SECURITY_BASIC_AUTH); + BasicAuthDefinition basicAuthDefinition = new BasicAuthDefinition(); + OASParserUtil.setScopesFromAPIToSecurityScheme(swaggerData, basicAuthDefinition); + swagger.addSecurityDefinition(APIConstants.API_SECURITY_BASIC_AUTH, basicAuthDefinition); + } + if (secList.contains(APIConstants.API_SECURITY_API_KEY)) { + if (log.isDebugEnabled()) { + log.debug("Updating the Swagger definition with api_key security of API: " + swaggerData.getTitle() + + " Version: " + swaggerData.getVersion()); + } + OASParserUtil.addSecurityRequirementToSwagger(swagger, APIConstants.API_SECURITY_API_KEY); + ApiKeyAuthDefinition apiKeyAuthDefinition = new ApiKeyAuthDefinition(); + apiKeyAuthDefinition.setName(APIConstants.API_KEY_AUTH_TYPE); + apiKeyAuthDefinition.setIn(In.HEADER); + swagger.addSecurityDefinition(APIConstants.API_SECURITY_API_KEY, apiKeyAuthDefinition); + } + // Add security requirements with scopes to the operations in OAS definition. + for (Map.Entry pathEntry : swagger.getPaths().entrySet()) { + for (Operation operation : pathEntry.getValue().getOperations()) { + List>> oldSecList = operation.getSecurity(); + // Get scopes from default oauth2 security of each resource. + List operationScopes = oldSecList.stream() + .filter(security -> security.containsKey(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY)) + .findFirst() + .map(security -> security.get(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY)) + .orElse(new ArrayList<>()); + // Add operation level security for basic_auth and api_key. + OASParserUtil.addSwaggerBasicAuthResourceScopesFromAPI(operationScopes, secList, operation); + OASParserUtil.addSwaggerOperationSecurityReqFromAPI(oldSecList, secList, + APIConstants.API_SECURITY_BASIC_AUTH, new ArrayList<>()); + OASParserUtil.addSwaggerOperationSecurityReqFromAPI(oldSecList, secList, + APIConstants.API_SECURITY_API_KEY, new ArrayList<>()); + if (!secList.isEmpty() && !secList.contains(APIConstants.DEFAULT_API_SECURITY_OAUTH2)) { + // If oauth2 is not set for the API, remove oauth security scheme from resource level if exists. + operation.setSecurity(operation.getSecurity().stream() + .filter(securityRequirement -> !securityRequirement + .containsKey(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY)) + .collect(Collectors.toList())); + } + } + } + if (!secList.isEmpty() && !secList.contains(APIConstants.DEFAULT_API_SECURITY_OAUTH2)) { + // If oauth2 is not set for the API, remove oauth security scheme from global level if exists. + if (log.isDebugEnabled()) { + log.debug("Removing default oauth2 security of API: " + swaggerData.getTitle() + + " Version: " + swaggerData.getVersion() + " from Swagger definition"); + } + swagger.getSecurityDefinitions().remove(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY); + swagger.setSecurity(swagger.getSecurity().stream().filter( + securityRequirement -> !securityRequirement.getRequirements() + .containsKey(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY)) + .collect(Collectors.toList())); + } + } + @Override public String getOASDefinitionWithTierContentAwareProperty(String oasDefinition, List contentAwareTiersList, String apiLevelTier) throws APIManagementException { diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS3Parser.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS3Parser.java index 533f9a355b64..1159e578c1a5 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS3Parser.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS3Parser.java @@ -1294,10 +1294,129 @@ private String updateSwaggerSecurityDefinitionForStore(OpenAPI openAPI, SwaggerD } else { authUrl = (hostsWithSchemes.get(APIConstants.HTTP_PROTOCOL)).concat("/authorize"); } - updateSwaggerSecurityDefinition(openAPI, swaggerData, authUrl); + updateSwaggerSecurityDefinitionForStore(openAPI, swaggerData, authUrl); return Json.pretty(openAPI); } + + /** + * Update Swagger security definition for dev portal only. + * + * @param openAPI OpenAPI + * @param swaggerData SwaggerData + * @param authUrl Authorization URL + */ + private void updateSwaggerSecurityDefinitionForStore(OpenAPI openAPI, SwaggerData swaggerData, String authUrl) { + + if (openAPI.getComponents() == null) openAPI.setComponents(new Components()); + // Get the security defined for the current API. + List secList = swaggerData.getSecurity() != null ? Arrays.asList(swaggerData.getSecurity().split(",")) + : new ArrayList<>(); + // Get the security schemes defined in the OAS definition. + Map securitySchemes = openAPI.getComponents().getSecuritySchemes(); + if (securitySchemes == null) { + // If no security schemes defined, create a new map. + securitySchemes = new HashMap<>(); + openAPI.getComponents().setSecuritySchemes(securitySchemes); + } + List security = new ArrayList<>(); // Override with new global security requirements. + openAPI.setSecurity(security); + // If the security in API is empty or default oauth, add oauth2 security to the OAS definition. + if (secList.isEmpty() || secList.contains(APIConstants.DEFAULT_API_SECURITY_OAUTH2)) { + if (log.isDebugEnabled()) { + log.debug("Updating the OAS definition with default oauth2 security of API: " + swaggerData.getTitle() + + " Version: " + swaggerData.getVersion()); + } + // Add oauth to global security requirement to the OAS definition. + OASParserUtil.addSecurityRequirementToSwagger(openAPI, OPENAPI_SECURITY_SCHEMA_KEY); + // If default oauth type security scheme in the OAS definition, add it. + SecurityScheme securityScheme = securitySchemes.computeIfAbsent(OPENAPI_SECURITY_SCHEMA_KEY, + key -> { + SecurityScheme newOAuthScheme = new SecurityScheme(); + newOAuthScheme.setType(SecurityScheme.Type.OAUTH2); + return newOAuthScheme; + }); + if (securityScheme.getFlows() == null) { // If no flows defined, create a new one. + securityScheme.setFlows(new OAuthFlows()); + } + OAuthFlow oAuthFlow = securityScheme.getFlows().getImplicit(); + if (oAuthFlow == null) { // If no implicit flow defined, create a new one. + oAuthFlow = new OAuthFlow(); + securityScheme.getFlows().setImplicit(oAuthFlow); + } + // rewrite the authorization url if the authorization url is not empty. + oAuthFlow.setAuthorizationUrl(authUrl); + // Set the scopes defined in the API to the OAS definition. + OASParserUtil.setScopesFromAPIToSecurityScheme(swaggerData, securityScheme); + } + // If the Basic Auth security is in API, add basic security to the OAS definition. + if (secList.contains(APIConstants.API_SECURITY_BASIC_AUTH)) { + if (log.isDebugEnabled()) { + log.debug("Updating the OAS definition with basic_auth security of API: " + swaggerData.getTitle() + + " Version: " + swaggerData.getVersion()); + } + SecurityScheme securityScheme = securitySchemes.computeIfAbsent(APIConstants.API_SECURITY_BASIC_AUTH, + key -> { + SecurityScheme scheme = new SecurityScheme(); + scheme.setType(SecurityScheme.Type.HTTP); + scheme.setScheme(APIConstants.AUTHORIZATION_HEADER_BASIC); + return scheme; + }); + // Set the scopes defined in the API to the OAS definition. + OASParserUtil.setScopesFromAPIToSecurityScheme(swaggerData, securityScheme); + // Add global basic security requirement to the OAS definition. + OASParserUtil.addSecurityRequirementToSwagger(openAPI, APIConstants.API_SECURITY_BASIC_AUTH); + } + if (secList.contains(APIConstants.API_SECURITY_API_KEY)) { + if (log.isDebugEnabled()) { + log.debug("Updating the OAS definition with api_key security of API: " + swaggerData.getTitle() + + " Version: " + swaggerData.getVersion()); + } + securitySchemes.computeIfAbsent(APIConstants.API_SECURITY_API_KEY, + key -> { + SecurityScheme scheme = new SecurityScheme(); + scheme.setType(SecurityScheme.Type.APIKEY); + scheme.setIn(SecurityScheme.In.HEADER); + scheme.setName(APIConstants.API_KEY_AUTH_TYPE); + return scheme; + }); + // Add global api key security requirement to the OAS definition. + OASParserUtil.addSecurityRequirementToSwagger(openAPI, APIConstants.API_SECURITY_API_KEY); + } + // Add requirement with scopes to the operations in OAS definition. + for (Map.Entry pathEntry : openAPI.getPaths().entrySet()) { + for (Operation operation : pathEntry.getValue().readOperations()) { + List oldSecList = operation.getSecurity(); + List operationScopes = oldSecList.stream() + .filter(securityRequirement -> securityRequirement.containsKey(OPENAPI_SECURITY_SCHEMA_KEY)) + .findFirst() + .map(securityRequirement -> securityRequirement.get(OPENAPI_SECURITY_SCHEMA_KEY)) + .orElse(new ArrayList<>()); + // Add operation level security for basic_auth and api_key. + OASParserUtil.addOASBasicAuthResourceScopesFromAPI(operationScopes, secList, operation); + OASParserUtil.addOASOperationSecurityReqFromAPI(oldSecList, secList, + APIConstants.API_SECURITY_BASIC_AUTH, new ArrayList<>()); + OASParserUtil.addOASOperationSecurityReqFromAPI(oldSecList, secList, APIConstants.API_SECURITY_API_KEY, + new ArrayList<>()); + if (!secList.isEmpty() && !secList.contains(APIConstants.DEFAULT_API_SECURITY_OAUTH2)) { + // If oauth2 is not set for the API, remove oauth security scheme from resource level if exists. + operation.setSecurity(operation.getSecurity().stream() + .filter(securityRequirement -> !securityRequirement + .containsKey(OPENAPI_SECURITY_SCHEMA_KEY)) + .collect(Collectors.toList())); + } + } + } + if (!secList.isEmpty() && !secList.contains(APIConstants.DEFAULT_API_SECURITY_OAUTH2)) { + if (log.isDebugEnabled()) { + log.debug("Removing default oauth2 security of API: " + swaggerData.getTitle() + + " Version: " + swaggerData.getVersion() + " from OAS definition"); + } + // Remove oauth security scheme from global level and resource level if exists + securitySchemes.remove(OPENAPI_SECURITY_SCHEMA_KEY); + } + } + /** * Update OAS definition with GW endpoints * diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OASParserUtil.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OASParserUtil.java index 09df3179247f..71e0d5ae437d 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OASParserUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OASParserUtil.java @@ -34,6 +34,8 @@ import io.swagger.models.RefResponse; import io.swagger.models.Response; import io.swagger.models.Swagger; +import io.swagger.models.auth.OAuth2Definition; +import io.swagger.models.auth.SecuritySchemeDefinition; import io.swagger.models.parameters.RefParameter; import io.swagger.models.properties.RefProperty; import io.swagger.parser.SwaggerParser; @@ -81,12 +83,13 @@ import org.wso2.carbon.apimgt.api.ExceptionCodes; import org.wso2.carbon.apimgt.api.model.API; import org.wso2.carbon.apimgt.api.model.APIIdentifier; -import org.wso2.carbon.apimgt.api.model.APIRevision; import org.wso2.carbon.apimgt.api.model.APIProductIdentifier; import org.wso2.carbon.apimgt.api.model.APIProductResource; +import org.wso2.carbon.apimgt.api.model.APIRevision; import org.wso2.carbon.apimgt.api.model.CORSConfiguration; import org.wso2.carbon.apimgt.api.model.Identifier; import org.wso2.carbon.apimgt.api.model.Scope; +import org.wso2.carbon.apimgt.api.model.SwaggerData; import org.wso2.carbon.apimgt.api.model.URITemplate; import org.wso2.carbon.apimgt.impl.APIConstants; import org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO; @@ -100,22 +103,22 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStream; -import java.io.FileNotFoundException; -import java.io.FilenameFilter; import java.net.URL; import java.nio.charset.Charset; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.HashMap; -import java.util.stream.Collectors; import java.util.ArrayList; +import java.util.Arrays; import java.util.Comparator; import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; -import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.UUID; +import java.util.stream.Collectors; + import static org.wso2.carbon.apimgt.impl.utils.APIUtil.handleException; /** @@ -1796,4 +1799,192 @@ private static boolean removeBlocksRecursivelyFromJsonObject(String keyToBeRemov } return definitionUpdated; } + + /** + * This method will set the scopes defined in the API to the security scheme in swagger3. + * + * @param swaggerData SwaggerData object which contains the API data. + * @param securityScheme SecurityScheme object which contains the security scheme. + */ + public static void setScopesFromAPIToSecurityScheme(SwaggerData swaggerData, SecurityScheme securityScheme) { + + Map scopeBindings = new LinkedHashMap<>(); + Scopes oas3Scopes = new Scopes(); + Set scopes = swaggerData.getScopes(); // Get the scopes defined in the API. + if (scopes != null && !scopes.isEmpty()) { // If scopes defined, add them to the OAS definition. + populateScopesFromAPI(scopes, oas3Scopes, scopeBindings); + // replace the scope bindings if the scopes are not empty. + if (SecurityScheme.Type.OAUTH2.toString().equals(securityScheme.getType().toString())) { + securityScheme.getFlows().getImplicit() + .addExtension(APIConstants.SWAGGER_X_SCOPES_BINDINGS, scopeBindings); + } else if (SecurityScheme.Type.HTTP.toString().equals(securityScheme.getType().toString()) && + APIConstants.AUTHORIZATION_HEADER_BASIC.equals(securityScheme.getScheme())) { + securityScheme.addExtension(APIConstants.SWAGGER_X_BASIC_AUTH_SCOPES, oas3Scopes); + securityScheme.addExtension(APIConstants.SWAGGER_X_SCOPES_BINDINGS, scopeBindings); + } + } + if (SecurityScheme.Type.OAUTH2.toString().equals(securityScheme.getType().toString())) { + securityScheme.getFlows().getImplicit().setScopes(oas3Scopes); + } + } + + /** + * This method will set the scopes defined in the API to the security scheme in swagger2. + * + * @param swaggerData SwaggerData object which contains the API data. + * @param securitySchemeDefinition SecuritySchemeDefinition object which contains the security scheme. + */ + public static void setScopesFromAPIToSecurityScheme(SwaggerData swaggerData, + SecuritySchemeDefinition securitySchemeDefinition) { + + Map swaggerScopes = new LinkedHashMap<>(); + Map scopeBindings = new LinkedHashMap<>(); + Set scopes = swaggerData.getScopes(); + if (scopes != null && !scopes.isEmpty()) { + populateScopesFromAPI(scopes, swaggerScopes, scopeBindings); + if (StringUtils.equals(APIConstants.DEFAULT_API_SECURITY_OAUTH2, securitySchemeDefinition.getType())) { + securitySchemeDefinition.setVendorExtension(APIConstants.SWAGGER_X_SCOPES_BINDINGS, scopeBindings); + } else if (StringUtils.equals(APIConstants.SWAGGER_API_SECURITY_BASIC_AUTH_TYPE, + securitySchemeDefinition.getType())) { + securitySchemeDefinition.setVendorExtension(APIConstants.SWAGGER_X_BASIC_AUTH_SCOPES, swaggerScopes); + securitySchemeDefinition.setVendorExtension(APIConstants.SWAGGER_X_SCOPES_BINDINGS, scopeBindings); + } + } + if (StringUtils.equals(APIConstants.DEFAULT_API_SECURITY_OAUTH2, securitySchemeDefinition.getType())) { + ((OAuth2Definition) securitySchemeDefinition).setScopes(swaggerScopes); + } + } + + private static void populateScopesFromAPI(Set apiScopes, Map scopes, + Map scopeBindings) { + + if (apiScopes != null && !apiScopes.isEmpty()) { + apiScopes.forEach(scope -> { + String description = scope.getDescription() != null ? scope.getDescription() : StringUtils.EMPTY; + scopes.put(scope.getKey(), description); + // If roles are defined for the scope, add them to the scope bindings. + String roles = (StringUtils.isNotBlank(scope.getRoles()) + && scope.getRoles().trim().split(",").length > 0) ? scope.getRoles() : StringUtils.EMPTY; + scopeBindings.put(scope.getKey(), roles); + }); + } + } + + /** + * Add security requirement to swagger2. + * + * @param swagger Swagger2 object + * @param securityReqName SecurityRequirement name (Eg: default, basic_auth etc). + */ + public static void addSecurityRequirementToSwagger(Swagger swagger, String securityReqName) { + + io.swagger.models.SecurityRequirement securityRequirement = new io.swagger.models.SecurityRequirement(); + securityRequirement.setRequirements(securityReqName, new ArrayList<>()); + if (swagger.getSecurity() == null || !swagger.getSecurity().contains(securityRequirement)) { + swagger.addSecurity(securityRequirement); + } + } + + /** + * Add security requirement to OAS definition. + * + * @param openAPI OAS Definition object + * @param securityReqName SecurityRequirement name (Eg: default, basic_auth etc). + */ + public static void addSecurityRequirementToSwagger(OpenAPI openAPI, String securityReqName) { + + SecurityRequirement secReq = new SecurityRequirement(); + secReq.addList(securityReqName, new ArrayList<>()); + openAPI.addSecurityItem(secReq); + } + + /** + * Add operation level security requirements from the API to OAS definition. + * + * @param operationSecurities Existing operation level security requirements + * @param apiSecurities Security defined for API + * @param securityReqName Specific security name (Eg: basic_auth, default etc) + * @param operationScopes Operation specific scopes for the security requirement + */ + public static void addOASOperationSecurityReqFromAPI(List operationSecurities, + List apiSecurities, String securityReqName, + List operationScopes) { + + if (apiSecurities.contains(securityReqName)) { + boolean isSecurityExists = operationSecurities.stream().anyMatch( + securityRequirement -> securityRequirement.containsKey(securityReqName)); + if (!isSecurityExists) { + SecurityRequirement securityRequirement = new SecurityRequirement(); + securityRequirement.addList(securityReqName, operationScopes); + operationSecurities.add(securityRequirement); + } else { + operationSecurities.stream().filter + (securityRequirement -> securityRequirement.containsKey(securityReqName)) + .findFirst().ifPresent(securityRequirement -> securityRequirement + .addList(securityReqName, operationScopes)); + } + } + } + + /** + * Set Basic Auth Scopes for API resources in OAS definition. + * + * @param operationScopes Operation specific scopes for the security requirement + * @param apiSecurities Security defined for API + * @param operation Existing operation + */ + public static void addOASBasicAuthResourceScopesFromAPI(List operationScopes, List apiSecurities, + Operation operation) { + + if (!operationScopes.isEmpty() && apiSecurities.contains(APIConstants.API_SECURITY_BASIC_AUTH)) { + operation.addExtension(APIConstants.SWAGGER_X_BASIC_AUTH_RESOURCE_SCOPES, operationScopes); + } + } + + /** + * Add operation level security requirements from the API to Swagger2. + * + * @param operationSecurities Existing operation level security requirements + * @param apiSecurities Security defined for API + * @param securityReqName Specific security name (Eg: basic_auth, default etc) + * @param operationScopes Operation specific scopes for the security requirement + */ + public static void addSwaggerOperationSecurityReqFromAPI(List>> operationSecurities, + List apiSecurities, String securityReqName, + List operationScopes) { + + if (apiSecurities.contains(securityReqName)) { + // If security requirement is set for the API. + boolean isSecurityExists = operationSecurities.stream().anyMatch( + securityRequirement -> securityRequirement.containsKey(securityReqName)); + if (!isSecurityExists) { + // If security not defined in the swagger definition, add new. + Map> securityRequirement = new HashMap<>(); + securityRequirement.put(securityReqName, operationScopes); + operationSecurities.add(securityRequirement); + } else { + // If security already defined in the swagger definition, update the scope list. + operationSecurities.stream().filter + (securityRequirement -> securityRequirement.containsKey(securityReqName)) + .findFirst().ifPresent(securityRequirement -> securityRequirement + .put(securityReqName, operationScopes)); + } + } + } + + /** + * Set Basic Auth Scopes for API resources in Swagger2 definition. + * + * @param operationScopes Operation specific scopes for the security requirement + * @param apiSecurities Security defined for API + * @param operation Existing operation + */ + public static void addSwaggerBasicAuthResourceScopesFromAPI(List operationScopes, + List apiSecurities, + io.swagger.models.Operation operation) { + + if (!operationScopes.isEmpty() && apiSecurities.contains(APIConstants.API_SECURITY_BASIC_AUTH)) { + operation.setVendorExtension(APIConstants.SWAGGER_X_BASIC_AUTH_RESOURCE_SCOPES, operationScopes); + } + } } From 0847c73cd92489fec50d3458d764c18aa8025956 Mon Sep 17 00:00:00 2001 From: dushani Date: Mon, 21 Aug 2023 11:48:24 +0530 Subject: [PATCH 2/6] fix api key auth header to reflect apikey. fix regression issue in migrated apis from 2.6 without security definitions. --- .../wso2/carbon/apimgt/impl/APIConstants.java | 1 + .../apimgt/impl/definitions/OAS2Parser.java | 22 +++++++++++++------ .../apimgt/impl/definitions/OAS3Parser.java | 10 ++++++--- .../impl/definitions/OASParserUtil.java | 2 +- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java index 683164f9c11b..9bd9e20691c7 100755 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java @@ -342,6 +342,7 @@ public final class APIConstants { public static final String DEFAULT_API_SECURITY_OAUTH2 = "oauth2"; public static final String API_SECURITY_MUTUAL_SSL = "mutualssl"; public static final String API_SECURITY_BASIC_AUTH = "basic_auth"; + public static final String SWAGGER_API_SECURITY_BASIC_AUTH_TYPE = "basic"; public static final String API_SECURITY_API_KEY = "api_key"; public static final String API_SECURITY_MUTUAL_SSL_MANDATORY = "mutualssl_mandatory"; public static final String API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY = "oauth_basic_auth_api_key_mandatory"; diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS2Parser.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS2Parser.java index 4a451fa5697b..ed1eff1f2910 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS2Parser.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS2Parser.java @@ -1372,7 +1372,7 @@ private void updateSwaggerSecurityDefinitionForStore(Swagger swagger, SwaggerDat } OASParserUtil.addSecurityRequirementToSwagger(swagger, APIConstants.API_SECURITY_API_KEY); ApiKeyAuthDefinition apiKeyAuthDefinition = new ApiKeyAuthDefinition(); - apiKeyAuthDefinition.setName(APIConstants.API_KEY_AUTH_TYPE); + apiKeyAuthDefinition.setName(APIConstants.API_KEY_HEADER_QUERY_PARAM); apiKeyAuthDefinition.setIn(In.HEADER); swagger.addSecurityDefinition(APIConstants.API_SECURITY_API_KEY, apiKeyAuthDefinition); } @@ -1380,6 +1380,9 @@ private void updateSwaggerSecurityDefinitionForStore(Swagger swagger, SwaggerDat for (Map.Entry pathEntry : swagger.getPaths().entrySet()) { for (Operation operation : pathEntry.getValue().getOperations()) { List>> oldSecList = operation.getSecurity(); + if (oldSecList == null) { + oldSecList = new ArrayList<>(); + } // Get scopes from default oauth2 security of each resource. List operationScopes = oldSecList.stream() .filter(security -> security.containsKey(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY)) @@ -1392,7 +1395,8 @@ private void updateSwaggerSecurityDefinitionForStore(Swagger swagger, SwaggerDat APIConstants.API_SECURITY_BASIC_AUTH, new ArrayList<>()); OASParserUtil.addSwaggerOperationSecurityReqFromAPI(oldSecList, secList, APIConstants.API_SECURITY_API_KEY, new ArrayList<>()); - if (!secList.isEmpty() && !secList.contains(APIConstants.DEFAULT_API_SECURITY_OAUTH2)) { + if (!secList.isEmpty() && !secList.contains(APIConstants.DEFAULT_API_SECURITY_OAUTH2) + && operation.getSecurity() != null) { // If oauth2 is not set for the API, remove oauth security scheme from resource level if exists. operation.setSecurity(operation.getSecurity().stream() .filter(securityRequirement -> !securityRequirement @@ -1407,11 +1411,15 @@ private void updateSwaggerSecurityDefinitionForStore(Swagger swagger, SwaggerDat log.debug("Removing default oauth2 security of API: " + swaggerData.getTitle() + " Version: " + swaggerData.getVersion() + " from Swagger definition"); } - swagger.getSecurityDefinitions().remove(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY); - swagger.setSecurity(swagger.getSecurity().stream().filter( - securityRequirement -> !securityRequirement.getRequirements() - .containsKey(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY)) - .collect(Collectors.toList())); + if (swagger.getSecurityDefinitions() != null) { + swagger.getSecurityDefinitions().remove(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY); + } + if (swagger.getSecurity() != null) { + swagger.setSecurity(swagger.getSecurity().stream().filter( + securityRequirement -> !securityRequirement.getRequirements() + .containsKey(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY)) + .collect(Collectors.toList())); + } } } diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS3Parser.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS3Parser.java index 852b8d00ac33..512f0887bf9e 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS3Parser.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OAS3Parser.java @@ -1366,7 +1366,7 @@ private void updateSwaggerSecurityDefinitionForStore(OpenAPI openAPI, SwaggerDat key -> { SecurityScheme scheme = new SecurityScheme(); scheme.setType(SecurityScheme.Type.HTTP); - scheme.setScheme(APIConstants.AUTHORIZATION_HEADER_BASIC); + scheme.setScheme(APIConstants.SWAGGER_API_SECURITY_BASIC_AUTH_TYPE); return scheme; }); // Set the scopes defined in the API to the OAS definition. @@ -1384,7 +1384,7 @@ private void updateSwaggerSecurityDefinitionForStore(OpenAPI openAPI, SwaggerDat SecurityScheme scheme = new SecurityScheme(); scheme.setType(SecurityScheme.Type.APIKEY); scheme.setIn(SecurityScheme.In.HEADER); - scheme.setName(APIConstants.API_KEY_AUTH_TYPE); + scheme.setName(APIConstants.API_KEY_HEADER_QUERY_PARAM); return scheme; }); // Add global api key security requirement to the OAS definition. @@ -1394,6 +1394,9 @@ private void updateSwaggerSecurityDefinitionForStore(OpenAPI openAPI, SwaggerDat for (Map.Entry pathEntry : openAPI.getPaths().entrySet()) { for (Operation operation : pathEntry.getValue().readOperations()) { List oldSecList = operation.getSecurity(); + if (oldSecList == null) { + oldSecList = new ArrayList<>(); + } List operationScopes = oldSecList.stream() .filter(securityRequirement -> securityRequirement.containsKey(OPENAPI_SECURITY_SCHEMA_KEY)) .findFirst() @@ -1405,7 +1408,8 @@ private void updateSwaggerSecurityDefinitionForStore(OpenAPI openAPI, SwaggerDat APIConstants.API_SECURITY_BASIC_AUTH, new ArrayList<>()); OASParserUtil.addOASOperationSecurityReqFromAPI(oldSecList, secList, APIConstants.API_SECURITY_API_KEY, new ArrayList<>()); - if (!secList.isEmpty() && !secList.contains(APIConstants.DEFAULT_API_SECURITY_OAUTH2)) { + if (!secList.isEmpty() && !secList.contains(APIConstants.DEFAULT_API_SECURITY_OAUTH2) + && operation.getSecurity() != null) { // If oauth2 is not set for the API, remove oauth security scheme from resource level if exists. operation.setSecurity(operation.getSecurity().stream() .filter(securityRequirement -> !securityRequirement diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OASParserUtil.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OASParserUtil.java index ab7312e7fce5..356d591dce79 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OASParserUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/definitions/OASParserUtil.java @@ -1832,7 +1832,7 @@ public static void setScopesFromAPIToSecurityScheme(SwaggerData swaggerData, Sec securityScheme.getFlows().getImplicit() .addExtension(APIConstants.SWAGGER_X_SCOPES_BINDINGS, scopeBindings); } else if (SecurityScheme.Type.HTTP.toString().equals(securityScheme.getType().toString()) && - APIConstants.AUTHORIZATION_HEADER_BASIC.equals(securityScheme.getScheme())) { + APIConstants.SWAGGER_API_SECURITY_BASIC_AUTH_TYPE.equals(securityScheme.getScheme())) { securityScheme.addExtension(APIConstants.SWAGGER_X_BASIC_AUTH_SCOPES, oas3Scopes); securityScheme.addExtension(APIConstants.SWAGGER_X_SCOPES_BINDINGS, scopeBindings); } From d52b438bc941035039194cdf6708cae0bdace5d1 Mon Sep 17 00:00:00 2001 From: dushani Date: Mon, 21 Aug 2023 11:49:16 +0530 Subject: [PATCH 3/6] add unit test cases. --- .../impl/definitions/OAS2ParserTest.java | 185 +++++++++++ .../impl/definitions/OAS3ParserTest.java | 177 ++++++++++ ...oas2_mig_with_sec_extensions_response.json | 91 ++++++ ...2_mig_without_sec_extensions_response.json | 64 ++++ .../oas2/devportal/oas2_with_apikey.json | 221 +++++++++++++ ...2_with_apikey_basic_oauth_security_u2.json | 258 +++++++++++++++ ...ikey_basic_oauth_security_u2_response.json | 273 ++++++++++++++++ .../devportal/oas2_with_apikey_response.json | 219 +++++++++++++ .../oas2/devportal/oas2_with_basic.json | 233 ++++++++++++++ .../devportal/oas2_with_basic_apisec.json | 233 ++++++++++++++ .../oas2_with_basic_apisec_response.json | 246 ++++++++++++++ .../devportal/oas2_with_basic_response.json | 232 ++++++++++++++ .../oas2_with_default_allsecurity.json | 233 ++++++++++++++ ...as2_with_default_allsecurity_response.json | 273 ++++++++++++++++ .../oas2_mig_with_sec_extensions.json | 65 ++++ ...oas2_mig_with_sec_extensions_response.json | 88 +++++ .../oas2_mig_without_sec_extensions.json | 46 +++ ...2_mig_without_sec_extensions_response.json | 68 ++++ ...2_with_apikey_basic_oauth_security_u2.json | 286 +++++++++++++++++ ...ikey_basic_oauth_security_u2_response.json | 261 +++++++++++++++ .../publisher/oas2_with_default_oauth.json | 302 ++++++++++++++++++ .../oas2_with_default_oauth_response.json | 278 ++++++++++++++++ ...oas3_mig_with_sec_extensions_response.json | 104 ++++++ ...3_mig_without_sec_extensions_response.json | 80 +++++ .../oas3/devportal/oas3_with_apikey.json | 73 +++++ ...ikey_basic_oauth_security_u2_response.json | 96 ++++++ .../devportal/oas3_with_apikey_response.json | 62 ++++ .../oas3/devportal/oas3_with_basic.json | 73 +++++ .../devportal/oas3_with_basic_apisec.json | 73 +++++ .../oas3_with_basic_apisec_response.json | 82 +++++ .../devportal/oas3_with_basic_response.json | 71 ++++ .../oas3_with_default_allsecurity.json | 73 +++++ ...as3_with_default_allsecurity_response.json | 104 ++++++ .../oas3_mig_with_sec_extensions.json | 81 +++++ ...oas3_mig_with_sec_extensions_response.json | 113 +++++++ .../oas3_mig_without_sec_extensions.json | 61 ++++ ...3_mig_without_sec_extensions_response.json | 96 ++++++ ...3_with_apikey_basic_oauth_security_u2.json | 95 ++++++ ...ikey_basic_oauth_security_u2_response.json | 89 ++++++ .../publisher/oas3_with_default_oauth.json | 73 +++++ .../oas3_with_default_oauth_response.json | 89 ++++++ 41 files changed, 5920 insertions(+) create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_mig_with_sec_extensions_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_mig_without_sec_extensions_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey_basic_oauth_security_u2.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey_basic_oauth_security_u2_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic_apisec.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic_apisec_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_default_allsecurity.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_default_allsecurity_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_with_sec_extensions.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_with_sec_extensions_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_without_sec_extensions.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_without_sec_extensions_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_apikey_basic_oauth_security_u2.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_apikey_basic_oauth_security_u2_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_mig_with_sec_extensions_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_mig_without_sec_extensions_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_apikey.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_apikey_basic_oauth_security_u2_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_apikey_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic_apisec.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic_apisec_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_default_allsecurity.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_default_allsecurity_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_with_sec_extensions.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_with_sec_extensions_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_without_sec_extensions.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_without_sec_extensions_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_apikey_basic_oauth_security_u2.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_apikey_basic_oauth_security_u2_response.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_default_oauth.json create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_default_oauth_response.json diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS2ParserTest.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS2ParserTest.java index ca67e970cf8b..bacc51754452 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS2ParserTest.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS2ParserTest.java @@ -33,11 +33,15 @@ import org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse; import org.wso2.carbon.apimgt.api.ExceptionCodes; import org.wso2.carbon.apimgt.api.model.API; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; +import org.wso2.carbon.apimgt.api.model.Scope; import org.wso2.carbon.apimgt.api.model.URITemplate; import org.wso2.carbon.apimgt.impl.APIConstants; import java.io.File; import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; @@ -181,4 +185,185 @@ public void testRootLevelApplicationSecurity() throws Exception { Assert.assertEquals(oasDefinitionEdited, response); } + @Test + public void testGetOASSecurityDefinitionForPublisher() throws Exception { + + // Testing API with migrated swagger coming from APIM version 2.x without any x-wso2-security or x-scopes. + String swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + + "publisher" + File.separator + "oas2_mig_without_sec_extensions.json"), + StandardCharsets.UTF_8); + API api = Mockito.mock(API.class); + String apiSecurity = "oauth_basic_auth_api_key_mandatory,oauth2"; + when(api.getApiSecurity()).thenReturn(apiSecurity); + APIDefinition parser = OASParserUtil.getOASParser(swagger); + String response = parser.getOASDefinitionForPublisher(api, swagger); + String oasDefinitionEdited = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + + "publisher" + File.separator + "oas2_mig_without_sec_extensions_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionEdited, response); + + // Testing API with migrated swagger coming from APIM version 2.x with x-wso2-security and x-scopes. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + + "publisher" + File.separator + "oas2_mig_with_sec_extensions.json"), StandardCharsets.UTF_8); + response = parser.getOASDefinitionForPublisher(api, swagger); + oasDefinitionEdited = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + + File.separator + "publisher" + File.separator + "oas2_mig_with_sec_extensions_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionEdited, response); + + // Testing API with swagger generated after APIM 2.x versions with oauth security definitions and x-wso2 + // extensions. API configured with all security. + apiSecurity = "oauth_basic_auth_api_key_mandatory,api_key,basic_auth,oauth2"; + when(api.getApiSecurity()).thenReturn(apiSecurity); + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + + File.separator + "publisher" + File.separator + "oas2_with_default_oauth.json"), + StandardCharsets.UTF_8); + response = parser.getOASDefinitionForPublisher(api, swagger); + oasDefinitionEdited = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + + File.separator + "publisher" + File.separator + "oas2_with_default_oauth_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionEdited, response); + + // Testing API with swagger generated after APIM 2.x version, but with basic_auth and api_key security in the + // scheme which went with as an u2 update for 4.1, then later reverted. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + + "publisher" + File.separator + "oas2_with_apikey_basic_oauth_security_u2.json"), + StandardCharsets.UTF_8); + response = parser.getOASDefinitionForPublisher(api, swagger); + oasDefinitionEdited = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + + "publisher" + File.separator + "oas2_with_apikey_basic_oauth_security_u2_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionEdited, response); + } + + @Test + public void testGetOASSecurityDefinitionForStore() throws Exception { + + // Testing API with migrated swagger coming from APIM version 2.x without any x-wso2-security or x-scopes. + String swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + + File.separator + "publisher" + File.separator + "oas2_mig_without_sec_extensions.json"), + StandardCharsets.UTF_8); + APIIdentifier apiIdentifier = new APIIdentifier("admin", "OldAPI", "1.0.0"); + Map hostWithSchemes = new HashMap<>(); + hostWithSchemes.put(APIConstants.HTTPS_PROTOCOL, "https://localhost"); + API api = new API(apiIdentifier); + api.setApiSecurity("oauth_basic_auth_api_key_mandatory,oauth2"); + api.setTransports("https"); + api.setContext("/oldapi"); + api.setScopes(new HashSet<>()); + String response = oas2Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); + String oasDefinitionExpected = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + + File.separator + "devportal" + File.separator + + "oas2_mig_without_sec_extensions_response.json"), StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionExpected, response); + + // Testing API with migrated swagger coming from APIM version 2.x with x-wso2-security and x-scopes. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + + File.separator + "publisher" + File.separator + "oas2_mig_with_sec_extensions.json"), + String.valueOf(StandardCharsets.UTF_8)); + api.setScopes(getAPITestScopes()); + response = oas2Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); + oasDefinitionExpected = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + + File.separator + "devportal" + File.separator + "oas2_mig_with_sec_extensions_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionExpected, response); + + // Testing API with swagger generated after APIM 2.x versions with oauth security definitions and x-wso2 + // extensions. API configured with all security. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + + File.separator + "devportal" + File.separator + "oas2_with_default_allsecurity.json"), + StandardCharsets.UTF_8); + apiIdentifier = new APIIdentifier("admin", "SwaggerPetstore", "1.0.6"); + api = new API(apiIdentifier); + api.setTransports("https"); + api.setContext("/v2"); + api.setScopes(getAPITestScopes()); + api.setApiSecurity("oauth_basic_auth_api_key_mandatory,api_key,basic_auth,oauth2"); + response = oas2Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); + oasDefinitionExpected = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + + File.separator + "devportal" + File.separator + + "oas2_with_default_allsecurity_response.json"), StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionExpected, response); + // Testing API with swagger generated after APIM 2.x version, but with basic_auth and api_key security in + // the scheme which went with as an u2 update for 4.1, then later reverted. API configured with all security. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + + "devportal" + File.separator + "oas2_with_apikey_basic_oauth_security_u2.json"), + StandardCharsets.UTF_8); + response = oas2Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); + oasDefinitionExpected = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + + "devportal" + File.separator + "oas2_with_apikey_basic_oauth_security_u2_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionExpected, response); + // Testing API with swagger generated after APIM 2.x versions with oauth security definitions and x-wso2 + // extensions. API configured with basic auth and api key. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + + File.separator + "devportal" + File.separator + "oas2_with_basic_apisec.json"), + StandardCharsets.UTF_8); + api.setApiSecurity("oauth_basic_auth_api_key_mandatory,api_key,basic_auth"); + response = oas2Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); + oasDefinitionExpected = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + + File.separator + "devportal" + File.separator + "oas2_with_basic_apisec_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionExpected, response); + // API configured with basic auth only. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + + File.separator + "devportal" + File.separator + "oas2_with_basic.json"), + String.valueOf(StandardCharsets.UTF_8)); + api.setApiSecurity("oauth_basic_auth_api_key_mandatory,basic_auth"); + response = oas2Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); + oasDefinitionExpected = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + + File.separator + "devportal" + File.separator + "oas2_with_basic_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionExpected, response); + // API Configured with api key only. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + + File.separator + "devportal" + File.separator + "oas2_with_apikey.json"), + String.valueOf(StandardCharsets.UTF_8)); + api.setApiSecurity("oauth_basic_auth_api_key_mandatory,api_key"); + response = oas2Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); + oasDefinitionExpected = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + + File.separator + "devportal" + File.separator + "oas2_with_apikey_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionExpected, response); + } + + private Set getAPITestScopes() { + Scope petLocalScope = new Scope(); + petLocalScope.setKey("PetLocalScope"); + petLocalScope.setName("PetLocalScope"); + petLocalScope.setRoles("admin"); + petLocalScope.setDescription(""); + Scope globalScope = new Scope(); + globalScope.setName("GlobalScope"); + globalScope.setKey("GlobalScope"); + globalScope.setDescription("desc"); + globalScope.setRoles(""); + Set apiScopes = new LinkedHashSet<>(); + apiScopes.add(globalScope); + apiScopes.add(petLocalScope); + return apiScopes; + } + } \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS3ParserTest.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS3ParserTest.java index 211b6f1655cb..7b035f700b3a 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS3ParserTest.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS3ParserTest.java @@ -15,12 +15,16 @@ import org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse; import org.wso2.carbon.apimgt.api.ExceptionCodes; import org.wso2.carbon.apimgt.api.model.API; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; import org.wso2.carbon.apimgt.api.model.APIResourceMediationPolicy; +import org.wso2.carbon.apimgt.api.model.Scope; import org.wso2.carbon.apimgt.api.model.URITemplate; import org.wso2.carbon.apimgt.impl.APIConstants; import java.io.File; import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; @@ -267,4 +271,177 @@ public void testProcessOtherSchemeScopesWithClientCredentialsScheme() throws Exc } + @Test + public void testGetOASSecurityDefinitionForPublisher() throws Exception { + + // Testing API with migrated swagger coming from APIM version 2.x without any x-wso2-security or x-scopes. + String swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + + File.separator + "publisher" + File.separator + "oas3_mig_without_sec_extensions.json"), + StandardCharsets.UTF_8); + API api = Mockito.mock(API.class); + String apiSecurity = "oauth_basic_auth_api_key_mandatory,oauth2"; + when(api.getApiSecurity()).thenReturn(apiSecurity); + APIDefinition parser = OASParserUtil.getOASParser(swagger); + String response = parser.getOASDefinitionForPublisher(api, swagger); + String oasDefinitionEdited = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "publisher" + File.separator + "oas3_mig_without_sec_extensions_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionEdited, response); + + // Testing API with migrated swagger coming from APIM version 2.x with x-wso2-security and x-scopes. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + + File.separator + "publisher" + File.separator + "oas3_mig_with_sec_extensions.json"), + StandardCharsets.UTF_8); + response = parser.getOASDefinitionForPublisher(api, swagger); + oasDefinitionEdited = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "publisher" + File.separator + "oas3_mig_with_sec_extensions_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionEdited, response); + + // Testing API with swagger generated after APIM 2.x versions with oauth security definitions and x-wso2 + // extensions. API configured with all security. + apiSecurity = "oauth_basic_auth_api_key_mandatory,api_key,basic_auth,oauth2"; + when(api.getApiSecurity()).thenReturn(apiSecurity); + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "publisher" + File.separator + "oas3_with_default_oauth.json"), StandardCharsets.UTF_8); + response = parser.getOASDefinitionForPublisher(api, swagger); + oasDefinitionEdited = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "publisher" + File.separator + "oas3_with_default_oauth_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionEdited, response); + + // Testing API with swagger generated after APIM 2.x version, but with basic_auth and api_key security in the + // scheme which went with as an u2 update for 4.1, then later reverted. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "publisher" + File.separator + "oas3_with_apikey_basic_oauth_security_u2.json"), + StandardCharsets.UTF_8); + response = parser.getOASDefinitionForPublisher(api, swagger); + oasDefinitionEdited = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "publisher" + File.separator + "oas3_with_apikey_basic_oauth_security_u2_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionEdited, response); + } + + + @Test + public void testGetOASSecurityDefinitionForStore() throws Exception { + + // Testing API with migrated swagger coming from APIM version 2.x without any x-wso2-security or x-scopes. + String swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "publisher" + File.separator + "oas3_mig_without_sec_extensions.json"), + StandardCharsets.UTF_8); + APIIdentifier apiIdentifier = new APIIdentifier("admin", "PizzaShackAPI", "1.0.0"); + Map hostWithSchemes = new HashMap<>(); + hostWithSchemes.put(APIConstants.HTTPS_PROTOCOL, "https://localhost"); + API api = new API(apiIdentifier); + api.setApiSecurity("oauth_basic_auth_api_key_mandatory,oauth2"); // oauth2 security only + api.setTransports("https"); + api.setContext("/"); + api.setScopes(new HashSet<>()); + String response = oas3Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); + String oasDefinitionExpected = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "devportal" + File.separator + "oas3_mig_without_sec_extensions_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionExpected, response); + + // Testing API with migrated swagger coming from APIM version 2.x with x-wso2-security and x-scopes. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "publisher" + File.separator + "oas3_mig_with_sec_extensions.json"), StandardCharsets.UTF_8); + api.setScopes(getAPITestScopes()); + response = oas3Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); + oasDefinitionExpected = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "devportal" + File.separator + "oas3_mig_with_sec_extensions_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionExpected, response); + + // Testing API with swagger generated after APIM 2.x versions with oauth security definitions and x-wso2 + // extensions. API configured with all security. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "devportal" + File.separator + "oas3_with_default_allsecurity.json"), StandardCharsets.UTF_8); + api.setScopes(getAPITestScopes()); + api.setApiSecurity("oauth_basic_auth_api_key_mandatory,api_key,basic_auth,oauth2"); + response = oas3Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); + oasDefinitionExpected = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "devportal" + File.separator + "oas3_with_default_allsecurity_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionExpected, response); + // Testing API with swagger generated after APIM 2.x version, but with basic_auth and api_key security in + // the scheme which went with as an u2 update for 4.1, then later reverted. API configured with all security. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "publisher" + File.separator + "oas3_with_apikey_basic_oauth_security_u2.json"), + StandardCharsets.UTF_8); + response = oas3Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); + oasDefinitionExpected = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "devportal" + File.separator + "oas3_with_apikey_basic_oauth_security_u2_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionExpected, response); + // Testing API with swagger generated after APIM 2.x versions with oauth security definitions and x-wso2 + // extensions. API configured with basic auth and api key. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + + File.separator + "devportal" + File.separator + "oas3_with_basic_apisec.json"), + StandardCharsets.UTF_8); + api.setApiSecurity("oauth_basic_auth_api_key_mandatory,api_key,basic_auth"); + response = oas3Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); + oasDefinitionExpected = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "devportal" + File.separator + "oas3_with_basic_apisec_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionExpected, response); + // API configured with basic auth only. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "devportal" + File.separator + "oas3_with_basic.json"), StandardCharsets.UTF_8); + api.setApiSecurity("oauth_basic_auth_api_key_mandatory,basic_auth"); + response = oas3Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); + oasDefinitionExpected = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + + "devportal" + File.separator + "oas3_with_basic_response.json"), StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionExpected, response); + // API Configured with api key only. + swagger = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + + File.separator + "devportal" + File.separator + "oas3_with_apikey.json"), + StandardCharsets.UTF_8); + api.setApiSecurity("oauth_basic_auth_api_key_mandatory,api_key"); + response = oas3Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); + oasDefinitionExpected = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + + File.separator + "devportal" + File.separator + "oas3_with_apikey_response.json"), + StandardCharsets.UTF_8); + Assert.assertEquals(oasDefinitionExpected, response); + } + + private Set getAPITestScopes() { + Scope petLocalScope = new Scope(); + petLocalScope.setKey("OrderScope"); + petLocalScope.setName("OrderScope"); + petLocalScope.setRoles("admin"); + petLocalScope.setDescription(""); + Scope globalScope = new Scope(); + globalScope.setName("MenuScope"); + globalScope.setKey("MenuScope"); + globalScope.setDescription("description"); + globalScope.setRoles(""); + Set apiScopes = new LinkedHashSet<>(); + apiScopes.add(globalScope); + apiScopes.add(petLocalScope); + return apiScopes; + } } diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_mig_with_sec_extensions_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_mig_with_sec_extensions_response.json new file mode 100644 index 000000000000..a56f64df798c --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_mig_with_sec_extensions_response.json @@ -0,0 +1,91 @@ +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "OldAPI" + }, + "host": "localhost", + "basePath": "/oldapi", + "schemes": [ + "https" + ], + "security": [ + { + "default": [] + } + ], + "paths": { + "/test": { + "get": { + "parameters": [], + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-scope": "PetLocalScope" + }, + "post": { + "parameters": [ + { + "in": "body", + "name": "Payload", + "description": "Request Body", + "required": false, + "schema": { + "type": "object", + "properties": { + "payload": { + "type": "string" + } + } + } + } + ], + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-scope": "GlobalScope" + } + } + }, + "securityDefinitions": { + "default": { + "type": "oauth2", + "authorizationUrl": "https://localhost/authorize", + "flow": "implicit", + "scopes": { + "PetLocalScope": "", + "GlobalScope": "desc" + }, + "x-scopes-bindings": { + "PetLocalScope": "admin", + "GlobalScope": "" + } + } + }, + "x-wso2-security": { + "apim": { + "x-wso2-scopes": [ + { + "name": "PetLocalScope", + "description": "", + "key": "PetLocalScope", + "roles": "admin" + }, + { + "name": "GlobalScope", + "description": "desc", + "key": "GlobalScope", + "roles": "" + } + ] + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_mig_without_sec_extensions_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_mig_without_sec_extensions_response.json new file mode 100644 index 000000000000..c88e2dc8d323 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_mig_without_sec_extensions_response.json @@ -0,0 +1,64 @@ +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "OldAPI" + }, + "host": "localhost", + "basePath": "/oldapi", + "schemes": [ + "https" + ], + "security": [ + { + "default": [] + } + ], + "paths": { + "/test": { + "get": { + "parameters": [], + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited" + }, + "post": { + "parameters": [ + { + "in": "body", + "name": "Payload", + "description": "Request Body", + "required": false, + "schema": { + "type": "object", + "properties": { + "payload": { + "type": "string" + } + } + } + } + ], + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited" + } + } + }, + "securityDefinitions": { + "default": { + "type": "oauth2", + "authorizationUrl": "https://localhost/authorize", + "flow": "implicit", + "scopes": {} + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey.json new file mode 100644 index 000000000000..439163ec53e7 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey.json @@ -0,0 +1,221 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server.", + "version": "1.0.6", + "title": "SwaggerPetstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "petstore.swagger.io", + "basePath": "/v2", + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Access to Petstore orders" + }, + { + "name": "user", + "description": "Operations about user", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "schemes": [ + "https", + "http" + ], + "security": [ + { + "default": [] + } + ], + "paths": { + "/pet": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "default": [] + } + ], + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited" + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "default": [] + } + ], + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited" + } + } + }, + "securityDefinitions": { + "default": { + "type": "oauth2", + "authorizationUrl": "https://test.com", + "flow": "implicit", + "scopes": {} + } + }, + "definitions": { + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "Category" + } + }, + "Pet": { + "type": "object", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "example": "doggie" + }, + "photoUrls": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "type": "string", + "xml": { + "name": "photoUrl" + } + } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold" + ] + } + }, + "xml": { + "name": "Pet" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey_basic_oauth_security_u2.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey_basic_oauth_security_u2.json new file mode 100644 index 000000000000..d0ee1afb3459 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey_basic_oauth_security_u2.json @@ -0,0 +1,258 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server.", + "version": "1.0.6", + "title": "SwaggerPetstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "petstore.swagger.io", + "basePath": "/v2", + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Access to Petstore orders" + }, + { + "name": "user", + "description": "Operations about user", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "schemes": [ + "https", + "http" + ], + "security": [ + { + "default": [] + }, + { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "paths": { + "/pet": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "default": [ + "PetLocalScope", + "GlobalScope" + ] + }, + { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited" + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "default": [ + "PetLocalScope" + ] + }, { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited" + } + } + }, + "securityDefinitions": { + "default": { + "type": "oauth2", + "authorizationUrl": "https://test.com", + "flow": "implicit", + "scopes": { + "PetLocalScope": "", + "GlobalScope": "desc" + }, + "x-scopes-bindings": { + "PetLocalScope": "admin", + "GlobalScope": "" + } + }, + "basic_auth": { + "type": "basic" + }, + "api_key": { + "type": "apiKey", + "name": "apikey", + "in": "header" + } + }, + "definitions": { + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "Category" + } + }, + "Pet": { + "type": "object", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "example": "doggie" + }, + "photoUrls": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "type": "string", + "xml": { + "name": "photoUrl" + } + } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold" + ] + } + }, + "xml": { + "name": "Pet" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey_basic_oauth_security_u2_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey_basic_oauth_security_u2_response.json new file mode 100644 index 000000000000..00f13094c382 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey_basic_oauth_security_u2_response.json @@ -0,0 +1,273 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server.", + "version": "1.0.6", + "title": "SwaggerPetstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "localhost", + "basePath": "/v2", + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Access to Petstore orders" + }, + { + "name": "user", + "description": "Operations about user", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "schemes": [ + "https" + ], + "security": [ + { + "default": [] + }, + { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "paths": { + "/pet": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "default": [ + "PetLocalScope", + "GlobalScope" + ] + }, + { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-basic-auth-scopes": [ + "PetLocalScope", + "GlobalScope" + ] + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "default": [ + "PetLocalScope" + ] + }, + { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-basic-auth-scopes": [ + "PetLocalScope" + ] + } + } + }, + "securityDefinitions": { + "default": { + "type": "oauth2", + "authorizationUrl": "https://localhost/authorize", + "flow": "implicit", + "scopes": { + "PetLocalScope": "", + "GlobalScope": "desc" + }, + "x-scopes-bindings": { + "PetLocalScope": "admin", + "GlobalScope": "" + } + }, + "basic_auth": { + "type": "basic", + "x-scopes": { + "PetLocalScope": "", + "GlobalScope": "desc" + }, + "x-scopes-bindings": { + "PetLocalScope": "admin", + "GlobalScope": "" + } + }, + "api_key": { + "type": "apiKey", + "name": "apikey", + "in": "header" + } + }, + "definitions": { + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "Category" + } + }, + "Pet": { + "type": "object", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "example": "doggie" + }, + "photoUrls": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "type": "string", + "xml": { + "name": "photoUrl" + } + } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold" + ] + } + }, + "xml": { + "name": "Pet" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey_response.json new file mode 100644 index 000000000000..d43c30854a63 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_apikey_response.json @@ -0,0 +1,219 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server.", + "version": "1.0.6", + "title": "SwaggerPetstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "localhost", + "basePath": "/v2", + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Access to Petstore orders" + }, + { + "name": "user", + "description": "Operations about user", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "schemes": [ + "https" + ], + "security": [ + { + "api_key": [] + } + ], + "paths": { + "/pet": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "api_key": [] + } + ], + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited" + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "api_key": [] + } + ], + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited" + } + } + }, + "securityDefinitions": { + "api_key": { + "type": "apiKey", + "name": "apikey", + "in": "header" + } + }, + "definitions": { + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "Category" + } + }, + "Pet": { + "type": "object", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "example": "doggie" + }, + "photoUrls": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "type": "string", + "xml": { + "name": "photoUrl" + } + } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold" + ] + } + }, + "xml": { + "name": "Pet" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic.json new file mode 100644 index 000000000000..dfbc4042c9d4 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic.json @@ -0,0 +1,233 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server.", + "version": "1.0.6", + "title": "SwaggerPetstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "petstore.swagger.io", + "basePath": "/v2", + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Access to Petstore orders" + }, + { + "name": "user", + "description": "Operations about user", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "schemes": [ + "https", + "http" + ], + "security": [ + { + "default": [] + } + ], + "paths": { + "/pet": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "default": [ + "PetLocalScope", + "GlobalScope" + ] + } + ], + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited" + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "default": [ + "PetLocalScope" + ] + } + ], + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited" + } + } + }, + "securityDefinitions": { + "default": { + "type": "oauth2", + "authorizationUrl": "https://test.com", + "flow": "implicit", + "scopes": { + "PetLocalScope": "", + "GlobalScope": "desc" + }, + "x-scopes-bindings": { + "PetLocalScope": "admin", + "GlobalScope": "" + } + } + }, + "definitions": { + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "Category" + } + }, + "Pet": { + "type": "object", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "example": "doggie" + }, + "photoUrls": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "type": "string", + "xml": { + "name": "photoUrl" + } + } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold" + ] + } + }, + "xml": { + "name": "Pet" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic_apisec.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic_apisec.json new file mode 100644 index 000000000000..dfbc4042c9d4 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic_apisec.json @@ -0,0 +1,233 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server.", + "version": "1.0.6", + "title": "SwaggerPetstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "petstore.swagger.io", + "basePath": "/v2", + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Access to Petstore orders" + }, + { + "name": "user", + "description": "Operations about user", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "schemes": [ + "https", + "http" + ], + "security": [ + { + "default": [] + } + ], + "paths": { + "/pet": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "default": [ + "PetLocalScope", + "GlobalScope" + ] + } + ], + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited" + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "default": [ + "PetLocalScope" + ] + } + ], + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited" + } + } + }, + "securityDefinitions": { + "default": { + "type": "oauth2", + "authorizationUrl": "https://test.com", + "flow": "implicit", + "scopes": { + "PetLocalScope": "", + "GlobalScope": "desc" + }, + "x-scopes-bindings": { + "PetLocalScope": "admin", + "GlobalScope": "" + } + } + }, + "definitions": { + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "Category" + } + }, + "Pet": { + "type": "object", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "example": "doggie" + }, + "photoUrls": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "type": "string", + "xml": { + "name": "photoUrl" + } + } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold" + ] + } + }, + "xml": { + "name": "Pet" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic_apisec_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic_apisec_response.json new file mode 100644 index 000000000000..8ed05795530c --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic_apisec_response.json @@ -0,0 +1,246 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server.", + "version": "1.0.6", + "title": "SwaggerPetstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "localhost", + "basePath": "/v2", + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Access to Petstore orders" + }, + { + "name": "user", + "description": "Operations about user", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "schemes": [ + "https" + ], + "security": [ + { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "paths": { + "/pet": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-basic-auth-scopes": [ + "PetLocalScope", + "GlobalScope" + ] + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-basic-auth-scopes": [ + "PetLocalScope" + ] + } + } + }, + "securityDefinitions": { + "basic_auth": { + "type": "basic", + "x-scopes": { + "PetLocalScope": "", + "GlobalScope": "desc" + }, + "x-scopes-bindings": { + "PetLocalScope": "admin", + "GlobalScope": "" + } + }, + "api_key": { + "type": "apiKey", + "name": "apikey", + "in": "header" + } + }, + "definitions": { + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "Category" + } + }, + "Pet": { + "type": "object", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "example": "doggie" + }, + "photoUrls": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "type": "string", + "xml": { + "name": "photoUrl" + } + } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold" + ] + } + }, + "xml": { + "name": "Pet" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic_response.json new file mode 100644 index 000000000000..1bc1b0fc2412 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_basic_response.json @@ -0,0 +1,232 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server.", + "version": "1.0.6", + "title": "SwaggerPetstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "localhost", + "basePath": "/v2", + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Access to Petstore orders" + }, + { + "name": "user", + "description": "Operations about user", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "schemes": [ + "https" + ], + "security": [ + { + "basic_auth": [] + } + ], + "paths": { + "/pet": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "basic_auth": [] + } + ], + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-basic-auth-scopes": [ + "PetLocalScope", + "GlobalScope" + ] + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "basic_auth": [] + } + ], + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-basic-auth-scopes": [ + "PetLocalScope" + ] + } + } + }, + "securityDefinitions": { + "basic_auth": { + "type": "basic", + "x-scopes": { + "PetLocalScope": "", + "GlobalScope": "desc" + }, + "x-scopes-bindings": { + "PetLocalScope": "admin", + "GlobalScope": "" + } + } + }, + "definitions": { + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "Category" + } + }, + "Pet": { + "type": "object", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "example": "doggie" + }, + "photoUrls": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "type": "string", + "xml": { + "name": "photoUrl" + } + } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold" + ] + } + }, + "xml": { + "name": "Pet" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_default_allsecurity.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_default_allsecurity.json new file mode 100644 index 000000000000..dfbc4042c9d4 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_default_allsecurity.json @@ -0,0 +1,233 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server.", + "version": "1.0.6", + "title": "SwaggerPetstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "petstore.swagger.io", + "basePath": "/v2", + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Access to Petstore orders" + }, + { + "name": "user", + "description": "Operations about user", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "schemes": [ + "https", + "http" + ], + "security": [ + { + "default": [] + } + ], + "paths": { + "/pet": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "default": [ + "PetLocalScope", + "GlobalScope" + ] + } + ], + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited" + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "default": [ + "PetLocalScope" + ] + } + ], + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited" + } + } + }, + "securityDefinitions": { + "default": { + "type": "oauth2", + "authorizationUrl": "https://test.com", + "flow": "implicit", + "scopes": { + "PetLocalScope": "", + "GlobalScope": "desc" + }, + "x-scopes-bindings": { + "PetLocalScope": "admin", + "GlobalScope": "" + } + } + }, + "definitions": { + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "Category" + } + }, + "Pet": { + "type": "object", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "example": "doggie" + }, + "photoUrls": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "type": "string", + "xml": { + "name": "photoUrl" + } + } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold" + ] + } + }, + "xml": { + "name": "Pet" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_default_allsecurity_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_default_allsecurity_response.json new file mode 100644 index 000000000000..00f13094c382 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/devportal/oas2_with_default_allsecurity_response.json @@ -0,0 +1,273 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server.", + "version": "1.0.6", + "title": "SwaggerPetstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "localhost", + "basePath": "/v2", + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Access to Petstore orders" + }, + { + "name": "user", + "description": "Operations about user", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "schemes": [ + "https" + ], + "security": [ + { + "default": [] + }, + { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "paths": { + "/pet": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "default": [ + "PetLocalScope", + "GlobalScope" + ] + }, + { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-basic-auth-scopes": [ + "PetLocalScope", + "GlobalScope" + ] + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "default": [ + "PetLocalScope" + ] + }, + { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-basic-auth-scopes": [ + "PetLocalScope" + ] + } + } + }, + "securityDefinitions": { + "default": { + "type": "oauth2", + "authorizationUrl": "https://localhost/authorize", + "flow": "implicit", + "scopes": { + "PetLocalScope": "", + "GlobalScope": "desc" + }, + "x-scopes-bindings": { + "PetLocalScope": "admin", + "GlobalScope": "" + } + }, + "basic_auth": { + "type": "basic", + "x-scopes": { + "PetLocalScope": "", + "GlobalScope": "desc" + }, + "x-scopes-bindings": { + "PetLocalScope": "admin", + "GlobalScope": "" + } + }, + "api_key": { + "type": "apiKey", + "name": "apikey", + "in": "header" + } + }, + "definitions": { + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "Category" + } + }, + "Pet": { + "type": "object", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "example": "doggie" + }, + "photoUrls": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "type": "string", + "xml": { + "name": "photoUrl" + } + } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold" + ] + } + }, + "xml": { + "name": "Pet" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_with_sec_extensions.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_with_sec_extensions.json new file mode 100644 index 000000000000..af2b3acf6650 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_with_sec_extensions.json @@ -0,0 +1,65 @@ +{ + "swagger": "2.0", + "paths": { + "/test": { + "get": { + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited", + "x-scope": "PetLocalScope" + }, + "post": { + "parameters": [ + { + "name": "Payload", + "description": "Request Body", + "required": false, + "in": "body", + "schema": { + "type": "object", + "properties": { + "payload": { + "type": "string" + } + } + } + } + ], + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited", + "x-scope": "GlobalScope" + } + } + }, + "info": { + "title": "OldAPI", + "version": "1.0.0" + }, + "x-wso2-security": { + "apim": { + "x-wso2-scopes": [ + { + "name": "PetLocalScope", + "description": "", + "key": "PetLocalScope", + "roles": "admin" + }, + { + "name": "GlobalScope", + "description": "desc", + "key": "GlobalScope", + "roles": "" + } + ] + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_with_sec_extensions_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_with_sec_extensions_response.json new file mode 100644 index 000000000000..82a2ee4af597 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_with_sec_extensions_response.json @@ -0,0 +1,88 @@ +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "OldAPI" + }, + "paths": { + "/test": { + "get": { + "parameters": [], + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-scope": "PetLocalScope", + "x-wso2-application-security": { + "security-types": [ + "oauth2" + ], + "optional": false + } + }, + "post": { + "parameters": [ + { + "in": "body", + "name": "Payload", + "description": "Request Body", + "required": false, + "schema": { + "type": "object", + "properties": { + "payload": { + "type": "string" + } + } + } + } + ], + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-scope": "GlobalScope", + "x-wso2-application-security": { + "security-types": [ + "oauth2" + ], + "optional": false + } + } + } + }, + "x-wso2-security": { + "apim": { + "x-wso2-scopes": [ + { + "name": "PetLocalScope", + "description": "", + "key": "PetLocalScope", + "roles": "admin" + }, + { + "name": "GlobalScope", + "description": "desc", + "key": "GlobalScope", + "roles": "" + } + ] + } + }, + "x-wso2-application-security": { + "security-types": [ + "oauth2" + ], + "optional": false + }, + "x-wso2-response-cache": { + "enabled": false, + "cacheTimeoutInSeconds": 0 + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_without_sec_extensions.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_without_sec_extensions.json new file mode 100644 index 000000000000..714664a5134f --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_without_sec_extensions.json @@ -0,0 +1,46 @@ +{ + "swagger": "2.0", + "info": { + "title": "OldAPI", + "version": "1.0.0" + }, + "paths": { + "/test": { + "get": { + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited" + }, + "post": { + "parameters": [ + { + "name": "Payload", + "description": "Request Body", + "required": false, + "in": "body", + "schema": { + "type": "object", + "properties": { + "payload": { + "type": "string" + } + } + } + } + ], + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited" + } + } + } + +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_without_sec_extensions_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_without_sec_extensions_response.json new file mode 100644 index 000000000000..4c1cc989b89a --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_mig_without_sec_extensions_response.json @@ -0,0 +1,68 @@ +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "OldAPI" + }, + "paths": { + "/test": { + "get": { + "parameters": [], + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-wso2-application-security": { + "security-types": [ + "oauth2" + ], + "optional": false + } + }, + "post": { + "parameters": [ + { + "in": "body", + "name": "Payload", + "description": "Request Body", + "required": false, + "schema": { + "type": "object", + "properties": { + "payload": { + "type": "string" + } + } + } + } + ], + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-wso2-application-security": { + "security-types": [ + "oauth2" + ], + "optional": false + } + } + } + }, + "x-wso2-application-security": { + "security-types": [ + "oauth2" + ], + "optional": false + }, + "x-wso2-response-cache": { + "enabled": false, + "cacheTimeoutInSeconds": 0 + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_apikey_basic_oauth_security_u2.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_apikey_basic_oauth_security_u2.json new file mode 100644 index 000000000000..13a55781c909 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_apikey_basic_oauth_security_u2.json @@ -0,0 +1,286 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server.", + "version": "1.0.6", + "title": "Swagger Petstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "petstore.swagger.io", + "basePath": "/v2", + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Access to Petstore orders" + }, + { + "name": "user", + "description": "Operations about user", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "schemes": [ + "https", + "http" + ], + "security": [ + { + "default": [] + }, + { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "paths": { + "/pet": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "default": [ + "PetLocalScope", + "GlobalScope" + ] + }, + { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited", + "x-wso2-application-security": { + "security-types": [ + "api_key", + "basic_auth", + "oauth2" + ], + "optional": false + } + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "default": [ + "PetLocalScope" + ] + }, { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited", + "x-wso2-application-security": { + "security-types": [ + "api_key", + "basic_auth", + "oauth2" + ], + "optional": false + } + } + } + }, + "securityDefinitions": { + "default": { + "type": "oauth2", + "authorizationUrl": "https://test.com", + "flow": "implicit", + "scopes": { + "PetLocalScope": "admin", + "GlobalScope": "desc" + }, + "x-scopes-bindings": { + "GlobalScope": "admin", + "PetLocalScope": "" + } + }, + "basic_auth": { + "type": "basic" + }, + "api_key": { + "type": "apiKey", + "name": "apikey", + "in": "header" + } + }, + "definitions": { + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "Category" + } + }, + "Pet": { + "type": "object", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "example": "doggie" + }, + "photoUrls": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "type": "string", + "xml": { + "name": "photoUrl" + } + } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold" + ] + } + }, + "xml": { + "name": "Pet" + } + } + }, + "x-wso2-application-security": { + "security-types": [ + "api_key", + "basic_auth", + "oauth2" + ], + "optional": false + }, + "x-wso2-response-cache": { + "enabled": false, + "cacheTimeoutInSeconds": 0 + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_apikey_basic_oauth_security_u2_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_apikey_basic_oauth_security_u2_response.json new file mode 100644 index 000000000000..f198b5b068b8 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_apikey_basic_oauth_security_u2_response.json @@ -0,0 +1,261 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server.", + "version": "1.0.6", + "title": "Swagger Petstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "petstore.swagger.io", + "basePath": "/v2", + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Access to Petstore orders" + }, + { + "name": "user", + "description": "Operations about user", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "schemes": [ + "https", + "http" + ], + "security": [ + { + "default": [] + } + ], + "paths": { + "/pet": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "default": [ + "PetLocalScope", + "GlobalScope" + ] + } + ], + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-wso2-application-security": { + "security-types": [ + "api_key", + "basic_auth", + "oauth2" + ], + "optional": false + } + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "default": [ + "PetLocalScope" + ] + } + ], + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-wso2-application-security": { + "security-types": [ + "api_key", + "basic_auth", + "oauth2" + ], + "optional": false + } + } + } + }, + "securityDefinitions": { + "default": { + "type": "oauth2", + "authorizationUrl": "https://test.com", + "flow": "implicit", + "scopes": { + "PetLocalScope": "admin", + "GlobalScope": "desc" + }, + "x-scopes-bindings": { + "GlobalScope": "admin", + "PetLocalScope": "" + } + } + }, + "definitions": { + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "Category" + } + }, + "Pet": { + "type": "object", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "example": "doggie" + }, + "photoUrls": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "type": "string", + "xml": { + "name": "photoUrl" + } + } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold" + ] + } + }, + "xml": { + "name": "Pet" + } + } + }, + "x-wso2-application-security": { + "security-types": [ + "api_key", + "basic_auth", + "oauth2" + ], + "optional": false + }, + "x-wso2-response-cache": { + "enabled": false, + "cacheTimeoutInSeconds": 0 + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth.json new file mode 100644 index 000000000000..4dbf41e5b87e --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth.json @@ -0,0 +1,302 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server.", + "version": "1.0.6", + "title": "SwaggerPetstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "petstore.swagger.io", + "basePath": "/v2", + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Access to Petstore orders" + }, + { + "name": "user", + "description": "Operations about user", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "schemes": [ + "https", + "http" + ], + "security": [ + { + "default": [] + } + ], + "paths": { + "/pet": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "default": [ + "PetLocalScope", + "GlobalScope" + ] + } + ], + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited", + "x-wso2-application-security": { + "security-types": [ + "oauth2", + "basic_auth", + "api_key" + ], + "optional": false + } + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "default": [ + "PetLocalScope" + ] + } + ], + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited", + "x-wso2-application-security": { + "security-types": [ + "oauth2", + "basic_auth", + "api_key" + ], + "optional": false + } + } + } + }, + "securityDefinitions": { + "default": { + "type": "oauth2", + "authorizationUrl": "https://test.com", + "flow": "implicit", + "scopes": { + "PetLocalScope": "admin", + "GlobalScope": "desc" + }, + "x-scopes-bindings": { + "GlobalScope": "admin", + "PetLocalScope": "" + } + } + }, + "definitions": { + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "Category" + } + }, + "Pet": { + "type": "object", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "example": "doggie" + }, + "photoUrls": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "type": "string", + "xml": { + "name": "photoUrl" + } + } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold" + ] + } + }, + "xml": { + "name": "Pet" + } + } + }, + "x-wso2-auth-header": "Authorization", + "x-wso2-cors": { + "corsConfigurationEnabled": false, + "accessControlAllowOrigins": [ + "*" + ], + "accessControlAllowCredentials": false, + "accessControlAllowHeaders": [ + "authorization", + "Access-Control-Allow-Origin", + "Content-Type", + "SOAPAction", + "apikey", + "Internal-Key" + ], + "accessControlAllowMethods": [ + "GET", + "PUT", + "POST", + "DELETE", + "PATCH", + "OPTIONS" + ] + }, + "x-wso2-production-endpoints": { + "urls": [ + "https://www.petstore.swagger.io" + ], + "type": "http" + }, + "x-wso2-sandbox-endpoints": { + "urls": [ + "https://www.petstore.swagger.io" + ], + "type": "http" + }, + "x-wso2-basePath": "/v2/1.0.6", + "x-wso2-transports": [ + "http", + "https" + ], + "x-wso2-application-security": { + "security-types": [ + "oauth2", + "basic_auth", + "api_key" + ], + "optional": false + }, + "x-wso2-response-cache": { + "enabled": false, + "cacheTimeoutInSeconds": 300 + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth_response.json new file mode 100644 index 000000000000..f5f6a43f23b7 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth_response.json @@ -0,0 +1,278 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server.", + "version": "1.0.6", + "title": "SwaggerPetstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "petstore.swagger.io", + "basePath": "/v2", + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Access to Petstore orders" + }, + { + "name": "user", + "description": "Operations about user", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "schemes": [ + "https", + "http" + ], + "security": [ + { + "default": [] + } + ], + "paths": { + "/pet": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "default": [ + "PetLocalScope", + "GlobalScope" + ] + } + ], + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-wso2-application-security": { + "security-types": [ + "api_key", + "basic_auth", + "oauth2" + ], + "optional": false + } + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "default": [ + "PetLocalScope" + ] + } + ], + "x-auth-type": "Application \u0026 Application User", + "x-throttling-tier": "Unlimited", + "x-wso2-application-security": { + "security-types": [ + "api_key", + "basic_auth", + "oauth2" + ], + "optional": false + } + } + } + }, + "securityDefinitions": { + "default": { + "type": "oauth2", + "authorizationUrl": "https://test.com", + "flow": "implicit", + "scopes": { + "PetLocalScope": "admin", + "GlobalScope": "desc" + }, + "x-scopes-bindings": { + "GlobalScope": "admin", + "PetLocalScope": "" + } + } + }, + "definitions": { + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "Category" + } + }, + "Pet": { + "type": "object", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "example": "doggie" + }, + "photoUrls": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "type": "string", + "xml": { + "name": "photoUrl" + } + } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold" + ] + } + }, + "xml": { + "name": "Pet" + } + } + }, + "x-wso2-auth-header": "Authorization", + "x-wso2-production-endpoints": { + "urls": [ + "https://www.petstore.swagger.io" + ], + "type": "http" + }, + "x-wso2-sandbox-endpoints": { + "urls": [ + "https://www.petstore.swagger.io" + ], + "type": "http" + }, + "x-wso2-transports": [ + "http", + "https" + ], + "x-wso2-application-security": { + "security-types": [ + "oauth2", + "basic_auth", + "api_key" + ], + "optional": false + }, + "x-wso2-response-cache": { + "enabled": false, + "cacheTimeoutInSeconds": 0 + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_mig_with_sec_extensions_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_mig_with_sec_extensions_response.json new file mode 100644 index 000000000000..b8c134a3e79c --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_mig_with_sec_extensions_response.json @@ -0,0 +1,104 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "https://localhost/" + } ], + "security" : [ { + "default" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "requestBody" : { + "description" : "Request Body", + "content" : { + "application/json" : { + "schema" : { + "type" : "object", + "properties" : { + "payload" : { + "type" : "string" + } + } + } + } + }, + "required" : true + }, + "responses" : { + "200" : { + "description" : "" + } + }, + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-scope" : "MenuScope" + }, + "post" : { + "requestBody" : { + "description" : "Request Body", + "content" : { + "application/json" : { + "schema" : { + "type" : "object", + "properties" : { + "payload" : { + "type" : "string" + } + } + } + } + }, + "required" : true + }, + "responses" : { + "200" : { + "description" : "" + } + }, + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-scope" : "OrderScope" + } + } + }, + "components" : { + "securitySchemes" : { + "default" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "https://localhost/authorize", + "scopes" : { + "OrderScope" : "", + "MenuScope" : "description" + }, + "x-scopes-bindings" : { + "OrderScope" : "admin", + "MenuScope" : "" + } + } + } + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "OrderScope", + "description" : "", + "key" : "OrderScope", + "roles" : "admin" + }, { + "name" : "MenuScope", + "description" : "description", + "key" : "MenuScope", + "roles" : "" + } ] + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_mig_without_sec_extensions_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_mig_without_sec_extensions_response.json new file mode 100644 index 000000000000..7680792db7e2 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_mig_without_sec_extensions_response.json @@ -0,0 +1,80 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "https://localhost/" + } ], + "security" : [ { + "default" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "requestBody" : { + "description" : "Request Body", + "content" : { + "application/json" : { + "schema" : { + "type" : "object", + "properties" : { + "payload" : { + "type" : "string" + } + } + } + } + }, + "required" : true + }, + "responses" : { + "200" : { + "description" : "" + } + }, + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + }, + "post" : { + "requestBody" : { + "description" : "Request Body", + "content" : { + "application/json" : { + "schema" : { + "type" : "object", + "properties" : { + "payload" : { + "type" : "string" + } + } + } + } + }, + "required" : true + }, + "responses" : { + "200" : { + "description" : "" + } + }, + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + } + } + }, + "components" : { + "securitySchemes" : { + "default" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "https://localhost/authorize", + "scopes" : { } + } + } + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_apikey.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_apikey.json new file mode 100644 index 000000000000..cb953aa35969 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_apikey.json @@ -0,0 +1,73 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "description" : "This is a RESTFul API for Pizza Shack online pizza delivery store.\n", + "contact" : { + "name" : "John Doe", + "url" : "http://www.pizzashack.com", + "email" : "architecture@pizzashack.com" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "/" + } ], + "security" : [ { + "default" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "MenuScope" ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + }, + "post" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "OrderScope", "MenuScope" ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + } + } + }, + "components" : { + "securitySchemes" : { + "default" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "https://localhost/authorize", + "scopes" : { + "OrderScope" : "", + "MenuScope" : "description" + }, + "x-scopes-bindings" : { + "OrderScope" : "admin", + "MenuScope" : "" + } + } + } + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_apikey_basic_oauth_security_u2_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_apikey_basic_oauth_security_u2_response.json new file mode 100644 index 000000000000..331e99bfb961 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_apikey_basic_oauth_security_u2_response.json @@ -0,0 +1,96 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "description" : "This is a RESTFul API for Pizza Shack online pizza delivery store.\n", + "contact" : { + "name" : "John Doe", + "url" : "http://www.pizzashack.com", + "email" : "architecture@pizzashack.com" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "https://localhost/" + } ], + "security" : [ { + "default" : [ ] + }, { + "basic_auth" : [ ] + }, { + "api_key" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "MenuScope" ] + }, { + "basic_auth" : [ ] + }, { + "api_key" : [ ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-basic-auth-scopes" : [ "MenuScope" ] + }, + "post" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "OrderScope", "MenuScope" ] + }, { + "basic_auth" : [ ] + }, { + "api_key" : [ ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-basic-auth-scopes" : [ "OrderScope", "MenuScope" ] + } + } + }, + "components" : { + "securitySchemes" : { + "basic_auth" : { + "type" : "http", + "scheme" : "Basic" + }, + "default" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "https://localhost/authorize", + "scopes" : { + "OrderScope" : "", + "MenuScope" : "description" + }, + "x-scopes-bindings" : { + "OrderScope" : "admin", + "MenuScope" : "" + } + } + } + }, + "api_key" : { + "type" : "apiKey", + "name" : "apikey", + "in" : "header" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_apikey_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_apikey_response.json new file mode 100644 index 000000000000..9c5479124a84 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_apikey_response.json @@ -0,0 +1,62 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "description" : "This is a RESTFul API for Pizza Shack online pizza delivery store.\n", + "contact" : { + "name" : "John Doe", + "url" : "http://www.pizzashack.com", + "email" : "architecture@pizzashack.com" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "https://localhost/" + } ], + "security" : [ { + "api_key" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "api_key" : [ ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + }, + "post" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "api_key" : [ ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + } + } + }, + "components" : { + "securitySchemes" : { + "api_key" : { + "type" : "apiKey", + "name" : "apikey", + "in" : "header" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic.json new file mode 100644 index 000000000000..cb953aa35969 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic.json @@ -0,0 +1,73 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "description" : "This is a RESTFul API for Pizza Shack online pizza delivery store.\n", + "contact" : { + "name" : "John Doe", + "url" : "http://www.pizzashack.com", + "email" : "architecture@pizzashack.com" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "/" + } ], + "security" : [ { + "default" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "MenuScope" ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + }, + "post" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "OrderScope", "MenuScope" ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + } + } + }, + "components" : { + "securitySchemes" : { + "default" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "https://localhost/authorize", + "scopes" : { + "OrderScope" : "", + "MenuScope" : "description" + }, + "x-scopes-bindings" : { + "OrderScope" : "admin", + "MenuScope" : "" + } + } + } + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic_apisec.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic_apisec.json new file mode 100644 index 000000000000..cb953aa35969 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic_apisec.json @@ -0,0 +1,73 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "description" : "This is a RESTFul API for Pizza Shack online pizza delivery store.\n", + "contact" : { + "name" : "John Doe", + "url" : "http://www.pizzashack.com", + "email" : "architecture@pizzashack.com" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "/" + } ], + "security" : [ { + "default" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "MenuScope" ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + }, + "post" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "OrderScope", "MenuScope" ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + } + } + }, + "components" : { + "securitySchemes" : { + "default" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "https://localhost/authorize", + "scopes" : { + "OrderScope" : "", + "MenuScope" : "description" + }, + "x-scopes-bindings" : { + "OrderScope" : "admin", + "MenuScope" : "" + } + } + } + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic_apisec_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic_apisec_response.json new file mode 100644 index 000000000000..deea57676377 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic_apisec_response.json @@ -0,0 +1,82 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "description" : "This is a RESTFul API for Pizza Shack online pizza delivery store.\n", + "contact" : { + "name" : "John Doe", + "url" : "http://www.pizzashack.com", + "email" : "architecture@pizzashack.com" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "https://localhost/" + } ], + "security" : [ { + "basic_auth" : [ ] + }, { + "api_key" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "basic_auth" : [ ] + }, { + "api_key" : [ ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-basic-auth-scopes" : [ "MenuScope" ] + }, + "post" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "basic_auth" : [ ] + }, { + "api_key" : [ ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-basic-auth-scopes" : [ "OrderScope", "MenuScope" ] + } + } + }, + "components" : { + "securitySchemes" : { + "basic_auth" : { + "type" : "http", + "scheme" : "basic", + "x-scopes" : { + "OrderScope" : "", + "MenuScope" : "description" + }, + "x-scopes-bindings" : { + "OrderScope" : "admin", + "MenuScope" : "" + } + }, + "api_key" : { + "type" : "apiKey", + "name" : "apikey", + "in" : "header" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic_response.json new file mode 100644 index 000000000000..65ad39c416d9 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_basic_response.json @@ -0,0 +1,71 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "description" : "This is a RESTFul API for Pizza Shack online pizza delivery store.\n", + "contact" : { + "name" : "John Doe", + "url" : "http://www.pizzashack.com", + "email" : "architecture@pizzashack.com" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "https://localhost/" + } ], + "security" : [ { + "basic_auth" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "basic_auth" : [ ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-basic-auth-scopes" : [ "MenuScope" ] + }, + "post" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "basic_auth" : [ ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-basic-auth-scopes" : [ "OrderScope", "MenuScope" ] + } + } + }, + "components" : { + "securitySchemes" : { + "basic_auth" : { + "type" : "http", + "scheme" : "basic", + "x-scopes" : { + "OrderScope" : "", + "MenuScope" : "description" + }, + "x-scopes-bindings" : { + "OrderScope" : "admin", + "MenuScope" : "" + } + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_default_allsecurity.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_default_allsecurity.json new file mode 100644 index 000000000000..9ae98ae825d8 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_default_allsecurity.json @@ -0,0 +1,73 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "description" : "This is a RESTFul API for Pizza Shack online pizza delivery store.\n", + "contact" : { + "name" : "John Doe", + "url" : "http://www.pizzashack.com", + "email" : "architecture@pizzashack.com" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "/" + } ], + "security" : [ { + "default" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "MenuScope" ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + }, + "post" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "OrderScope", "MenuScope" ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + } + } + }, + "components" : { + "securitySchemes" : { + "default" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "https://test.com", + "scopes" : { + "OrderScope": "", + "MenuScope": "description" + }, + "x-scopes-bindings": { + "OrderScope": "admin", + "MenuScope": "" + } + } + } + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_default_allsecurity_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_default_allsecurity_response.json new file mode 100644 index 000000000000..44e16fce415d --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/devportal/oas3_with_default_allsecurity_response.json @@ -0,0 +1,104 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "description" : "This is a RESTFul API for Pizza Shack online pizza delivery store.\n", + "contact" : { + "name" : "John Doe", + "url" : "http://www.pizzashack.com", + "email" : "architecture@pizzashack.com" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "https://localhost/" + } ], + "security" : [ { + "default" : [ ] + }, { + "basic_auth" : [ ] + }, { + "api_key" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "MenuScope" ] + }, { + "basic_auth" : [ ] + }, { + "api_key" : [ ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-basic-auth-scopes" : [ "MenuScope" ] + }, + "post" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "OrderScope", "MenuScope" ] + }, { + "basic_auth" : [ ] + }, { + "api_key" : [ ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-basic-auth-scopes" : [ "OrderScope", "MenuScope" ] + } + } + }, + "components" : { + "securitySchemes" : { + "default" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "https://localhost/authorize", + "scopes" : { + "OrderScope" : "", + "MenuScope" : "description" + }, + "x-scopes-bindings" : { + "OrderScope" : "admin", + "MenuScope" : "" + } + } + } + }, + "basic_auth" : { + "type" : "http", + "scheme" : "basic", + "x-scopes" : { + "OrderScope" : "", + "MenuScope" : "description" + }, + "x-scopes-bindings" : { + "OrderScope" : "admin", + "MenuScope" : "" + } + }, + "api_key" : { + "type" : "apiKey", + "name" : "apikey", + "in" : "header" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_with_sec_extensions.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_with_sec_extensions.json new file mode 100644 index 000000000000..04a2a2ecc019 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_with_sec_extensions.json @@ -0,0 +1,81 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "PizzaShackAPI", + "version": "1.0.0" + }, + "paths": { + "/test": { + "post": { + "requestBody": { + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "payload": { + "type": "string" + } + } + } + } + }, + "required": true, + "description": "Request Body" + }, + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited", + "x-scope": "OrderScope" + }, + "put": { + "requestBody": { + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "payload": { + "type": "string" + } + } + } + } + }, + "required": true, + "description": "Request Body" + }, + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited", + "x-scope": "MenuScope" + } + } + }, + "x-wso2-security": { + "apim": { + "x-wso2-scopes": [ + { + "name": "OrderScope", + "description": "", + "key": "OrderScope", + "roles": "admin" + }, + { + "name": "MenuScope", + "description": "description", + "key": "MenuScope", + "roles": "" + } + ] + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_with_sec_extensions_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_with_sec_extensions_response.json new file mode 100644 index 000000000000..fdd9bfe47c47 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_with_sec_extensions_response.json @@ -0,0 +1,113 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "/" + } ], + "security" : [ { + "default" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "requestBody" : { + "description" : "Request Body", + "content" : { + "application/json" : { + "schema" : { + "type" : "object", + "properties" : { + "payload" : { + "type" : "string" + } + } + } + } + }, + "required" : true + }, + "responses" : { + "200" : { + "description" : "" + } + }, + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-scope" : "MenuScope", + "x-wso2-application-security" : { + "security-types" : [ "oauth2" ], + "optional" : false + } + }, + "post" : { + "requestBody" : { + "description" : "Request Body", + "content" : { + "application/json" : { + "schema" : { + "type" : "object", + "properties" : { + "payload" : { + "type" : "string" + } + } + } + } + }, + "required" : true + }, + "responses" : { + "200" : { + "description" : "" + } + }, + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-scope" : "OrderScope", + "x-wso2-application-security" : { + "security-types" : [ "oauth2" ], + "optional" : false + } + } + } + }, + "components" : { + "securitySchemes" : { + "default" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "https://test.com", + "scopes" : { } + } + } + } + } + }, + "x-wso2-security" : { + "apim" : { + "x-wso2-scopes" : [ { + "name" : "OrderScope", + "description" : "", + "key" : "OrderScope", + "roles" : "admin" + }, { + "name" : "MenuScope", + "description" : "description", + "key" : "MenuScope", + "roles" : "" + } ] + } + }, + "x-wso2-application-security" : { + "security-types" : [ "oauth2" ], + "optional" : false + }, + "x-wso2-response-cache" : { + "enabled" : false, + "cacheTimeoutInSeconds" : 0 + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_without_sec_extensions.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_without_sec_extensions.json new file mode 100644 index 000000000000..c064aa77641c --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_without_sec_extensions.json @@ -0,0 +1,61 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "PizzaShackAPI", + "version": "1.0.0" + }, + "paths": { + "/test": { + "post": { + "requestBody": { + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "payload": { + "type": "string" + } + } + } + } + }, + "required": true, + "description": "Request Body" + }, + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited" + }, + "put": { + "requestBody": { + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "payload": { + "type": "string" + } + } + } + } + }, + "required": true, + "description": "Request Body" + }, + "responses": { + "200": { + "description": "" + } + }, + "x-auth-type": "Application & Application User", + "x-throttling-tier": "Unlimited" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_without_sec_extensions_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_without_sec_extensions_response.json new file mode 100644 index 000000000000..57958de62ee2 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_mig_without_sec_extensions_response.json @@ -0,0 +1,96 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "/" + } ], + "security" : [ { + "default" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "requestBody" : { + "description" : "Request Body", + "content" : { + "application/json" : { + "schema" : { + "type" : "object", + "properties" : { + "payload" : { + "type" : "string" + } + } + } + } + }, + "required" : true + }, + "responses" : { + "200" : { + "description" : "" + } + }, + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-wso2-application-security" : { + "security-types" : [ "oauth2" ], + "optional" : false + } + }, + "post" : { + "requestBody" : { + "description" : "Request Body", + "content" : { + "application/json" : { + "schema" : { + "type" : "object", + "properties" : { + "payload" : { + "type" : "string" + } + } + } + } + }, + "required" : true + }, + "responses" : { + "200" : { + "description" : "" + } + }, + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-wso2-application-security" : { + "security-types" : [ "oauth2" ], + "optional" : false + } + } + } + }, + "components" : { + "securitySchemes" : { + "default" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "https://test.com", + "scopes" : { } + } + } + } + } + }, + "x-wso2-application-security" : { + "security-types" : [ "oauth2" ], + "optional" : false + }, + "x-wso2-response-cache" : { + "enabled" : false, + "cacheTimeoutInSeconds" : 0 + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_apikey_basic_oauth_security_u2.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_apikey_basic_oauth_security_u2.json new file mode 100644 index 000000000000..19045c0e30bf --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_apikey_basic_oauth_security_u2.json @@ -0,0 +1,95 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "description" : "This is a RESTFul API for Pizza Shack online pizza delivery store.\n", + "contact" : { + "name" : "John Doe", + "url" : "http://www.pizzashack.com", + "email" : "architecture@pizzashack.com" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "/" + } ], + "security" : [{ + "default": [] + }, + { + "basic_auth": [] + }, + { + "api_key": [] + } + ], + "paths" : { + "/test" : { + "put" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "MenuScope" ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + }, + "post" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "OrderScope", "MenuScope" ] + }, + { + "basic_auth": [ ] + }, + { + "api_key": [ ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + } + } + }, + "components" : { + "securitySchemes" : { + "basic_auth": { + "type": "http", + "scheme": "Basic" + }, + "default" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "https://test.com", + "scopes" : { + "OrderScope": "", + "MenuScope": "description" + }, + "x-scopes-bindings": { + "OrderScope": "admin", + "MenuScope": "" + } + } + } + }, + "api_key": { + "type": "apiKey", + "name": "apikey", + "in": "header" + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_apikey_basic_oauth_security_u2_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_apikey_basic_oauth_security_u2_response.json new file mode 100644 index 000000000000..7b7b8bb451a1 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_apikey_basic_oauth_security_u2_response.json @@ -0,0 +1,89 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "description" : "This is a RESTFul API for Pizza Shack online pizza delivery store.\n", + "contact" : { + "name" : "John Doe", + "url" : "http://www.pizzashack.com", + "email" : "architecture@pizzashack.com" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "/" + } ], + "security" : [ { + "default" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "MenuScope" ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-wso2-application-security" : { + "security-types" : [ "api_key", "basic_auth", "oauth2" ], + "optional" : false + } + }, + "post" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "OrderScope", "MenuScope" ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-wso2-application-security" : { + "security-types" : [ "api_key", "basic_auth", "oauth2" ], + "optional" : false + } + } + } + }, + "components" : { + "securitySchemes" : { + "default" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "https://test.com", + "scopes" : { + "OrderScope" : "", + "MenuScope" : "description" + }, + "x-scopes-bindings" : { + "OrderScope" : "admin", + "MenuScope" : "" + } + } + } + } + } + }, + "x-wso2-application-security" : { + "security-types" : [ "api_key", "basic_auth", "oauth2" ], + "optional" : false + }, + "x-wso2-response-cache" : { + "enabled" : false, + "cacheTimeoutInSeconds" : 0 + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_default_oauth.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_default_oauth.json new file mode 100644 index 000000000000..9ae98ae825d8 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_default_oauth.json @@ -0,0 +1,73 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "description" : "This is a RESTFul API for Pizza Shack online pizza delivery store.\n", + "contact" : { + "name" : "John Doe", + "url" : "http://www.pizzashack.com", + "email" : "architecture@pizzashack.com" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "/" + } ], + "security" : [ { + "default" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "MenuScope" ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + }, + "post" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "OrderScope", "MenuScope" ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited" + } + } + }, + "components" : { + "securitySchemes" : { + "default" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "https://test.com", + "scopes" : { + "OrderScope": "", + "MenuScope": "description" + }, + "x-scopes-bindings": { + "OrderScope": "admin", + "MenuScope": "" + } + } + } + } + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_default_oauth_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_default_oauth_response.json new file mode 100644 index 000000000000..7b7b8bb451a1 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas3/publisher/oas3_with_default_oauth_response.json @@ -0,0 +1,89 @@ +{ + "openapi" : "3.0.0", + "info" : { + "title" : "PizzaShackAPI", + "description" : "This is a RESTFul API for Pizza Shack online pizza delivery store.\n", + "contact" : { + "name" : "John Doe", + "url" : "http://www.pizzashack.com", + "email" : "architecture@pizzashack.com" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version" : "1.0.0" + }, + "servers" : [ { + "url" : "/" + } ], + "security" : [ { + "default" : [ ] + } ], + "paths" : { + "/test" : { + "put" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "MenuScope" ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-wso2-application-security" : { + "security-types" : [ "api_key", "basic_auth", "oauth2" ], + "optional" : false + } + }, + "post" : { + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "ok" + } + }, + "security" : [ { + "default" : [ "OrderScope", "MenuScope" ] + } ], + "x-auth-type" : "Application & Application User", + "x-throttling-tier" : "Unlimited", + "x-wso2-application-security" : { + "security-types" : [ "api_key", "basic_auth", "oauth2" ], + "optional" : false + } + } + } + }, + "components" : { + "securitySchemes" : { + "default" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "https://test.com", + "scopes" : { + "OrderScope" : "", + "MenuScope" : "description" + }, + "x-scopes-bindings" : { + "OrderScope" : "admin", + "MenuScope" : "" + } + } + } + } + } + }, + "x-wso2-application-security" : { + "security-types" : [ "api_key", "basic_auth", "oauth2" ], + "optional" : false + }, + "x-wso2-response-cache" : { + "enabled" : false, + "cacheTimeoutInSeconds" : 0 + } +} \ No newline at end of file From ef3458a3ef6b36152e02e2b1fe0ecb643c97f015 Mon Sep 17 00:00:00 2001 From: dushani Date: Mon, 21 Aug 2023 17:08:02 +0530 Subject: [PATCH 4/6] fix test cases. --- .../apimgt/impl/definitions/OAS2ParserTest.java | 13 ------------- .../publisher/oas2_with_default_oauth_response.json | 4 ++-- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS2ParserTest.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS2ParserTest.java index bacc51754452..690468a84ebb 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS2ParserTest.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS2ParserTest.java @@ -229,19 +229,6 @@ public void testGetOASSecurityDefinitionForPublisher() throws Exception { + File.separator + "publisher" + File.separator + "oas2_with_default_oauth_response.json"), StandardCharsets.UTF_8); Assert.assertEquals(oasDefinitionEdited, response); - - // Testing API with swagger generated after APIM 2.x version, but with basic_auth and api_key security in the - // scheme which went with as an u2 update for 4.1, then later reverted. - swagger = IOUtils.toString( - getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator - + "publisher" + File.separator + "oas2_with_apikey_basic_oauth_security_u2.json"), - StandardCharsets.UTF_8); - response = parser.getOASDefinitionForPublisher(api, swagger); - oasDefinitionEdited = IOUtils.toString( - getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator - + "publisher" + File.separator + "oas2_with_apikey_basic_oauth_security_u2_response.json"), - StandardCharsets.UTF_8); - Assert.assertEquals(oasDefinitionEdited, response); } @Test diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth_response.json index f5f6a43f23b7..24bba54b2c4c 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth_response.json +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth_response.json @@ -265,9 +265,9 @@ ], "x-wso2-application-security": { "security-types": [ - "oauth2", + "api_key", "basic_auth", - "api_key" + "oauth2" ], "optional": false }, From 76688527361506e1a08299c60958bb50f9edc8f9 Mon Sep 17 00:00:00 2001 From: dushani Date: Mon, 21 Aug 2023 21:15:56 +0530 Subject: [PATCH 5/6] fix charsets. --- .../impl/definitions/OAS2ParserTest.java | 38 +++++++------- .../impl/definitions/OAS3ParserTest.java | 51 ++++++++++--------- 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS2ParserTest.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS2ParserTest.java index 690468a84ebb..a8de68ee0687 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS2ParserTest.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS2ParserTest.java @@ -157,7 +157,8 @@ public void testRemoveResponsesObjectFromOpenAPI20Spec() throws Exception { public void testSwaggerValidatorWithValidationLevel2() throws Exception { String faultySwagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" - + File.separator + "oas_util_test_faulty_swagger.json"), StandardCharsets.UTF_8); + + File.separator + "oas_util_test_faulty_swagger.json"), + String.valueOf(StandardCharsets.UTF_8)); APIDefinitionValidationResponse response = OASParserUtil.validateAPIDefinition(faultySwagger, true); Assert.assertFalse(response.isValid()); Assert.assertEquals(3, response.getErrorItems().size()); @@ -192,7 +193,7 @@ public void testGetOASSecurityDefinitionForPublisher() throws Exception { String swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "publisher" + File.separator + "oas2_mig_without_sec_extensions.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); API api = Mockito.mock(API.class); String apiSecurity = "oauth_basic_auth_api_key_mandatory,oauth2"; when(api.getApiSecurity()).thenReturn(apiSecurity); @@ -201,18 +202,19 @@ public void testGetOASSecurityDefinitionForPublisher() throws Exception { String oasDefinitionEdited = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "publisher" + File.separator + "oas2_mig_without_sec_extensions_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionEdited, response); // Testing API with migrated swagger coming from APIM version 2.x with x-wso2-security and x-scopes. swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator - + "publisher" + File.separator + "oas2_mig_with_sec_extensions.json"), StandardCharsets.UTF_8); + + "publisher" + File.separator + "oas2_mig_with_sec_extensions.json"), + String.valueOf(StandardCharsets.UTF_8)); response = parser.getOASDefinitionForPublisher(api, swagger); oasDefinitionEdited = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "publisher" + File.separator + "oas2_mig_with_sec_extensions_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionEdited, response); // Testing API with swagger generated after APIM 2.x versions with oauth security definitions and x-wso2 @@ -222,12 +224,12 @@ public void testGetOASSecurityDefinitionForPublisher() throws Exception { swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "publisher" + File.separator + "oas2_with_default_oauth.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); response = parser.getOASDefinitionForPublisher(api, swagger); oasDefinitionEdited = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "publisher" + File.separator + "oas2_with_default_oauth_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionEdited, response); } @@ -238,7 +240,7 @@ public void testGetOASSecurityDefinitionForStore() throws Exception { String swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "publisher" + File.separator + "oas2_mig_without_sec_extensions.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); APIIdentifier apiIdentifier = new APIIdentifier("admin", "OldAPI", "1.0.0"); Map hostWithSchemes = new HashMap<>(); hostWithSchemes.put(APIConstants.HTTPS_PROTOCOL, "https://localhost"); @@ -251,7 +253,7 @@ public void testGetOASSecurityDefinitionForStore() throws Exception { String oasDefinitionExpected = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "devportal" + File.separator - + "oas2_mig_without_sec_extensions_response.json"), StandardCharsets.UTF_8); + + "oas2_mig_without_sec_extensions_response.json"), String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionExpected, response); // Testing API with migrated swagger coming from APIM version 2.x with x-wso2-security and x-scopes. @@ -264,7 +266,7 @@ public void testGetOASSecurityDefinitionForStore() throws Exception { oasDefinitionExpected = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "devportal" + File.separator + "oas2_mig_with_sec_extensions_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionExpected, response); // Testing API with swagger generated after APIM 2.x versions with oauth security definitions and x-wso2 @@ -272,7 +274,7 @@ public void testGetOASSecurityDefinitionForStore() throws Exception { swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "devportal" + File.separator + "oas2_with_default_allsecurity.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); apiIdentifier = new APIIdentifier("admin", "SwaggerPetstore", "1.0.6"); api = new API(apiIdentifier); api.setTransports("https"); @@ -283,32 +285,32 @@ public void testGetOASSecurityDefinitionForStore() throws Exception { oasDefinitionExpected = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "devportal" + File.separator - + "oas2_with_default_allsecurity_response.json"), StandardCharsets.UTF_8); + + "oas2_with_default_allsecurity_response.json"), String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionExpected, response); // Testing API with swagger generated after APIM 2.x version, but with basic_auth and api_key security in // the scheme which went with as an u2 update for 4.1, then later reverted. API configured with all security. swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "devportal" + File.separator + "oas2_with_apikey_basic_oauth_security_u2.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); response = oas2Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); oasDefinitionExpected = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "devportal" + File.separator + "oas2_with_apikey_basic_oauth_security_u2_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionExpected, response); // Testing API with swagger generated after APIM 2.x versions with oauth security definitions and x-wso2 // extensions. API configured with basic auth and api key. swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "devportal" + File.separator + "oas2_with_basic_apisec.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); api.setApiSecurity("oauth_basic_auth_api_key_mandatory,api_key,basic_auth"); response = oas2Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); oasDefinitionExpected = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "devportal" + File.separator + "oas2_with_basic_apisec_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionExpected, response); // API configured with basic auth only. swagger = IOUtils.toString( @@ -320,7 +322,7 @@ public void testGetOASSecurityDefinitionForStore() throws Exception { oasDefinitionExpected = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "devportal" + File.separator + "oas2_with_basic_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionExpected, response); // API Configured with api key only. swagger = IOUtils.toString( @@ -332,7 +334,7 @@ public void testGetOASSecurityDefinitionForStore() throws Exception { oasDefinitionExpected = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas2" + File.separator + "devportal" + File.separator + "oas2_with_apikey_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionExpected, response); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS3ParserTest.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS3ParserTest.java index 7b035f700b3a..6121d9458bd3 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS3ParserTest.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS3ParserTest.java @@ -216,7 +216,7 @@ public void testOpenAPIValidatorWithValidationLevel1() throws Exception { String faultySwagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "openApi3_validation.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); APIDefinitionValidationResponse response = OASParserUtil.validateAPIDefinition(faultySwagger, true); Assert.assertFalse(response.isValid()); @@ -278,7 +278,7 @@ public void testGetOASSecurityDefinitionForPublisher() throws Exception { String swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "publisher" + File.separator + "oas3_mig_without_sec_extensions.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); API api = Mockito.mock(API.class); String apiSecurity = "oauth_basic_auth_api_key_mandatory,oauth2"; when(api.getApiSecurity()).thenReturn(apiSecurity); @@ -287,19 +287,19 @@ public void testGetOASSecurityDefinitionForPublisher() throws Exception { String oasDefinitionEdited = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "publisher" + File.separator + "oas3_mig_without_sec_extensions_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionEdited, response); // Testing API with migrated swagger coming from APIM version 2.x with x-wso2-security and x-scopes. swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "publisher" + File.separator + "oas3_mig_with_sec_extensions.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); response = parser.getOASDefinitionForPublisher(api, swagger); oasDefinitionEdited = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "publisher" + File.separator + "oas3_mig_with_sec_extensions_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionEdited, response); // Testing API with swagger generated after APIM 2.x versions with oauth security definitions and x-wso2 @@ -308,12 +308,13 @@ public void testGetOASSecurityDefinitionForPublisher() throws Exception { when(api.getApiSecurity()).thenReturn(apiSecurity); swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator - + "publisher" + File.separator + "oas3_with_default_oauth.json"), StandardCharsets.UTF_8); + + "publisher" + File.separator + "oas3_with_default_oauth.json"), + String.valueOf(StandardCharsets.UTF_8)); response = parser.getOASDefinitionForPublisher(api, swagger); oasDefinitionEdited = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "publisher" + File.separator + "oas3_with_default_oauth_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionEdited, response); // Testing API with swagger generated after APIM 2.x version, but with basic_auth and api_key security in the @@ -321,12 +322,12 @@ public void testGetOASSecurityDefinitionForPublisher() throws Exception { swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "publisher" + File.separator + "oas3_with_apikey_basic_oauth_security_u2.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); response = parser.getOASDefinitionForPublisher(api, swagger); oasDefinitionEdited = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "publisher" + File.separator + "oas3_with_apikey_basic_oauth_security_u2_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionEdited, response); } @@ -338,7 +339,7 @@ public void testGetOASSecurityDefinitionForStore() throws Exception { String swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "publisher" + File.separator + "oas3_mig_without_sec_extensions.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); APIIdentifier apiIdentifier = new APIIdentifier("admin", "PizzaShackAPI", "1.0.0"); Map hostWithSchemes = new HashMap<>(); hostWithSchemes.put(APIConstants.HTTPS_PROTOCOL, "https://localhost"); @@ -351,80 +352,84 @@ public void testGetOASSecurityDefinitionForStore() throws Exception { String oasDefinitionExpected = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "devportal" + File.separator + "oas3_mig_without_sec_extensions_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionExpected, response); // Testing API with migrated swagger coming from APIM version 2.x with x-wso2-security and x-scopes. swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator - + "publisher" + File.separator + "oas3_mig_with_sec_extensions.json"), StandardCharsets.UTF_8); + + "publisher" + File.separator + "oas3_mig_with_sec_extensions.json"), + String.valueOf(StandardCharsets.UTF_8)); api.setScopes(getAPITestScopes()); response = oas3Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); oasDefinitionExpected = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "devportal" + File.separator + "oas3_mig_with_sec_extensions_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionExpected, response); // Testing API with swagger generated after APIM 2.x versions with oauth security definitions and x-wso2 // extensions. API configured with all security. swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator - + "devportal" + File.separator + "oas3_with_default_allsecurity.json"), StandardCharsets.UTF_8); + + "devportal" + File.separator + "oas3_with_default_allsecurity.json"), + String.valueOf(StandardCharsets.UTF_8)); api.setScopes(getAPITestScopes()); api.setApiSecurity("oauth_basic_auth_api_key_mandatory,api_key,basic_auth,oauth2"); response = oas3Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); oasDefinitionExpected = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "devportal" + File.separator + "oas3_with_default_allsecurity_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionExpected, response); // Testing API with swagger generated after APIM 2.x version, but with basic_auth and api_key security in // the scheme which went with as an u2 update for 4.1, then later reverted. API configured with all security. swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "publisher" + File.separator + "oas3_with_apikey_basic_oauth_security_u2.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); response = oas3Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); oasDefinitionExpected = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "devportal" + File.separator + "oas3_with_apikey_basic_oauth_security_u2_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionExpected, response); // Testing API with swagger generated after APIM 2.x versions with oauth security definitions and x-wso2 // extensions. API configured with basic auth and api key. swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "devportal" + File.separator + "oas3_with_basic_apisec.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); api.setApiSecurity("oauth_basic_auth_api_key_mandatory,api_key,basic_auth"); response = oas3Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); oasDefinitionExpected = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "devportal" + File.separator + "oas3_with_basic_apisec_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionExpected, response); // API configured with basic auth only. swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator - + "devportal" + File.separator + "oas3_with_basic.json"), StandardCharsets.UTF_8); + + "devportal" + File.separator + "oas3_with_basic.json"), + String.valueOf(StandardCharsets.UTF_8)); api.setApiSecurity("oauth_basic_auth_api_key_mandatory,basic_auth"); response = oas3Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); oasDefinitionExpected = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator - + "devportal" + File.separator + "oas3_with_basic_response.json"), StandardCharsets.UTF_8); + + "devportal" + File.separator + "oas3_with_basic_response.json"), + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionExpected, response); // API Configured with api key only. swagger = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "devportal" + File.separator + "oas3_with_apikey.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); api.setApiSecurity("oauth_basic_auth_api_key_mandatory,api_key"); response = oas3Parser.getOASDefinitionForStore(api, swagger, hostWithSchemes); oasDefinitionExpected = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator + "devportal" + File.separator + "oas3_with_apikey_response.json"), - StandardCharsets.UTF_8); + String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionExpected, response); } From d3c1ee4d297519e8665fae708c7549721da51f26 Mon Sep 17 00:00:00 2001 From: dushani Date: Mon, 21 Aug 2023 22:55:39 +0530 Subject: [PATCH 6/6] fix tests. --- .../apimgt/impl/definitions/OAS3ParserTest.java | 13 ------------- .../oas2/publisher/oas2_with_default_oauth.json | 8 -------- .../publisher/oas2_with_default_oauth_response.json | 8 ++++---- 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS3ParserTest.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS3ParserTest.java index 6121d9458bd3..5e09bef7a0ca 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS3ParserTest.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/definitions/OAS3ParserTest.java @@ -316,19 +316,6 @@ public void testGetOASSecurityDefinitionForPublisher() throws Exception { + "publisher" + File.separator + "oas3_with_default_oauth_response.json"), String.valueOf(StandardCharsets.UTF_8)); Assert.assertEquals(oasDefinitionEdited, response); - - // Testing API with swagger generated after APIM 2.x version, but with basic_auth and api_key security in the - // scheme which went with as an u2 update for 4.1, then later reverted. - swagger = IOUtils.toString( - getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator - + "publisher" + File.separator + "oas3_with_apikey_basic_oauth_security_u2.json"), - String.valueOf(StandardCharsets.UTF_8)); - response = parser.getOASDefinitionForPublisher(api, swagger); - oasDefinitionEdited = IOUtils.toString( - getClass().getClassLoader().getResourceAsStream("definitions" + File.separator + "oas3" + File.separator - + "publisher" + File.separator + "oas3_with_apikey_basic_oauth_security_u2_response.json"), - String.valueOf(StandardCharsets.UTF_8)); - Assert.assertEquals(oasDefinitionEdited, response); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth.json index 4dbf41e5b87e..7af1d141139c 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth.json +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth.json @@ -287,14 +287,6 @@ "http", "https" ], - "x-wso2-application-security": { - "security-types": [ - "oauth2", - "basic_auth", - "api_key" - ], - "optional": false - }, "x-wso2-response-cache": { "enabled": false, "cacheTimeoutInSeconds": 300 diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth_response.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth_response.json index 24bba54b2c4c..71efb4d88960 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth_response.json +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/definitions/oas2/publisher/oas2_with_default_oauth_response.json @@ -263,6 +263,10 @@ "http", "https" ], + "x-wso2-response-cache": { + "enabled": false, + "cacheTimeoutInSeconds": 0 + }, "x-wso2-application-security": { "security-types": [ "api_key", @@ -270,9 +274,5 @@ "oauth2" ], "optional": false - }, - "x-wso2-response-cache": { - "enabled": false, - "cacheTimeoutInSeconds": 0 } } \ No newline at end of file