Search in sources :

Example 46 with PathItem

use of io.swagger.v3.oas.models.PathItem 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)

Example 47 with PathItem

use of io.swagger.v3.oas.models.PathItem 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" + "}");
}
Also used : Schema(io.swagger.v3.oas.models.media.Schema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Components(io.swagger.v3.oas.models.Components) PathItem(io.swagger.v3.oas.models.PathItem) Callback(io.swagger.v3.oas.models.callbacks.Callback) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Header(io.swagger.v3.oas.models.headers.Header) Content(io.swagger.v3.oas.models.media.Content) Example(io.swagger.v3.oas.models.examples.Example) Parameter(io.swagger.v3.oas.models.parameters.Parameter) MediaType(io.swagger.v3.oas.models.media.MediaType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) OpenAPI(io.swagger.v3.oas.models.OpenAPI) SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) Link(io.swagger.v3.oas.models.links.Link) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Example 48 with PathItem

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

the class OpenAPI3_1SerializationTest method testParameterRefSerialization.

@Test
public void testParameterRefSerialization() {
    OpenAPI openAPI = new OpenAPI().openapi("3.1.0").components(new Components().addParameters("testParameter", new Parameter().in("query"))).path("/test", new PathItem().description("test path item").get(new Operation().operationId("testPathItem").addParametersItem(new Parameter().$ref("#/components/parameters/testParameter").description("test parameter"))));
    SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.1.0\n" + "paths:\n" + "  /test:\n" + "    description: test path item\n" + "    get:\n" + "      operationId: testPathItem\n" + "      parameters:\n" + "      - description: test parameter\n" + "        $ref: '#/components/parameters/testParameter'\n" + "components:\n" + "  parameters:\n" + "    testParameter:\n" + "      in: query");
    SerializationMatchers.assertEqualsToJson31(openAPI, "{\n" + "  \"openapi\" : \"3.1.0\",\n" + "  \"paths\" : {\n" + "    \"/test\" : {\n" + "      \"description\" : \"test path item\",\n" + "      \"get\" : {\n" + "        \"operationId\" : \"testPathItem\",\n" + "        \"parameters\" : [ {\n" + "          \"description\" : \"test parameter\",\n" + "          \"$ref\" : \"#/components/parameters/testParameter\"\n" + "        } ]\n" + "      }\n" + "    }\n" + "  },\n" + "  \"components\" : {\n" + "    \"parameters\" : {\n" + "      \"testParameter\" : {\n" + "        \"in\" : \"query\"\n" + "      }\n" + "    }\n" + "  }\n" + "}");
}
Also used : Components(io.swagger.v3.oas.models.Components) PathItem(io.swagger.v3.oas.models.PathItem) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 49 with PathItem

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

the class OpenAPI3_1SerializationTest method testWebHooksSerialization.

@Test
public void testWebHooksSerialization() {
    OpenAPI openAPI = new OpenAPI().openapi("3.1.0").addWebhooks("hook", new PathItem().description("test path hook").get(new Operation().operationId("testHookOperation").responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("test response description")))));
    SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.1.0\n" + "webhooks:\n" + "  hook:\n" + "    description: test path hook\n" + "    get:\n" + "      operationId: testHookOperation\n" + "      responses:\n" + "        \"200\":\n" + "          description: test response description");
    SerializationMatchers.assertEqualsToJson31(openAPI, "{\n" + "  \"openapi\" : \"3.1.0\",\n" + "  \"webhooks\" : {\n" + "    \"hook\" : {\n" + "      \"description\" : \"test path hook\",\n" + "      \"get\" : {\n" + "        \"operationId\" : \"testHookOperation\",\n" + "        \"responses\" : {\n" + "          \"200\" : {\n" + "            \"description\" : \"test response description\"\n" + "          }\n" + "        }\n" + "      }\n" + "    }\n" + "  }\n" + "}");
    openAPI.setOpenapi("3.0.3");
    SerializationMatchers.assertEqualsToYaml(openAPI, "openapi: 3.0.3");
    SerializationMatchers.assertEqualsToJson(openAPI, "{\n" + "  \"openapi\" : \"3.0.3\"\n}");
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Example 50 with PathItem

use of io.swagger.v3.oas.models.PathItem 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" + "}");
}
Also used : Components(io.swagger.v3.oas.models.Components) PathItem(io.swagger.v3.oas.models.PathItem) Header(io.swagger.v3.oas.models.headers.Header) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Aggregations

PathItem (io.swagger.v3.oas.models.PathItem)66 Operation (io.swagger.v3.oas.models.Operation)52 OpenAPI (io.swagger.v3.oas.models.OpenAPI)50 Test (org.testng.annotations.Test)39 Paths (io.swagger.v3.oas.models.Paths)24 Map (java.util.Map)19 HashMap (java.util.HashMap)18 Schema (io.swagger.v3.oas.models.media.Schema)16 Components (io.swagger.v3.oas.models.Components)15 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)14 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)14 LinkedHashMap (java.util.LinkedHashMap)14 ArrayList (java.util.ArrayList)11 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)10 Parameter (io.swagger.v3.oas.models.parameters.Parameter)10 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)8 MediaType (io.swagger.v3.oas.models.media.MediaType)8 HttpMethod (io.swagger.models.HttpMethod)7 Callback (io.swagger.v3.oas.models.callbacks.Callback)7 Content (io.swagger.v3.oas.models.media.Content)7