Search in sources :

Example 11 with Paths

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

the class OpenAPI3_1SerializationTest method testRequestBodyRefSerialization.

@Test
public void testRequestBodyRefSerialization() {
    OpenAPI openAPI = new OpenAPI().openapi("3.1.0").path("/test", new PathItem().description("test path item").post(new Operation().operationId("testPathItem").requestBody(new RequestBody().$ref("#/components/requestBodies/body").description("ref request body")))).components(new Components().addRequestBodies("body", new RequestBody().content(new Content().addMediaType("application/json", new MediaType().schema(new ObjectSchema())))));
    SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.1.0\n" + "paths:\n" + "  /test:\n" + "    description: test path item\n" + "    post:\n" + "      operationId: testPathItem\n" + "      requestBody:\n" + "        description: ref request body\n" + "        $ref: '#/components/requestBodies/body'\n" + "components:\n" + "  requestBodies:\n" + "    body:\n" + "      content:\n" + "        application/json:\n" + "          schema: {}");
    SerializationMatchers.assertEqualsToJson31(openAPI, "{\n" + "  \"openapi\" : \"3.1.0\",\n" + "  \"paths\" : {\n" + "    \"/test\" : {\n" + "      \"description\" : \"test path item\",\n" + "      \"post\" : {\n" + "        \"operationId\" : \"testPathItem\",\n" + "        \"requestBody\" : {\n" + "          \"description\" : \"ref request body\",\n" + "          \"$ref\" : \"#/components/requestBodies/body\"\n" + "        }\n" + "      }\n" + "    }\n" + "  },\n" + "  \"components\" : {\n" + "    \"requestBodies\" : {\n" + "      \"body\" : {\n" + "        \"content\" : {\n" + "          \"application/json\" : {\n" + "            \"schema\" : { }\n" + "          }\n" + "        }\n" + "      }\n" + "    }\n" + "  }\n" + "}");
}
Also used : Components(io.swagger.v3.oas.models.Components) PathItem(io.swagger.v3.oas.models.PathItem) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Content(io.swagger.v3.oas.models.media.Content) MediaType(io.swagger.v3.oas.models.media.MediaType) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Example 12 with Paths

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

the class OpenAPI3_1SerializationTest method testResponseRefSerialization.

@Test
public void testResponseRefSerialization() {
    OpenAPI openAPI = new OpenAPI().openapi("3.1.0").path("/test", new PathItem().description("test path item").get(new Operation().operationId("testPathItem").responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("point to a $ref response").$ref("#/components/responses/okResponse"))))).components(new Components().addResponses("okResponse", new ApiResponse().description("everything is good")));
    SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.1.0\n" + "paths:\n" + "  /test:\n" + "    description: test path item\n" + "    get:\n" + "      operationId: testPathItem\n" + "      responses:\n" + "        \"200\":\n" + "          description: point to a $ref response\n" + "          $ref: '#/components/responses/okResponse'\n" + "components:\n" + "  responses:\n" + "    okResponse:\n" + "      description: everything is good");
    SerializationMatchers.assertEqualsToJson31(openAPI, "{\n" + "  \"openapi\" : \"3.1.0\",\n" + "  \"paths\" : {\n" + "    \"/test\" : {\n" + "      \"description\" : \"test path item\",\n" + "      \"get\" : {\n" + "        \"operationId\" : \"testPathItem\",\n" + "        \"responses\" : {\n" + "          \"200\" : {\n" + "            \"description\" : \"point to a $ref response\",\n" + "            \"$ref\" : \"#/components/responses/okResponse\"\n" + "          }\n" + "        }\n" + "      }\n" + "    }\n" + "  },\n" + "  \"components\" : {\n" + "    \"responses\" : {\n" + "      \"okResponse\" : {\n" + "        \"description\" : \"everything is good\"\n" + "      }\n" + "    }\n" + "  }\n" + "}");
}
Also used : Components(io.swagger.v3.oas.models.Components) 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 13 with Paths

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

the class ReaderTest method testResolveDuplicatedOperationId.

@Test(description = "Get a Duplicated Operation Id")
public void testResolveDuplicatedOperationId() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(DuplicatedOperationIdResource.class);
    Paths paths = openAPI.getPaths();
    assertNotNull(paths);
    Operation firstOperation = paths.get(PATH_REF).getGet();
    Operation secondOperation = paths.get(PATH_2_REF).getGet();
    Operation thirdOperation = paths.get(PATH_REF).getPost();
    assertNotNull(firstOperation);
    assertNotNull(secondOperation);
    assertNotNull(thirdOperation);
    assertNotEquals(firstOperation.getOperationId(), secondOperation.getOperationId());
    assertNotEquals(firstOperation.getOperationId(), thirdOperation.getOperationId());
    assertNotEquals(secondOperation.getOperationId(), thirdOperation.getOperationId());
}
Also used : Paths(io.swagger.v3.oas.models.Paths) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 14 with Paths

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

the class ReaderTest method testTicket2848.

@Test(description = "array schema required property")
public void testTicket2848() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket2848Resource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      operationId: getter\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/Town'\n" + "components:\n" + "  schemas:\n" + "    Town:\n" + "      required:\n" + "      - streets\n" + "      type: object\n" + "      properties:\n" + "        streets:\n" + "          minItems: 1\n" + "          uniqueItems: true\n" + "          type: array\n" + "          items:\n" + "            type: string\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 15 with Paths

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

the class ReaderTest method testParameterWithRef.

@Test(description = "Parameter with ref")
public void testParameterWithRef() {
    Components components = new Components();
    components.addParameters("id", new Parameter().description("Id Description").schema(new IntegerSchema()).in(ParameterIn.QUERY.toString()).example(1).required(true));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(RefParameterResource.class);
    String yaml = "openapi: 3.0.1\n" + "info:\n" + "  description: info\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      summary: Simple get operation\n" + "      description: Defines a simple get operation with a payload complex input object\n" + "      operationId: sendPayload\n" + "      parameters:\n" + "      - $ref: '#/components/parameters/id'\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "      deprecated: true\n" + "components:\n" + "  parameters: \n" + "    id:\n" + "      in: query\n" + "      description: Id Description\n" + "      required: true\n" + "      schema:\n" + "        type: integer\n" + "        format: int32\n" + "      example: 1\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)154 OpenAPI (io.swagger.v3.oas.models.OpenAPI)145 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)75 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)70 PathItem (io.swagger.v3.oas.models.PathItem)61 Operation (io.swagger.v3.oas.models.Operation)46 Paths (io.swagger.v3.oas.models.Paths)45 Schema (io.swagger.v3.oas.models.media.Schema)40 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)36 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)33 Components (io.swagger.v3.oas.models.Components)32 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)27 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)27 StringSchema (io.swagger.v3.oas.models.media.StringSchema)25 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)23 Parameter (io.swagger.v3.oas.models.parameters.Parameter)23 Info (io.swagger.v3.oas.models.info.Info)21 MapSchema (io.swagger.v3.oas.models.media.MapSchema)21 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)21 DateSchema (io.swagger.v3.oas.models.media.DateSchema)19