Search in sources :

Example 1 with SwaggerDescriptor

use of io.gravitee.rest.api.service.swagger.SwaggerDescriptor in project gravitee-management-rest-api by gravitee-io.

the class SwaggerServiceImpl method createAPI.

@Override
public SwaggerApiEntity createAPI(ImportSwaggerDescriptorEntity swaggerDescriptor, DefinitionVersion definitionVersion) {
    ParseOptions options = new ParseOptions();
    // In the context of an import, we need to fully resolve $ref which are required for OAIDescriptorVisitors (ie. policies).
    options.setResolveFully(true);
    boolean wsdlImport = Format.WSDL.equals(swaggerDescriptor.getFormat());
    SwaggerDescriptor descriptor = parse(swaggerDescriptor.getPayload(), wsdlImport, options);
    if (wsdlImport) {
        overridePayload(swaggerDescriptor, descriptor);
        populateXmlToJsonPolicy(swaggerDescriptor);
    }
    if (descriptor != null) {
        if (definitionVersion.equals(DefinitionVersion.V2)) {
            return new OAIToAPIV2Converter(swaggerDescriptor, policyOperationVisitorManager, groupService, tagService).convert((OAIDescriptor) descriptor);
        } else {
            return new OAIToAPIConverter(swaggerDescriptor, policyOperationVisitorManager, groupService, tagService).convert((OAIDescriptor) descriptor);
        }
    }
    throw new SwaggerDescriptorException();
}
Also used : OAIToAPIConverter(io.gravitee.rest.api.service.impl.swagger.converter.api.OAIToAPIConverter) OAIToAPIV2Converter(io.gravitee.rest.api.service.impl.swagger.converter.api.OAIToAPIV2Converter) SwaggerDescriptorException(io.gravitee.rest.api.service.exceptions.SwaggerDescriptorException) SwaggerDescriptor(io.gravitee.rest.api.service.swagger.SwaggerDescriptor) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions)

Example 2 with SwaggerDescriptor

use of io.gravitee.rest.api.service.swagger.SwaggerDescriptor in project gravitee-management-rest-api by gravitee-io.

the class SwaggerService_ParseTest method shouldNotThrowAnythingWhenFailIfErrorsFalse.

@Test
public void shouldNotThrowAnythingWhenFailIfErrorsFalse() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/swagger-v2-no-info-name.json", MediaType.APPLICATION_JSON);
    SwaggerDescriptor descriptor = swaggerService.parse(pageEntity.getContent());
    assertNotNull(descriptor);
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) SwaggerDescriptor(io.gravitee.rest.api.service.swagger.SwaggerDescriptor) Test(org.junit.Test)

Example 3 with SwaggerDescriptor

use of io.gravitee.rest.api.service.swagger.SwaggerDescriptor in project gravitee-management-rest-api by gravitee-io.

the class SwaggerService_ParseTest method shouldParseSwaggerV2_json.

@Test
public void shouldParseSwaggerV2_json() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/swagger-v2.json", MediaType.APPLICATION_JSON);
    SwaggerDescriptor descriptor = swaggerService.parse(pageEntity.getContent(), false);
    assertNotNull(descriptor);
    validateV3(Json.mapper().readTree(descriptor.toJson()), false);
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) SwaggerDescriptor(io.gravitee.rest.api.service.swagger.SwaggerDescriptor) Test(org.junit.Test)

Example 4 with SwaggerDescriptor

use of io.gravitee.rest.api.service.swagger.SwaggerDescriptor in project gravitee-management-rest-api by gravitee-io.

the class SwaggerService_ParseTest method shouldParseSwaggerV3_json.

@Test
public void shouldParseSwaggerV3_json() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi.json", MediaType.APPLICATION_JSON);
    SwaggerDescriptor descriptor = swaggerService.parse(pageEntity.getContent(), false);
    assertNotNull(descriptor);
    validateV3(Json.mapper().readTree(descriptor.toJson()));
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) SwaggerDescriptor(io.gravitee.rest.api.service.swagger.SwaggerDescriptor) Test(org.junit.Test)

Example 5 with SwaggerDescriptor

use of io.gravitee.rest.api.service.swagger.SwaggerDescriptor in project gravitee-management-rest-api by gravitee-io.

the class SwaggerService_ParseTest method shouldParseSwaggerV1_json.

@Test
public void shouldParseSwaggerV1_json() throws IOException {
    SwaggerDescriptor descriptor = swaggerService.parse("/io/gravitee/rest/api/management/service/swagger-v1.json", false);
    assertNotNull(descriptor);
    validateV3(Json.mapper().readTree(descriptor.toJson()), false);
}
Also used : SwaggerDescriptor(io.gravitee.rest.api.service.swagger.SwaggerDescriptor) Test(org.junit.Test)

Aggregations

SwaggerDescriptor (io.gravitee.rest.api.service.swagger.SwaggerDescriptor)8 Test (org.junit.Test)7 PageEntity (io.gravitee.rest.api.model.PageEntity)6 SwaggerDescriptorException (io.gravitee.rest.api.service.exceptions.SwaggerDescriptorException)1 OAIToAPIConverter (io.gravitee.rest.api.service.impl.swagger.converter.api.OAIToAPIConverter)1 OAIToAPIV2Converter (io.gravitee.rest.api.service.impl.swagger.converter.api.OAIToAPIV2Converter)1 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)1