Search in sources :

Example 16 with SwaggerApiEntity

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

the class SwaggerService_CreateAPITest method shouldPrepareAPIFromSwaggerV3WithNoServer.

@Test
public void shouldPrepareAPIFromSwaggerV3WithNoServer() throws IOException {
    final SwaggerApiEntity api = prepareInline("io/gravitee/rest/api/management/service/mock/openapi-noserver.yaml", true);
    assertEquals("noserver", api.getProxy().getVirtualHosts().get(0).getPath());
    final List<String> endpoints = api.getProxy().getGroups().iterator().next().getEndpoints().stream().map(Endpoint::getTarget).collect(Collectors.toList());
    assertEquals(1, endpoints.size());
    assertTrue(endpoints.contains("/"));
}
Also used : SwaggerApiEntity(io.gravitee.rest.api.model.api.SwaggerApiEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 17 with SwaggerApiEntity

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

the class SwaggerService_CreateAPITest method shouldPrepareAPIFromSwaggerV3WithExample.

@Test
public void shouldPrepareAPIFromSwaggerV3WithExample() throws IOException {
    final SwaggerApiEntity api = prepareInline("io/gravitee/rest/api/management/service/mock/uspto.yaml", true, true);
    assertEquals("1.0.0", api.getVersion());
    assertEquals("USPTO Data Set API", api.getName());
    assertEquals("/ds-api", api.getProxy().getVirtualHosts().get(0).getPath());
    final List<String> endpoints = api.getProxy().getGroups().iterator().next().getEndpoints().stream().map(Endpoint::getTarget).collect(Collectors.toList());
    assertEquals(2, 4, endpoints.size());
    assertTrue(endpoints.contains("http://developer.uspto.gov/ds-api"));
    assertTrue(endpoints.contains("https://developer.uspto.gov/ds-api"));
    validatePolicies(api, 3, 3, asList("/", "/:dataset/:version/fields", "/:dataset/:version/records"));
}
Also used : SwaggerApiEntity(io.gravitee.rest.api.model.api.SwaggerApiEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 18 with SwaggerApiEntity

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

the class SwaggerService_CreateAPITest method shouldPrepareAPIFromSwaggerV3WithLinks.

@Test
public void shouldPrepareAPIFromSwaggerV3WithLinks() throws IOException {
    final SwaggerApiEntity api = prepareInline("io/gravitee/rest/api/management/service/mock/link-example.yaml", true, true);
    assertEquals("1.0.0", api.getVersion());
    assertEquals("Link Example", api.getName());
    assertEquals("linkexample", api.getProxy().getVirtualHosts().get(0).getPath());
    assertEquals("/", api.getProxy().getGroups().iterator().next().getEndpoints().iterator().next().getTarget());
    validatePolicies(api, 6, 6, asList("/2.0/users/:username", "/2.0/repositories/:username/:slug", "/2.0/repositories/:username/:slug/pullrequests", "/2.0/repositories/:username/:slug/pullrequests/:pid", "/2.0/repositories/:username/:slug/pullrequests/:pid/merge"));
}
Also used : SwaggerApiEntity(io.gravitee.rest.api.model.api.SwaggerApiEntity) Test(org.junit.Test)

Example 19 with SwaggerApiEntity

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

the class SwaggerService_CreateAPITest method shouldPrepareAPIFromSwaggerV3WithVariablesInServer.

@Test
public void shouldPrepareAPIFromSwaggerV3WithVariablesInServer() throws IOException {
    final SwaggerApiEntity api = prepareInline("io/gravitee/rest/api/management/service/mock/openapi-variables-in-server.yaml", true);
    assertEquals("/v2", api.getProxy().getVirtualHosts().get(0).getPath());
    final List<String> endpoints = api.getProxy().getGroups().iterator().next().getEndpoints().stream().map(Endpoint::getTarget).collect(Collectors.toList());
    assertEquals(2, endpoints.size());
    assertTrue(endpoints.contains("https://demo.gigantic-server.com:443/v2"));
    assertTrue(endpoints.contains("https://demo.gigantic-server.com:8443/v2"));
}
Also used : SwaggerApiEntity(io.gravitee.rest.api.model.api.SwaggerApiEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

SwaggerApiEntity (io.gravitee.rest.api.model.api.SwaggerApiEntity)19 Test (org.junit.Test)17 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 HttpMethod (io.gravitee.common.http.HttpMethod)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 io.gravitee.definition.model (io.gravitee.definition.model)2 Flow (io.gravitee.definition.model.flow.Flow)2 Step (io.gravitee.definition.model.flow.Step)2 Policy (io.gravitee.policy.api.swagger.Policy)2 io.gravitee.rest.api.model (io.gravitee.rest.api.model)2 GroupService (io.gravitee.rest.api.service.GroupService)2 TagService (io.gravitee.rest.api.service.TagService)2 PolicyOperationVisitorManager (io.gravitee.rest.api.service.impl.swagger.policy.PolicyOperationVisitorManager)2 OAIOperationVisitor (io.gravitee.rest.api.service.impl.swagger.visitor.v3.OAIOperationVisitor)2 PolicyHelper.clearNullValues (io.gravitee.rest.api.service.validator.PolicyHelper.clearNullValues)2 OpenAPI (io.swagger.v3.oas.models.OpenAPI)2 Operation (io.swagger.v3.oas.models.Operation)2 PathItem (io.swagger.v3.oas.models.PathItem)2 Collections.singleton (java.util.Collections.singleton)2