Search in sources :

Example 11 with OAIDescriptor

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

the class SwaggerService_TransformTest method shouldTransformAPIFromSwaggerV3_json.

@Test
public void shouldTransformAPIFromSwaggerV3_json() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi.json", MediaType.APPLICATION_JSON);
    OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent(), false);
    swaggerService.transform(descriptor, Collections.singleton(new PageConfigurationOAITransformer(pageEntity)));
    assertNotNull(descriptor.toJson());
    validateV3(Json.mapper().readTree(descriptor.toJson()));
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) OAIDescriptor(io.gravitee.rest.api.service.swagger.OAIDescriptor) PageConfigurationOAITransformer(io.gravitee.rest.api.service.impl.swagger.transformer.page.PageConfigurationOAITransformer) Test(org.junit.Test)

Example 12 with OAIDescriptor

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

the class SwaggerService_TransformTest method shouldTransformAPIWithOriginalServerAndContextPath.

@Test
public void shouldTransformAPIWithOriginalServerAndContextPath() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi.json", MediaType.APPLICATION_JSON);
    Map<String, String> pageConfigurationEntity = new HashMap<>();
    pageConfigurationEntity.put(SwaggerProperties.ENTRYPOINTS_AS_SERVERS, "false");
    pageConfigurationEntity.put(SwaggerProperties.ENTRYPOINT_AS_BASEPATH, "true");
    pageEntity.setConfiguration(pageConfigurationEntity);
    OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent(), false);
    final ApiEntity apiEntity = getApiEntity();
    swaggerService.transform(descriptor, Arrays.asList(new PageConfigurationOAITransformer(pageEntity), new EntrypointsOAITransformer(pageEntity, apiEntity)));
    assertNotNull(descriptor.toJson());
    final JsonNode node = Json.mapper().readTree(descriptor.toJson());
    assertEquals("https://demo.gravitee.io/test", node.get("servers").get(0).get("url").asText());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) OAIDescriptor(io.gravitee.rest.api.service.swagger.OAIDescriptor) EntrypointsOAITransformer(io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer) PageConfigurationOAITransformer(io.gravitee.rest.api.service.impl.swagger.transformer.page.PageConfigurationOAITransformer) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 13 with OAIDescriptor

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

the class SwaggerService_TransformTest method shouldTransformAPIWithCustomServerUrl.

@Test
public void shouldTransformAPIWithCustomServerUrl() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi.json", MediaType.APPLICATION_JSON);
    Map<String, String> pageConfigurationEntity = new HashMap<>();
    pageConfigurationEntity.put(SwaggerProperties.ENTRYPOINT_AS_BASEPATH, "false");
    pageConfigurationEntity.put(SwaggerProperties.TRY_IT, "https://custom.gravitee.io/tryit?q=test");
    pageEntity.setConfiguration(pageConfigurationEntity);
    OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent(), false);
    final ApiEntity apiEntity = getApiEntity();
    swaggerService.transform(descriptor, Arrays.asList(new PageConfigurationOAITransformer(pageEntity), new EntrypointsOAITransformer(pageEntity, apiEntity)));
    assertNotNull(descriptor.toJson());
    final JsonNode node = Json.mapper().readTree(descriptor.toJson());
    assertEquals("https://custom.gravitee.io/tryit?q=test", node.get("servers").get(0).get("url").asText());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) OAIDescriptor(io.gravitee.rest.api.service.swagger.OAIDescriptor) EntrypointsOAITransformer(io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer) PageConfigurationOAITransformer(io.gravitee.rest.api.service.impl.swagger.transformer.page.PageConfigurationOAITransformer) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 14 with OAIDescriptor

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

the class SwaggerService_TransformTest method shouldTransformAPIWithCustomServerUrlAndContextPath.

@Test
public void shouldTransformAPIWithCustomServerUrlAndContextPath() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi.json", MediaType.APPLICATION_JSON);
    Map<String, String> pageConfigurationEntity = new HashMap<>();
    pageConfigurationEntity.put(SwaggerProperties.ENTRYPOINT_AS_BASEPATH, "true");
    pageConfigurationEntity.put(SwaggerProperties.TRY_IT, "https://custom.gravitee.io/tryit?q=test");
    pageEntity.setConfiguration(pageConfigurationEntity);
    OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent(), false);
    final ApiEntity apiEntity = getApiEntity();
    swaggerService.transform(descriptor, Arrays.asList(new PageConfigurationOAITransformer(pageEntity), new EntrypointsOAITransformer(pageEntity, apiEntity)));
    assertNotNull(descriptor.toJson());
    final JsonNode node = Json.mapper().readTree(descriptor.toJson());
    assertEquals("https://custom.gravitee.io/test?q=test", node.get("servers").get(0).get("url").asText());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) OAIDescriptor(io.gravitee.rest.api.service.swagger.OAIDescriptor) EntrypointsOAITransformer(io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer) PageConfigurationOAITransformer(io.gravitee.rest.api.service.impl.swagger.transformer.page.PageConfigurationOAITransformer) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 15 with OAIDescriptor

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

the class SwaggerService_ParseTest method shouldReturnErrorMessageWhenParseSwaggerV3WithoutInfo_json.

@Test
public void shouldReturnErrorMessageWhenParseSwaggerV3WithoutInfo_json() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi-no-info.json", MediaType.APPLICATION_JSON);
    OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent());
    assertNotNull(descriptor.getMessages());
    assertEquals("attribute info is missing", descriptor.getMessages().get(0));
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) OAIDescriptor(io.gravitee.rest.api.service.swagger.OAIDescriptor) Test(org.junit.Test)

Aggregations

OAIDescriptor (io.gravitee.rest.api.service.swagger.OAIDescriptor)18 PageEntity (io.gravitee.rest.api.model.PageEntity)16 Test (org.junit.Test)15 PageConfigurationOAITransformer (io.gravitee.rest.api.service.impl.swagger.transformer.page.PageConfigurationOAITransformer)8 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 EntrypointsOAITransformer (io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer)6 SwaggerDescriptorException (io.gravitee.rest.api.service.exceptions.SwaggerDescriptorException)2 List (java.util.List)2 ApiEntrypointEntity (io.gravitee.rest.api.model.api.ApiEntrypointEntity)1 SwaggerProperties (io.gravitee.rest.api.service.impl.swagger.SwaggerProperties)1 OAIParser (io.gravitee.rest.api.service.impl.swagger.parser.OAIParser)1 WsdlParser (io.gravitee.rest.api.service.impl.swagger.parser.WsdlParser)1 AbstractPageConfigurationSwaggerTransformer (io.gravitee.rest.api.service.impl.swagger.transformer.page.AbstractPageConfigurationSwaggerTransformer)1 OpenAPIParser (io.swagger.parser.OpenAPIParser)1 OpenAPI (io.swagger.v3.oas.models.OpenAPI)1 Server (io.swagger.v3.oas.models.servers.Server)1 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)1 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)1 BufferedWriter (java.io.BufferedWriter)1