Search in sources :

Example 6 with PageEntity

use of io.gravitee.rest.api.model.PageEntity 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 7 with PageEntity

use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.

the class SwaggerService_TransformTest method shouldTransformAPIFromSwaggerV3_yaml.

@Test
public void shouldTransformAPIFromSwaggerV3_yaml() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi.yaml", MediaType.TEXT_PLAIN);
    OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent(), false);
    swaggerService.transform(descriptor, Collections.singleton(new PageConfigurationOAITransformer(pageEntity)));
    assertNotNull(descriptor.toYaml());
    validateV3(Yaml.mapper().readTree(descriptor.toYaml()));
}
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 8 with PageEntity

use of io.gravitee.rest.api.model.PageEntity 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 9 with PageEntity

use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.

the class SwaggerService_TransformTest method getPage.

private PageEntity getPage(String resource, String contentType) throws IOException {
    URL url = Resources.getResource(resource);
    String descriptor = Resources.toString(url, Charsets.UTF_8);
    PageEntity pageEntity = new PageEntity();
    pageEntity.setContent(descriptor);
    pageEntity.setContentType(contentType);
    Map<String, String> pageConfigurationEntity = new HashMap<>();
    pageConfigurationEntity.put(PageConfigurationKeys.SWAGGER_SWAGGERUI_TRY_IT, "true");
    pageConfigurationEntity.put(PageConfigurationKeys.SWAGGER_SWAGGERUI_TRY_IT_URL, "https://my.domain.com/v1");
    pageEntity.setConfiguration(pageConfigurationEntity);
    return pageEntity;
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) URL(java.net.URL)

Example 10 with PageEntity

use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.

the class SwaggerService_ParseTest method shouldReturnErrorMessageWhenParseSwaggerV2WithoutInfo_json.

@Test
public void shouldReturnErrorMessageWhenParseSwaggerV2WithoutInfo_json() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/swagger-v2-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

PageEntity (io.gravitee.rest.api.model.PageEntity)67 Test (org.junit.Test)48 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)15 OAIDescriptor (io.gravitee.rest.api.service.swagger.OAIDescriptor)15 Page (io.gravitee.rest.api.portal.rest.model.Page)13 Response (javax.ws.rs.core.Response)13 UpdatePageEntity (io.gravitee.rest.api.model.UpdatePageEntity)9 PageConfigurationOAITransformer (io.gravitee.rest.api.service.impl.swagger.transformer.page.PageConfigurationOAITransformer)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)6 EntrypointsOAITransformer (io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer)6 SwaggerDescriptor (io.gravitee.rest.api.service.swagger.SwaggerDescriptor)5 Before (org.junit.Before)5 Page (io.gravitee.repository.management.model.Page)4 NewPageEntity (io.gravitee.rest.api.model.NewPageEntity)4 PageNotFoundException (io.gravitee.rest.api.service.exceptions.PageNotFoundException)4 ArgumentMatchers (org.mockito.ArgumentMatchers)4 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)3 PageRepository (io.gravitee.repository.management.api.PageRepository)3 PageReferenceType (io.gravitee.repository.management.model.PageReferenceType)3