use of org.wso2.carbon.apimgt.impl.definitions.OAS3Parser 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.impl.definitions.OAS3Parser 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);
}
use of org.wso2.carbon.apimgt.impl.definitions.OAS3Parser in project carbon-apimgt by wso2.
the class OASYamlApi method oasYamlGet.
/**
* Retrieves swagger definition of Service Catalog REST API and returns
*
* @return swagger definition of Service Catalog REST API in yaml format
*/
@GET
@Consumes({ "text/yaml" })
@Produces({ "text/yaml" })
@io.swagger.annotations.ApiOperation(value = "Get OpenAPI Definition", notes = "Get OpenAPI Definition of Service Catalog REST API.", response = Void.class)
@io.swagger.annotations.ApiResponses(value = { @io.swagger.annotations.ApiResponse(code = 200, message = "OK.\nOpenAPI Definition is returned."), @io.swagger.annotations.ApiResponse(code = 304, message = "Not Modified.\nEmpty body because the client has already the latest version of the requested resource."), @io.swagger.annotations.ApiResponse(code = 406, message = "Not Acceptable.\nThe requested media type is not supported") })
public Response oasYamlGet() throws APIManagementException {
try {
if (openAPIDef == null) {
synchronized (LOCK_SERVICE_CATALOG_OPENAPI_DEF) {
if (openAPIDef == null) {
String definition = IOUtils.toString(this.getClass().getResourceAsStream("/service-catalog-api.yaml"), "UTF-8");
openAPIDef = new OAS3Parser().removeExamplesFromOpenAPI(definition);
}
}
}
RESTAPICacheConfiguration restapiCacheConfiguration = APIUtil.getRESTAPICacheConfig();
if (restapiCacheConfiguration.isCacheControlHeadersEnabled()) {
CacheControl cacheControl = new CacheControl();
cacheControl.setMaxAge(restapiCacheConfiguration.getCacheControlHeadersMaxAge());
cacheControl.setPrivate(true);
return Response.ok().entity(openAPIDef).cacheControl(cacheControl).build();
} else {
return Response.ok().entity(openAPIDef).build();
}
} catch (IOException e) {
String errorMessage = "Error while retrieving the OAS of the Service Catalog API";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.impl.definitions.OAS3Parser in project carbon-apimgt by wso2.
the class SwaggerYamlApi method swaggerYamlGet.
/**
* Retrieves swagger definition of Publisher REST API and returns
*
* @return swagger definition of Publisher REST API in yaml format
*/
@GET
@Consumes({ "text/yaml" })
@Produces({ "text/yaml" })
@io.swagger.annotations.ApiOperation(value = "Get Swagger Definition", notes = "Get Swagger Definition of Publisher REST API.", response = Void.class)
@io.swagger.annotations.ApiResponses(value = { @io.swagger.annotations.ApiResponse(code = 200, message = "OK.\nSwagger Definition is returned."), @io.swagger.annotations.ApiResponse(code = 304, message = "Not Modified.\nEmpty body because the client has already the latest version of the requested resource."), @io.swagger.annotations.ApiResponse(code = 406, message = "Not Acceptable.\nThe requested media type is not supported") })
public Response swaggerYamlGet() throws APIManagementException {
try {
if (openAPIDef == null) {
synchronized (LOCK_PUBLISHER_OPENAPI_DEF) {
if (openAPIDef == null) {
String definition = IOUtils.toString(this.getClass().getResourceAsStream("/publisher-api.yaml"), "UTF-8");
openAPIDef = new OAS3Parser().removeExamplesFromOpenAPI(definition);
}
}
}
RESTAPICacheConfiguration restapiCacheConfiguration = APIUtil.getRESTAPICacheConfig();
if (restapiCacheConfiguration.isCacheControlHeadersEnabled()) {
CacheControl cacheControl = new CacheControl();
cacheControl.setMaxAge(restapiCacheConfiguration.getCacheControlHeadersMaxAge());
cacheControl.setPrivate(true);
return Response.ok().entity(openAPIDef).cacheControl(cacheControl).build();
} else {
return Response.ok().entity(openAPIDef).build();
}
} catch (IOException e) {
String errorMessage = "Error while retrieving the OAS of the Publisher API";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.impl.definitions.OAS3Parser in project carbon-apimgt by wso2.
the class SwaggerYamlApi method swaggerYamlGet.
/**
* Retrieves OAS of Developer Portal REST API and returns
*
* @return OAS of Developer Portal REST API in yaml format
*/
@GET
@Consumes({ "text/yaml" })
@Produces({ "text/yaml" })
@io.swagger.annotations.ApiOperation(value = "Get OAS Definition", notes = "Get OAS of Developer Portal REST API.", response = Void.class)
@io.swagger.annotations.ApiResponses(value = { @io.swagger.annotations.ApiResponse(code = 200, message = "OK.\nOAS Definition is returned."), @io.swagger.annotations.ApiResponse(code = 304, message = "Not Modified.\nEmpty body because the client has already the latest version of the requested resource."), @io.swagger.annotations.ApiResponse(code = 406, message = "Not Acceptable.\nThe requested media type is not supported") })
public Response swaggerYamlGet() throws APIManagementException {
try {
if (openAPIDef == null) {
synchronized (LOCK_STORE_OPENAPI_DEF) {
if (openAPIDef == null) {
String definition = IOUtils.toString(this.getClass().getResourceAsStream("/devportal-api.yaml"), "UTF-8");
openAPIDef = new OAS3Parser().removeExamplesFromOpenAPI(definition);
}
}
}
RESTAPICacheConfiguration restapiCacheConfiguration = APIUtil.getRESTAPICacheConfig();
if (restapiCacheConfiguration.isCacheControlHeadersEnabled()) {
CacheControl cacheControl = new CacheControl();
cacheControl.setMaxAge(restapiCacheConfiguration.getCacheControlHeadersMaxAge());
cacheControl.setPrivate(true);
return Response.ok().entity(openAPIDef).cacheControl(cacheControl).build();
} else {
return Response.ok().entity(openAPIDef).build();
}
} catch (IOException e) {
String errorMessage = "Error while retrieving the OAS of the Developer Portal API";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
Aggregations