Search in sources :

Example 1 with EntrypointsOAITransformer

use of io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer in project gravitee-management-rest-api by gravitee-io.

the class SwaggerService_TransformTest method shouldTransformAPIWithServerUrlAndContextPath.

@Test
public void shouldTransformAPIWithServerUrlAndContextPath() 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, "true");
    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://apis.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 2 with EntrypointsOAITransformer

use of io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer in project gravitee-management-rest-api by gravitee-io.

the class SwaggerService_TransformTest method shouldTransformAPIWithOriginalServer.

@Test
public void shouldTransformAPIWithOriginalServer() 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, "false");
    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/gateway/echo", 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 3 with EntrypointsOAITransformer

use of io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer in project gravitee-management-rest-api by gravitee-io.

the class SwaggerService_TransformTest method shouldTransformAPIWithServerUrl.

@Test
public void shouldTransformAPIWithServerUrl() 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, "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://apis.gravitee.io", 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 4 with EntrypointsOAITransformer

use of io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer 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 5 with EntrypointsOAITransformer

use of io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer 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)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)6 PageEntity (io.gravitee.rest.api.model.PageEntity)6 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)6 EntrypointsOAITransformer (io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer)6 PageConfigurationOAITransformer (io.gravitee.rest.api.service.impl.swagger.transformer.page.PageConfigurationOAITransformer)6 OAIDescriptor (io.gravitee.rest.api.service.swagger.OAIDescriptor)6 Test (org.junit.Test)6