use of io.swagger.v3.oas.annotations.callbacks.Callback in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method pathsResolver.
@Test
public void pathsResolver() throws Exception {
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
String pathFile = FileUtils.readFileToString(new File("src/test/resources/oas3.yaml.template"));
pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
final JsonNode rootNode = mapper.readTree(pathFile.getBytes());
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
assertEquals(new OpenAPIResolver(openAPI, new ArrayList<>(), null).resolve(), openAPI);
// internal url pathItem
assertEquals(openAPI.getPaths().get("/pathItemRef2"), openAPI.getPaths().get("/pet"));
// internal array schema inside operation -> responses -> content
ArraySchema schema = (ArraySchema) openAPI.getPaths().get("/pet").getPut().getResponses().get("400").getContent().get("application/json").getSchema();
assertEquals(schema.getItems().get$ref(), "#/components/schemas/VeryComplexType");
// replace of parameters in operation and remove the ones from the pathItem
Assert.assertNotNull(openAPI.getPaths().get("/pet").getPost().getParameters());
Assert.assertNull(openAPI.getPaths().get("/pet").getParameters());
// remote ref pathItem
assertEquals(openAPI.getPaths().get("/pathItemRef").getSummary(), "summary");
assertEquals(openAPI.getPaths().get("/pathItemRef").getPost().getResponses().get("405").getDescription(), "Invalid input");
// internal pathItem operation -> response -> schema
Assert.assertNotNull(openAPI.getPaths().get("/pet/{petId}").getGet().getResponses());
assertEquals(openAPI.getPaths().get("/pet/{petId}").getGet().getResponses().get("200").getContent().get("application/xml").getSchema().get$ref(), "#/components/schemas/Pet");
// internal pathItem -> operation -> callback -> pathItem -> operation -> response -> schema
assertEquals(openAPI.getPaths().get("/pet/{petId}").getGet().getCallbacks().get("mainHook").get("$request.body#/url").getPost().getResponses().get("200").getContent().get("application/xml").getSchema().get$ref(), "#/components/schemas/Pet");
// internal pathItem -> operation -> requestBody
Schema id = (Schema) openAPI.getPaths().get("/pet/findByStatus").getGet().getRequestBody().getContent().get("multipart/mixed").getSchema().getProperties().get("id");
assertEquals(id.get$ref(), "#/components/schemas/Pet");
// internal parameter url
assertEquals(openAPI.getPaths().get("/store/inventory").getGet().getParameters().get(0), openAPI.getComponents().getParameters().get("limitParam"));
}
use of io.swagger.v3.oas.annotations.callbacks.Callback in project swagger-core by swagger-api.
the class JsonDeserializationTest method testDeserializeRefCallback.
@Test(description = "Deserialize ref callback")
public void testDeserializeRefCallback() throws Exception {
String yaml = "openapi: 3.0.1\n" + "info:\n" + " description: info\n" + "paths:\n" + " /simplecallback:\n" + " get:\n" + " summary: Simple get operation\n" + " operationId: getWithNoParameters\n" + " responses:\n" + " \"200\":\n" + " description: voila!\n" + " callbacks:\n" + " testCallback1:\n" + " $ref: '#/components/callbacks/Callback'\n" + " callbacks:\n" + " testCallback1:\n" + " $ref: '#/components/callbacks/Callback'\n" + "components:\n" + " callbacks:\n" + " Callback:\n" + " /post:\n" + " description: Post Path Item\n";
OpenAPI oas = Yaml.mapper().readValue(yaml, OpenAPI.class);
assertEquals(oas.getPaths().get("/simplecallback").getGet().getCallbacks().get("testCallback1").get$ref(), "#/components/callbacks/Callback");
}
use of io.swagger.v3.oas.annotations.callbacks.Callback in project swagger-core by swagger-api.
the class OpenAPI3_1SerializationTest method testCallRefSerialization.
@Test
public void testCallRefSerialization() {
OpenAPI openAPI = new OpenAPI().openapi("3.1.0").path("/test", new PathItem().description("test path item").post(new Operation().operationId("testPathItem").addCallback("callbackSample", new Callback().$ref("#/components/callbacks/TestCallback")))).components(new Components().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" + "paths:\n" + " /test:\n" + " description: test path item\n" + " post:\n" + " operationId: testPathItem\n" + " callbacks:\n" + " callbackSample:\n" + " $ref: '#/components/callbacks/TestCallback'\n" + "components:\n" + " callbacks:\n" + " TestCallback:\n" + " '{$request.query.queryUrl}':\n" + " description: test path item\n" + " post:\n" + " operationId: testPathItem");
SerializationMatchers.assertEqualsToJson31(openAPI, "{\n" + " \"openapi\" : \"3.1.0\",\n" + " \"paths\" : {\n" + " \"/test\" : {\n" + " \"description\" : \"test path item\",\n" + " \"post\" : {\n" + " \"operationId\" : \"testPathItem\",\n" + " \"callbacks\" : {\n" + " \"callbackSample\" : {\n" + " \"$ref\" : \"#/components/callbacks/TestCallback\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"components\" : {\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.callbacks.Callback 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.callbacks.Callback in project swagger-core by swagger-api.
the class ReaderTest method testGetCallbacks.
@Test(description = "Callbacks")
public void testGetCallbacks() {
Reader reader = new Reader(new OpenAPI());
Method[] methods = SimpleCallbackResource.class.getMethods();
Operation callbackOperation = reader.parseMethod(methods[0], null, null);
assertNotNull(callbackOperation);
Map<String, Callback> callbacks = callbackOperation.getCallbacks();
assertNotNull(callbacks);
Callback callback = callbacks.get(CALLBACK_SUBSCRIPTION_ID);
assertNotNull(callback);
PathItem pathItem = callback.get(CALLBACK_URL);
assertNotNull(pathItem);
Operation postOperation = pathItem.getPost();
assertNotNull(postOperation);
assertEquals(CALLBACK_POST_OPERATION_DESCRIPTION, postOperation.getDescription());
Operation getOperation = pathItem.getGet();
assertNotNull(getOperation);
assertEquals(CALLBACK_GET_OPERATION_DESCRIPTION, getOperation.getDescription());
Operation putOperation = pathItem.getPut();
assertNotNull(putOperation);
assertEquals(CALLBACK_POST_OPERATION_DESCRIPTION, putOperation.getDescription());
}
Aggregations