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);
}
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");
}
}
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());
}
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);
}
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);
}
Aggregations