Search in sources :

Example 21 with Callback

use of io.swagger.v3.oas.annotations.callbacks.Callback in project swagger-parser by swagger-api.

the class ComponentsProcessor method processCallbacks.

private void processCallbacks(Set<String> callbackKey, Map<String, Callback> callbacks) {
    callbackKey.addAll(callbacks.keySet());
    for (String callbackName : callbackKey) {
        final Callback callback = callbacks.get(callbackName);
        callbackProcessor.processCallback(callback);
    }
}
Also used : Callback(io.swagger.v3.oas.models.callbacks.Callback)

Example 22 with Callback

use of io.swagger.v3.oas.annotations.callbacks.Callback in project swagger-parser by swagger-api.

the class CallbackProcessor method processReferenceCallback.

public void processReferenceCallback(Callback callback) {
    String $ref = callback.get$ref();
    RefFormat refFormat = computeRefFormat($ref);
    if (isAnExternalRefFormat(refFormat)) {
        final String newRef = externalRefProcessor.processRefToExternalCallback($ref, refFormat);
        if (newRef != null) {
            callback.set$ref("#/components/callbacks/" + newRef);
        }
    }
}
Also used : RefFormat(io.swagger.v3.parser.models.RefFormat) RefUtils.isAnExternalRefFormat(io.swagger.v3.parser.util.RefUtils.isAnExternalRefFormat) RefUtils.computeRefFormat(io.swagger.v3.parser.util.RefUtils.computeRefFormat)

Example 23 with Callback

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"));
}
Also used : OpenAPIDeserializer(io.swagger.v3.parser.util.OpenAPIDeserializer) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) OpenAPIResolver(io.swagger.v3.parser.OpenAPIResolver) JsonNode(com.fasterxml.jackson.databind.JsonNode) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) File(java.io.File) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 24 with Callback

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");
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 25 with 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" + "}");
}
Also used : Components(io.swagger.v3.oas.models.Components) PathItem(io.swagger.v3.oas.models.PathItem) Callback(io.swagger.v3.oas.models.callbacks.Callback) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

Callback (io.swagger.v3.oas.models.callbacks.Callback)19 Operation (io.swagger.v3.oas.models.Operation)13 PathItem (io.swagger.v3.oas.models.PathItem)13 OpenAPI (io.swagger.v3.oas.models.OpenAPI)12 Parameter (io.swagger.v3.oas.models.parameters.Parameter)9 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)9 Test (org.testng.annotations.Test)9 Components (io.swagger.v3.oas.models.Components)7 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)6 Schema (io.swagger.v3.oas.models.media.Schema)6 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Operation (io.swagger.v3.oas.annotations.Operation)4 Example (io.swagger.v3.oas.models.examples.Example)4 Link (io.swagger.v3.oas.models.links.Link)4 StringSchema (io.swagger.v3.oas.models.media.StringSchema)4 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)4 SecurityScheme (io.swagger.v3.oas.models.security.SecurityScheme)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4