use of io.swagger.v3.oas.annotations.headers.Header in project swagger-core by swagger-api.
the class ParameterDeSerializationTest method deserializeStringArrayHeaderParameter.
@Test(description = "it should deserialize a string array HeaderParameter")
public void deserializeStringArrayHeaderParameter() throws IOException {
final String json = "{\"in\":\"header\",\"required\":true,\"schema\":{\"type\":\"string\"}}";
final Parameter p = m.readValue(json, Parameter.class);
SerializationMatchers.assertEqualsToJson(p, json);
}
use of io.swagger.v3.oas.annotations.headers.Header in project swagger-core by swagger-api.
the class AnnotationsUtilsHeadersTest method extensionsTest.
@Test(dataProvider = "expectedData")
public void extensionsTest(String methodName, Optional<Map<String, io.swagger.v3.oas.models.headers.Header>> expected) throws NoSuchMethodException {
final Method method = getClass().getDeclaredMethod(methodName);
final Header[] headers = Arrays.stream(method.getAnnotation(Operation.class).responses()).flatMap(response -> Arrays.stream(response.headers())).toArray(Header[]::new);
final Optional<Map<String, io.swagger.v3.oas.models.headers.Header>> optionalMap = AnnotationsUtils.getHeaders(headers, null);
Assert.assertEquals(optionalMap, expected);
}
use of io.swagger.v3.oas.annotations.headers.Header in project swagger-core by swagger-api.
the class OpenAPI3_1SerializationTest method testComponentPathItemsSerialization.
@Test
public void testComponentPathItemsSerialization() {
Schema schema = new StringSchema();
schema.addType(schema.getType());
OpenAPI openAPI = new OpenAPI().openapi("3.1.0").components(new Components().addSchemas("stringTest", schema).addPathItem("/pathTest", new PathItem().description("test path item").get(new Operation().operationId("testPathItem").responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("response description"))))).addResponses("201", new ApiResponse().description("api response description")).addParameters("param", new Parameter().in("query").description("parameter description").schema(schema)).addExamples("example", new Example().summary("example summary").value("This is an example/").description("example description")).addRequestBodies("body", new RequestBody().content(new Content().addMediaType("application/json", new MediaType().schema(new ObjectSchema())))).addHeaders("test-head", new Header().description("test header description")).addSecuritySchemes("basic", new SecurityScheme().in(SecurityScheme.In.HEADER).scheme("http").description("ref security description")).addLinks("Link", new Link().operationRef("#/paths/~12.0~1repositories~1{username}/get")).addCallbacks("TestCallback", new Callback().addPathItem("{$request.query.queryUrl}", new PathItem().description("test path item").post(new Operation().operationId("testPathItem")))));
SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.1.0\n" + "components:\n" + " schemas:\n" + " stringTest:\n" + " type: string\n" + " responses:\n" + " \"201\":\n" + " description: api response description\n" + " parameters:\n" + " param:\n" + " in: query\n" + " description: parameter description\n" + " schema:\n" + " type: string\n" + " examples:\n" + " example:\n" + " summary: example summary\n" + " description: example description\n" + " value: This is an example/\n" + " requestBodies:\n" + " body:\n" + " content:\n" + " application/json:\n" + " schema: {}\n" + " headers:\n" + " test-head:\n" + " description: test header description\n" + " securitySchemes:\n" + " basic:\n" + " description: ref security description\n" + " in: header\n" + " scheme: http\n" + " links:\n" + " Link:\n" + " operationRef: \"#/paths/~12.0~1repositories~1{username}/get\"\n" + " callbacks:\n" + " TestCallback:\n" + " '{$request.query.queryUrl}':\n" + " description: test path item\n" + " post:\n" + " operationId: testPathItem\n" + " pathItems:\n" + " /pathTest:\n" + " description: test path item\n" + " get:\n" + " operationId: testPathItem\n" + " responses:\n" + " \"200\":\n" + " description: response description");
SerializationMatchers.assertEqualsToJson31(openAPI, "{\n" + " \"openapi\" : \"3.1.0\",\n" + " \"components\" : {\n" + " \"schemas\" : {\n" + " \"stringTest\" : {\n" + " \"type\" : \"string\"\n" + " }\n" + " },\n" + " \"responses\" : {\n" + " \"201\" : {\n" + " \"description\" : \"api response description\"\n" + " }\n" + " },\n" + " \"parameters\" : {\n" + " \"param\" : {\n" + " \"in\" : \"query\",\n" + " \"description\" : \"parameter description\",\n" + " \"schema\" : {\n" + " \"type\" : \"string\"\n" + " }\n" + " }\n" + " },\n" + " \"examples\" : {\n" + " \"example\" : {\n" + " \"summary\" : \"example summary\",\n" + " \"description\" : \"example description\",\n" + " \"value\" : \"This is an example/\"\n" + " }\n" + " },\n" + " \"requestBodies\" : {\n" + " \"body\" : {\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : { }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"headers\" : {\n" + " \"test-head\" : {\n" + " \"description\" : \"test header description\"\n" + " }\n" + " },\n" + " \"securitySchemes\" : {\n" + " \"basic\" : {\n" + " \"description\" : \"ref security description\",\n" + " \"in\" : \"header\",\n" + " \"scheme\" : \"http\"\n" + " }\n" + " },\n" + " \"links\" : {\n" + " \"Link\" : {\n" + " \"operationRef\" : \"#/paths/~12.0~1repositories~1{username}/get\"\n" + " }\n" + " },\n" + " \"callbacks\" : {\n" + " \"TestCallback\" : {\n" + " \"{$request.query.queryUrl}\" : {\n" + " \"description\" : \"test path item\",\n" + " \"post\" : {\n" + " \"operationId\" : \"testPathItem\"\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"pathItems\" : {\n" + " \"/pathTest\" : {\n" + " \"description\" : \"test path item\",\n" + " \"get\" : {\n" + " \"operationId\" : \"testPathItem\",\n" + " \"responses\" : {\n" + " \"200\" : {\n" + " \"description\" : \"response description\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}");
openAPI.openapi("3.0.3");
SerializationMatchers.assertEqualsToYaml(openAPI, "openapi: 3.0.3\n" + "components:\n" + " schemas:\n" + " stringTest:\n" + " type: string\n" + " responses:\n" + " \"201\":\n" + " description: api response description\n" + " parameters:\n" + " param:\n" + " in: query\n" + " description: parameter description\n" + " schema:\n" + " type: string\n" + " examples:\n" + " example:\n" + " summary: example summary\n" + " description: example description\n" + " value: This is an example/\n" + " requestBodies:\n" + " body:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: object\n" + " headers:\n" + " test-head:\n" + " description: test header description\n" + " securitySchemes:\n" + " basic:\n" + " description: ref security description\n" + " in: header\n" + " scheme: http\n" + " links:\n" + " Link:\n" + " operationRef: \"#/paths/~12.0~1repositories~1{username}/get\"\n" + " callbacks:\n" + " TestCallback:\n" + " '{$request.query.queryUrl}':\n" + " description: test path item\n" + " post:\n" + " operationId: testPathItem");
SerializationMatchers.assertEqualsToJson(openAPI, "{\n" + " \"openapi\" : \"3.0.3\",\n" + " \"components\" : {\n" + " \"schemas\" : {\n" + " \"stringTest\" : {\n" + " \"type\" : \"string\"\n" + " }\n" + " },\n" + " \"responses\" : {\n" + " \"201\" : {\n" + " \"description\" : \"api response description\"\n" + " }\n" + " },\n" + " \"parameters\" : {\n" + " \"param\" : {\n" + " \"in\" : \"query\",\n" + " \"description\" : \"parameter description\",\n" + " \"schema\" : {\n" + " \"type\" : \"string\"\n" + " }\n" + " }\n" + " },\n" + " \"examples\" : {\n" + " \"example\" : {\n" + " \"summary\" : \"example summary\",\n" + " \"description\" : \"example description\",\n" + " \"value\" : \"This is an example/\"\n" + " }\n" + " },\n" + " \"requestBodies\" : {\n" + " \"body\" : {\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : {\n" + " \"type\" : \"object\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"headers\" : {\n" + " \"test-head\" : {\n" + " \"description\" : \"test header description\"\n" + " }\n" + " },\n" + " \"securitySchemes\" : {\n" + " \"basic\" : {\n" + " \"description\" : \"ref security description\",\n" + " \"in\" : \"header\",\n" + " \"scheme\" : \"http\"\n" + " }\n" + " },\n" + " \"links\" : {\n" + " \"Link\" : {\n" + " \"operationRef\" : \"#/paths/~12.0~1repositories~1{username}/get\"\n" + " }\n" + " },\n" + " \"callbacks\" : {\n" + " \"TestCallback\" : {\n" + " \"{$request.query.queryUrl}\" : {\n" + " \"description\" : \"test path item\",\n" + " \"post\" : {\n" + " \"operationId\" : \"testPathItem\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}");
}
use of io.swagger.v3.oas.annotations.headers.Header in project swagger-core by swagger-api.
the class OpenAPI3_1SerializationTest method testHeaderRefSerialization.
@Test
public void testHeaderRefSerialization() {
OpenAPI openAPI = new OpenAPI().openapi("3.1.0").path("/test", new PathItem().description("test path item").post(new Operation().operationId("testPathItem").responses(new ApiResponses().addApiResponse("default", new ApiResponse().description("default response").addHeaderObject("header", new Header().$ref("#/components/responses/okResponse").description("ref header description")))))).components(new Components().addHeaders("test-head", new Header().description("test header description")));
SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.1.0\n" + "paths:\n" + " /test:\n" + " description: test path item\n" + " post:\n" + " operationId: testPathItem\n" + " responses:\n" + " default:\n" + " description: default response\n" + " headers:\n" + " header:\n" + " description: ref header description\n" + " $ref: '#/components/responses/okResponse'\n" + "components:\n" + " headers:\n" + " test-head:\n" + " description: test header description");
SerializationMatchers.assertEqualsToJson31(openAPI, "{\n" + " \"openapi\" : \"3.1.0\",\n" + " \"paths\" : {\n" + " \"/test\" : {\n" + " \"description\" : \"test path item\",\n" + " \"post\" : {\n" + " \"operationId\" : \"testPathItem\",\n" + " \"responses\" : {\n" + " \"default\" : {\n" + " \"description\" : \"default response\",\n" + " \"headers\" : {\n" + " \"header\" : {\n" + " \"description\" : \"ref header description\",\n" + " \"$ref\" : \"#/components/responses/okResponse\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"components\" : {\n" + " \"headers\" : {\n" + " \"test-head\" : {\n" + " \"description\" : \"test header description\"\n" + " }\n" + " }\n" + " }\n" + "}");
}
use of io.swagger.v3.oas.annotations.headers.Header in project swagger-core by swagger-api.
the class ParameterDeserializer method deserialize.
@Override
public Parameter deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
Parameter result = null;
JsonNode node = jp.getCodec().readTree(jp);
JsonNode sub = node.get("$ref");
JsonNode inNode = node.get("in");
JsonNode desc = node.get("description");
if (sub != null) {
result = new Parameter().$ref(sub.asText());
if (desc != null && openapi31) {
result.description(desc.asText());
}
} else if (inNode != null) {
String in = inNode.asText();
ObjectReader reader = null;
ObjectMapper mapper = null;
if (openapi31) {
mapper = Json31.mapper();
} else {
mapper = Json.mapper();
}
if ("query".equals(in)) {
reader = mapper.readerFor(QueryParameter.class);
} else if ("header".equals(in)) {
reader = mapper.readerFor(HeaderParameter.class);
} else if ("path".equals(in)) {
reader = mapper.readerFor(PathParameter.class);
} else if ("cookie".equals(in)) {
reader = mapper.readerFor(CookieParameter.class);
}
if (reader != null) {
result = reader.with(DeserializationFeature.READ_ENUMS_USING_TO_STRING).readValue(node);
}
}
return result;
}
Aggregations