Search in sources :

Example 61 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project flink by apache.

the class OpenApiSpecGenerator method add.

private static void add(MessageHeaders<?, ?, ?> spec, OpenAPI openApi) {
    final PathItem pathItem = openApi.getPaths().computeIfAbsent(// ":parameter" -> "{parameter}"
    spec.getTargetRestEndpointURL().replaceAll(":([\\w]+)", "{$1}"), ignored -> new PathItem());
    final Operation operation = new Operation();
    operation.description(spec.getDescription());
    setParameters(operation, spec);
    setRequest(operation, spec);
    setResponse(operation, spec);
    pathItem.operation(convert(spec.getHttpMethod()), operation);
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Operation(io.swagger.v3.oas.models.Operation)

Example 62 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.

the class SpecFilterTest method filterAwaySecretParameters.

@Test(description = "it should filter away secret parameters")
public void filterAwaySecretParameters() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    final RemoveInternalParamsFilter filter = new RemoveInternalParamsFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
    if (filtered.getPaths() != null) {
        for (Map.Entry<String, PathItem> entry : filtered.getPaths().entrySet()) {
            final Operation get = entry.getValue().getGet();
            if (get != null) {
                for (Parameter param : get.getParameters()) {
                    final String description = param.getDescription();
                    if (StringUtils.isNotBlank(description)) {
                        assertFalse(description.startsWith("secret"));
                    }
                }
            }
        }
    } else {
        fail("paths should not be null");
    }
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Operation(io.swagger.v3.oas.models.Operation) RemoveInternalParamsFilter(io.swagger.v3.core.filter.resources.RemoveInternalParamsFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.testng.annotations.Test)

Example 63 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.

the class OpenAPI3_1DeserializationTest method testDeserializationOnOAS31.

@Test
public void testDeserializationOnOAS31() throws IOException {
    final String jsonString = ResourceUtils.loadClassResource(getClass(), "specFiles/3.1.0/petstore-3.1_sample.yaml");
    OpenAPI openAPI = Yaml31.mapper().readValue(jsonString, OpenAPI.class);
    assertNotNull(openAPI);
    assertEquals(openAPI.getInfo().getTitle(), "Swagger Petstore");
    assertEquals(openAPI.getInfo().getVersion(), "1.0.0");
    assertEquals(openAPI.getInfo().getSummary(), "petstore sample for OAS 3.1.0");
    assertEquals(openAPI.getInfo().getLicense().getName(), "MIT");
    assertEquals(openAPI.getInfo().getLicense().getIdentifier(), "test");
    assertNotNull(openAPI.getWebhooks());
    assertFalse(openAPI.getWebhooks().isEmpty());
    assertNotNull(openAPI.getWebhooks().get("newPet"));
    assertNotNull(openAPI.getWebhooks().get("newPet").getPost());
    assertNotNull(openAPI.getComponents().getPathItems());
    assertNotNull(openAPI.getComponents().getPathItems().get("/pet"));
    assertEquals(openAPI.getComponents().getPathItems().get("/pet").getDescription(), "get a pet");
    assertNotNull(openAPI.getComponents().getPathItems().get("/pet").getGet());
    assertEquals(openAPI.getComponents().getPathItems().get("/pet").getGet().getOperationId(), "getPet");
    assertNotNull(openAPI.getComponents().getSchemas());
    assertNotNull(openAPI.getComponents().getSchemas().get("Pet"));
    assertNotNull(openAPI.getComponents().getSchemas().get("Pet").getDiscriminator());
    assertNotNull(openAPI.getComponents().getSchemas().get("Pet").getDiscriminator().getExtensions());
    assertEquals(openAPI.getComponents().getSchemas().get("Pet").getDiscriminator().getExtensions().get("x-test-extension"), "extended");
    assertNotNull(openAPI.getComponents().getResponses());
    assertNotNull(openAPI.getComponents().getResponses().get("201"));
    assertEquals(openAPI.getComponents().getResponses().get("201").getDescription(), "api response description");
    assertNotNull(openAPI.getComponents().getParameters());
    assertNotNull(openAPI.getComponents().getParameters().get("param"));
    assertEquals(openAPI.getComponents().getParameters().get("param").getIn(), "query");
    assertEquals(openAPI.getComponents().getParameters().get("param").getName(), "param0");
    assertEquals(openAPI.getComponents().getParameters().get("param").getDescription(), "parameter description");
    assertNotNull(openAPI.getComponents().getExamples());
    assertNotNull(openAPI.getComponents().getExamples().get("example"));
    assertEquals(openAPI.getComponents().getExamples().get("example").getDescription(), "example description");
    assertEquals(openAPI.getComponents().getExamples().get("example").getSummary(), "example summary");
    assertEquals(openAPI.getComponents().getExamples().get("example").getValue(), "This is an example");
    assertNotNull(openAPI.getComponents().getRequestBodies());
    assertNotNull(openAPI.getComponents().getRequestBodies().get("body"));
    assertNotNull(openAPI.getComponents().getHeaders());
    assertNotNull(openAPI.getComponents().getHeaders().get("test-head"));
    assertEquals(openAPI.getComponents().getHeaders().get("test-head").getDescription(), "test header description");
    assertNotNull(openAPI.getComponents().getSecuritySchemes());
    assertNotNull(openAPI.getComponents().getSecuritySchemes().get("basic"));
    assertEquals(openAPI.getComponents().getSecuritySchemes().get("basic").getDescription(), "security description");
    assertEquals(openAPI.getComponents().getSecuritySchemes().get("basic").getType().toString(), "http");
    assertNotNull(openAPI.getComponents().getLinks());
    assertNotNull(openAPI.getComponents().getLinks().get("Link"));
    assertEquals(openAPI.getComponents().getLinks().get("Link").getOperationRef(), "#/paths/~12.0~1repositories~1{username}/get");
    assertNotNull(openAPI.getComponents().getCallbacks());
    assertNotNull(openAPI.getComponents().getCallbacks().get("TestCallback"));
    openAPI = Yaml.mapper().readValue(jsonString, OpenAPI.class);
    assertNotNull(openAPI);
    assertNull(openAPI.getInfo().getSummary());
    assertNull(openAPI.getWebhooks());
    assertNull(openAPI.getComponents().getPathItems());
    assertNull(openAPI.getComponents().getSchemas().get("Pet").getDiscriminator().getExtensions());
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 64 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.

the class OpenAPI3_1DeserializationTest method testDeserializationOnOAS30.

@Test
public void testDeserializationOnOAS30() throws IOException {
    final String jsonString = ResourceUtils.loadClassResource(getClass(), "specFiles/3.1.0/petstore-3.1_sample.yaml");
    OpenAPI openAPI = Yaml.mapper().readValue(jsonString, OpenAPI.class);
    assertNotNull(openAPI);
    assertEquals(openAPI.getInfo().getTitle(), "Swagger Petstore");
    assertEquals(openAPI.getInfo().getVersion(), "1.0.0");
    assertNull(openAPI.getInfo().getSummary());
    assertEquals(openAPI.getInfo().getLicense().getName(), "MIT");
    assertNull(openAPI.getInfo().getLicense().getIdentifier());
    assertNull(openAPI.getWebhooks());
    assertNull(openAPI.getComponents().getPathItems());
    assertNotNull(openAPI.getComponents().getSchemas());
    assertNotNull(openAPI.getComponents().getSchemas().get("Pet"));
    assertNotNull(openAPI.getComponents().getSchemas().get("Pet").getDiscriminator());
    assertNull(openAPI.getComponents().getSchemas().get("Pet").getDiscriminator().getExtensions());
    assertNotNull(openAPI.getComponents().getResponses());
    assertNotNull(openAPI.getComponents().getResponses().get("201"));
    assertEquals(openAPI.getComponents().getResponses().get("201").getDescription(), "api response description");
    assertNotNull(openAPI.getComponents().getParameters());
    assertNotNull(openAPI.getComponents().getParameters().get("param"));
    assertEquals(openAPI.getComponents().getParameters().get("param").getIn(), "query");
    assertEquals(openAPI.getComponents().getParameters().get("param").getName(), "param0");
    assertEquals(openAPI.getComponents().getParameters().get("param").getDescription(), "parameter description");
    assertNotNull(openAPI.getComponents().getExamples());
    assertNotNull(openAPI.getComponents().getExamples().get("example"));
    assertEquals(openAPI.getComponents().getExamples().get("example").getDescription(), "example description");
    assertEquals(openAPI.getComponents().getExamples().get("example").getSummary(), "example summary");
    assertEquals(openAPI.getComponents().getExamples().get("example").getValue(), "This is an example");
    assertNotNull(openAPI.getComponents().getRequestBodies());
    assertNotNull(openAPI.getComponents().getRequestBodies().get("body"));
    assertNotNull(openAPI.getComponents().getHeaders());
    assertNotNull(openAPI.getComponents().getHeaders().get("test-head"));
    assertEquals(openAPI.getComponents().getHeaders().get("test-head").getDescription(), "test header description");
    assertNotNull(openAPI.getComponents().getSecuritySchemes());
    assertNotNull(openAPI.getComponents().getSecuritySchemes().get("basic"));
    assertEquals(openAPI.getComponents().getSecuritySchemes().get("basic").getDescription(), "security description");
    assertEquals(openAPI.getComponents().getSecuritySchemes().get("basic").getType().toString(), "http");
    assertNotNull(openAPI.getComponents().getLinks());
    assertNotNull(openAPI.getComponents().getLinks().get("Link"));
    assertEquals(openAPI.getComponents().getLinks().get("Link").getOperationRef(), "#/paths/~12.0~1repositories~1{username}/get");
    assertNotNull(openAPI.getComponents().getCallbacks());
    assertNotNull(openAPI.getComponents().getCallbacks().get("TestCallback"));
    openAPI = Yaml.mapper().readValue(jsonString, OpenAPI.class);
    assertNotNull(openAPI);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 65 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.

the class ParameterDeSerializationTest method deserializeQueryParameter.

@Test(description = "it should deserialize a QueryParameter")
public void deserializeQueryParameter() throws IOException {
    final String json = "{\"in\":\"query\",\"required\":false,\"schema\":{\"type\":\"string\"}}";
    final Parameter p = m.readValue(json, Parameter.class);
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : Parameter(io.swagger.v3.oas.models.parameters.Parameter) Test(org.testng.annotations.Test)

Aggregations

Parameter (io.swagger.v3.oas.models.parameters.Parameter)48 Test (org.testng.annotations.Test)39 Operation (io.swagger.v3.oas.models.Operation)28 Operation (io.swagger.v3.oas.annotations.Operation)27 lombok.val (lombok.val)26 OpenAPI (io.swagger.v3.oas.models.OpenAPI)20 Map (java.util.Map)17 ArrayList (java.util.ArrayList)16 ReadOperation (org.springframework.boot.actuate.endpoint.annotation.ReadOperation)15 OpenAPI3RequestValidationHandlerImpl (io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl)14 Test (org.junit.Test)14 PathItem (io.swagger.v3.oas.models.PathItem)13 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)13 StringUtils (org.apache.commons.lang3.StringUtils)13 StringSchema (io.swagger.v3.oas.models.media.StringSchema)12 LinkedHashMap (java.util.LinkedHashMap)12 Parameter (io.swagger.v3.oas.annotations.Parameter)11 RequestParameters (io.vertx.ext.web.api.RequestParameters)11 HashMap (java.util.HashMap)11 Schema (io.swagger.v3.oas.models.media.Schema)10