use of org.wso2.carbon.apimgt.api.model.SwaggerData in project carbon-apimgt by wso2.
the class OAS3Parser method getOASDefinitionForStore.
/**
* Update OAS definition for store
*
* @param product APIProduct
* @param oasDefinition OAS definition
* @param hostsWithSchemes host addresses with protocol mapping
* @return OAS definition
*/
@Override
public String getOASDefinitionForStore(APIProduct product, String oasDefinition, Map<String, String> hostsWithSchemes) {
OpenAPI openAPI = getOpenAPI(oasDefinition);
updateOperations(openAPI);
updateEndpoints(product, hostsWithSchemes, openAPI);
return updateSwaggerSecurityDefinitionForStore(openAPI, new SwaggerData(product), hostsWithSchemes);
}
use of org.wso2.carbon.apimgt.api.model.SwaggerData in project carbon-apimgt by wso2.
the class OAS2Parser method getOASDefinitionForStore.
/**
* Update OAS definition for store
*
* @param api API
* @param oasDefinition OAS definition
* @param hostsWithSchemes host addresses with protocol mapping
* @return OAS definition
* @throws APIManagementException throws if an error occurred
*/
@Override
public String getOASDefinitionForStore(API api, String oasDefinition, Map<String, String> hostsWithSchemes) throws APIManagementException {
Swagger swagger = getSwagger(oasDefinition);
updateOperations(swagger);
updateEndpoints(api, hostsWithSchemes, swagger);
return updateSwaggerSecurityDefinitionForStore(swagger, new SwaggerData(api), hostsWithSchemes);
}
use of org.wso2.carbon.apimgt.api.model.SwaggerData in project carbon-apimgt by wso2.
the class OAS3Parser method updateSwaggerSecurityDefinition.
/**
* Include Scope details to the definition
*
* @param openAPI openapi definition
* @param swaggerData Swagger related API data
*/
private void updateSwaggerSecurityDefinition(OpenAPI openAPI, SwaggerData swaggerData, String authUrl) {
if (openAPI.getComponents() == null) {
openAPI.setComponents(new Components());
}
Map<String, SecurityScheme> securitySchemes = openAPI.getComponents().getSecuritySchemes();
if (securitySchemes == null) {
securitySchemes = new HashMap<>();
openAPI.getComponents().setSecuritySchemes(securitySchemes);
}
SecurityScheme securityScheme = securitySchemes.get(OPENAPI_SECURITY_SCHEMA_KEY);
if (securityScheme == null) {
securityScheme = new SecurityScheme();
securityScheme.setType(SecurityScheme.Type.OAUTH2);
securitySchemes.put(OPENAPI_SECURITY_SCHEMA_KEY, securityScheme);
List<SecurityRequirement> security = new ArrayList<SecurityRequirement>();
SecurityRequirement secReq = new SecurityRequirement();
secReq.addList(OPENAPI_SECURITY_SCHEMA_KEY, new ArrayList<String>());
security.add(secReq);
openAPI.setSecurity(security);
}
if (securityScheme.getFlows() == null) {
securityScheme.setFlows(new OAuthFlows());
}
OAuthFlow oAuthFlow = securityScheme.getFlows().getImplicit();
if (oAuthFlow == null) {
oAuthFlow = new OAuthFlow();
securityScheme.getFlows().setImplicit(oAuthFlow);
}
oAuthFlow.setAuthorizationUrl(authUrl);
Scopes oas3Scopes = new Scopes();
Set<Scope> scopes = swaggerData.getScopes();
if (scopes != null && !scopes.isEmpty()) {
Map<String, String> scopeBindings = new HashMap<>();
for (Scope scope : scopes) {
String description = scope.getDescription() != null ? scope.getDescription() : "";
oas3Scopes.put(scope.getKey(), description);
String roles = (StringUtils.isNotBlank(scope.getRoles()) && scope.getRoles().trim().split(",").length > 0) ? scope.getRoles() : StringUtils.EMPTY;
scopeBindings.put(scope.getKey(), roles);
}
oAuthFlow.addExtension(APIConstants.SWAGGER_X_SCOPES_BINDINGS, scopeBindings);
}
oAuthFlow.setScopes(oas3Scopes);
}
use of org.wso2.carbon.apimgt.api.model.SwaggerData in project carbon-apimgt by wso2.
the class APIProviderImpl method addAPIProductSwagger.
@Override
public void addAPIProductSwagger(String productId, Map<API, List<APIProductResource>> apiToProductResourceMapping, APIProduct apiProduct, String orgId) throws APIManagementException {
APIDefinition parser = new OAS3Parser();
SwaggerData swaggerData = new SwaggerData(apiProduct);
String apiProductSwagger = parser.generateAPIDefinition(swaggerData);
apiProductSwagger = OASParserUtil.updateAPIProductSwaggerOperations(apiToProductResourceMapping, apiProductSwagger);
saveSwaggerDefinition(productId, apiProductSwagger, orgId);
apiProduct.setDefinition(apiProductSwagger);
}
use of org.wso2.carbon.apimgt.api.model.SwaggerData in project carbon-apimgt by wso2.
the class APIProviderImpl method updateAPIProductSwagger.
@Override
public void updateAPIProductSwagger(String productId, Map<API, List<APIProductResource>> apiToProductResourceMapping, APIProduct apiProduct, String orgId) throws APIManagementException {
APIDefinition parser = new OAS3Parser();
SwaggerData updatedData = new SwaggerData(apiProduct);
String existingProductSwagger = getAPIDefinitionOfAPIProduct(apiProduct);
String updatedProductSwagger = parser.generateAPIDefinition(updatedData, existingProductSwagger);
updatedProductSwagger = OASParserUtil.updateAPIProductSwaggerOperations(apiToProductResourceMapping, updatedProductSwagger);
saveSwaggerDefinition(productId, updatedProductSwagger, orgId);
apiProduct.setDefinition(updatedProductSwagger);
}
Aggregations