Search in sources :

Example 1 with OAS3Parser

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);
}
Also used : SwaggerData(org.wso2.carbon.apimgt.api.model.SwaggerData) APIDefinition(org.wso2.carbon.apimgt.api.APIDefinition) OAS3Parser(org.wso2.carbon.apimgt.impl.definitions.OAS3Parser)

Example 2 with OAS3Parser

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);
}
Also used : SwaggerData(org.wso2.carbon.apimgt.api.model.SwaggerData) APIDefinition(org.wso2.carbon.apimgt.api.APIDefinition) OAS3Parser(org.wso2.carbon.apimgt.impl.definitions.OAS3Parser)

Example 3 with OAS3Parser

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;
}
Also used : OAS3Parser(org.wso2.carbon.apimgt.impl.definitions.OAS3Parser) RESTAPICacheConfiguration(org.wso2.carbon.apimgt.impl.RESTAPICacheConfiguration) CacheControl(javax.ws.rs.core.CacheControl) IOException(java.io.IOException) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with OAS3Parser

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;
}
Also used : OAS3Parser(org.wso2.carbon.apimgt.impl.definitions.OAS3Parser) RESTAPICacheConfiguration(org.wso2.carbon.apimgt.impl.RESTAPICacheConfiguration) CacheControl(javax.ws.rs.core.CacheControl) IOException(java.io.IOException) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with OAS3Parser

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;
}
Also used : OAS3Parser(org.wso2.carbon.apimgt.impl.definitions.OAS3Parser) RESTAPICacheConfiguration(org.wso2.carbon.apimgt.impl.RESTAPICacheConfiguration) CacheControl(javax.ws.rs.core.CacheControl) IOException(java.io.IOException) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

OAS3Parser (org.wso2.carbon.apimgt.impl.definitions.OAS3Parser)8 APIDefinition (org.wso2.carbon.apimgt.api.APIDefinition)6 IOException (java.io.IOException)5 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)5 SwaggerData (org.wso2.carbon.apimgt.api.model.SwaggerData)5 API (org.wso2.carbon.apimgt.api.model.API)4 ArrayList (java.util.ArrayList)3 Consumes (javax.ws.rs.Consumes)3 GET (javax.ws.rs.GET)3 Produces (javax.ws.rs.Produces)3 CacheControl (javax.ws.rs.core.CacheControl)3 RESTAPICacheConfiguration (org.wso2.carbon.apimgt.impl.RESTAPICacheConfiguration)3 OpenAPI (io.swagger.v3.oas.models.OpenAPI)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)2 APIDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Gson (com.google.gson.Gson)1 Path (io.swagger.models.Path)1