Search in sources :

Example 71 with Content

use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.

the class ReaderTest method testTicket2340.

@Test(description = "Responses with array schema")
public void testTicket2340() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket2340Resource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /test/test:\n" + "    post:\n" + "      operationId: getAnimal\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              $ref: '#/components/schemas/Animal'\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                type: string\n" + "components:\n" + "  schemas:\n" + "    Animal:\n" + "      required:\n" + "      - type\n" + "      type: object\n" + "      properties:\n" + "        type:\n" + "          type: string\n" + "      discriminator:\n" + "        propertyName: type\n" + "    Cat:\n" + "      type: object\n" + "      allOf:\n" + "      - $ref: '#/components/schemas/Animal'\n" + "      - type: object\n" + "        properties:\n" + "          lives:\n" + "            type: integer\n" + "            format: int32\n" + "    Dog:\n" + "      type: object\n" + "      allOf:\n" + "      - $ref: '#/components/schemas/Animal'\n" + "      - type: object\n" + "        properties:\n" + "          barkVolume:\n" + "            type: number\n" + "            format: double\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 72 with Content

use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.

the class ReaderTest method testTicket3587.

@Test(description = "Parameter examples ordering")
public void testTicket3587() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket3587Resource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /test/test:\n" + "    get:\n" + "      operationId: parameterExamplesOrderingTest\n" + "      parameters:\n" + "      - in: query\n" + "        schema:\n" + "          type: string\n" + "        examples:\n" + "          Example One:\n" + "            description: Example One\n" + "          Example Two:\n" + "            description: Example Two\n" + "          Example Three:\n" + "            description: Example Three\n" + "      - in: query\n" + "        schema:\n" + "          type: string\n" + "        examples:\n" + "          Example Three:\n" + "            description: Example Three\n" + "          Example Two:\n" + "            description: Example Two\n" + "          Example One:\n" + "            description: Example One\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}";
    SerializationMatchers.assertEqualsToYamlExact(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 73 with Content

use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.

the class ReaderTest method testTicket3731.

@Test(description = "Constraints annotations in models")
public void testTicket3731() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket3731Resource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /test/cart:\n" + "    get:\n" + "      summary: Get cart items\n" + "      description: Paging follows RFC 5005.\n" + "      operationId: getCart\n" + "      parameters:\n" + "      - name: pageSize\n" + "        in: query\n" + "        description: \"Number of items per page. Range[1, 200]\"\n" + "        schema:\n" + "          maximum: 200\n" + "          minimum: 1\n" + "          type: integer\n" + "          format: int32\n" + "          default: 50\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                type: array\n" + "                items:\n" + "                  type: string\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
    reader = new Reader(new OpenAPI());
    openAPI = reader.read(Ticket3731BisResource.class);
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Ticket3731BisResource(io.swagger.v3.jaxrs2.resources.Ticket3731BisResource) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 74 with Content

use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.

the class ReaderTest method testGetResponsesWithComposition.

@Test(description = "Responses with composition")
public void testGetResponsesWithComposition() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(ResponsesResource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      summary: Simple get operation\n" + "      description: Defines a simple get operation with no inputs and a complex output\n" + "        object\n" + "      operationId: getWithPayloadResponse\n" + "      responses:\n" + "        \"200\":\n" + "          description: voila!\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: '#/components/schemas/SampleResponseSchema'\n" + "        default:\n" + "          description: boo\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/GenericError'\n" + "      deprecated: true\n" + "  /allOf:\n" + "    get:\n" + "      summary: Test inheritance / polymorphism\n" + "      operationId: getAllOf\n" + "      parameters:\n" + "      - name: number\n" + "        in: query\n" + "        description: Test inheritance / polymorphism\n" + "        required: true\n" + "        schema:\n" + "          type: integer\n" + "          format: int32\n" + "        example: 1\n" + "      responses:\n" + "        \"200\":\n" + "          description: bean answer\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                allOf:\n" + "                - $ref: '#/components/schemas/MultipleSub1Bean'\n" + "                - $ref: '#/components/schemas/MultipleSub2Bean'\n" + "  /anyOf:\n" + "    get:\n" + "      summary: Test inheritance / polymorphism\n" + "      operationId: getAnyOf\n" + "      parameters:\n" + "      - name: number\n" + "        in: query\n" + "        description: Test inheritance / polymorphism\n" + "        required: true\n" + "        schema:\n" + "          type: integer\n" + "          format: int32\n" + "        example: 1\n" + "      responses:\n" + "        \"200\":\n" + "          description: bean answer\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                anyOf:\n" + "                - $ref: '#/components/schemas/MultipleSub1Bean'\n" + "                - $ref: '#/components/schemas/MultipleSub2Bean'\n" + "  /oneOf:\n" + "    get:\n" + "      summary: Test inheritance / polymorphism\n" + "      operationId: getOneOf\n" + "      parameters:\n" + "      - name: number\n" + "        in: query\n" + "        description: Test inheritance / polymorphism\n" + "        required: true\n" + "        schema:\n" + "          type: integer\n" + "          format: int32\n" + "        example: 1\n" + "      responses:\n" + "        \"200\":\n" + "          description: bean answer\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                oneOf:\n" + "                - $ref: '#/components/schemas/MultipleSub1Bean'\n" + "                - $ref: '#/components/schemas/MultipleSub2Bean'\n" + "components:\n" + "  schemas:\n" + "    SampleResponseSchema:\n" + "      type: object\n" + "    GenericError:\n" + "      type: object\n" + "    MultipleSub1Bean:\n" + "      type: object\n" + "      description: MultipleSub1Bean\n" + "      allOf:\n" + "      - $ref: '#/components/schemas/MultipleBaseBean'\n" + "      - type: object\n" + "        properties:\n" + "          c:\n" + "            type: integer\n" + "            format: int32\n" + "    MultipleSub2Bean:\n" + "      type: object\n" + "      description: MultipleSub2Bean\n" + "      allOf:\n" + "      - $ref: '#/components/schemas/MultipleBaseBean'\n" + "      - type: object\n" + "        properties:\n" + "          d:\n" + "            type: integer\n" + "            format: int32\n" + "    MultipleBaseBean:\n" + "      type: object\n" + "      properties:\n" + "        beanType:\n" + "          type: string\n" + "        a:\n" + "          type: integer\n" + "          format: int32\n" + "        b:\n" + "          type: string\n" + "      description: MultipleBaseBean";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 75 with Content

use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.

the class ReaderTest method testExampleWithFilter.

@Test(description = "Example with Ref Filter")
public void testExampleWithFilter() {
    Components components = new Components();
    components.addExamples("Id", new Example().description("Id Example").summary("Id Example").value("1"));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(SimpleExamplesResource.class);
    OpenAPISpecFilter filterImpl = new RefExampleFilter();
    SpecFilter f = new SpecFilter();
    openAPI = f.filter(openAPI, filterImpl, null, null, null);
    String yaml = "openapi: 3.0.1\n" + "info:\n" + "  description: info\n" + "paths:\n" + "  /example:\n" + "    post:\n" + "      description: subscribes a client to updates relevant to the requestor's account\n" + "      operationId: subscribe\n" + "      parameters:\n" + "      - example:\n" + "          $ref: '#/components/examples/Id'\n" + "      requestBody:\n" + "        content:\n" + "          '*/*':\n" + "            schema:\n" + "              type: integer\n" + "              format: int32\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/SubscriptionResponse'\n" + "components:\n" + "  schemas:\n" + "    SubscriptionResponse:\n" + "      type: object\n" + "      properties:\n" + "        subscriptionId:\n" + "          type: string\n" + "  examples:\n" + "    Id:\n" + "      summary: Id Example\n" + "      description: Id Example\n" + "      value: \"1\"\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) OpenAPISpecFilter(io.swagger.v3.core.filter.OpenAPISpecFilter) Example(io.swagger.v3.oas.models.examples.Example) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) AbstractSpecFilter(io.swagger.v3.core.filter.AbstractSpecFilter) OpenAPISpecFilter(io.swagger.v3.core.filter.OpenAPISpecFilter) SpecFilter(io.swagger.v3.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Aggregations

OpenAPI (io.swagger.v3.oas.models.OpenAPI)121 Test (org.testng.annotations.Test)120 MediaType (io.swagger.v3.oas.models.media.MediaType)70 Schema (io.swagger.v3.oas.models.media.Schema)70 Operation (io.swagger.v3.oas.annotations.Operation)65 Content (io.swagger.v3.oas.models.media.Content)64 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)62 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)59 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)57 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)53 Operation (io.swagger.v3.oas.models.Operation)52 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)51 StringSchema (io.swagger.v3.oas.models.media.StringSchema)50 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)42 PathItem (io.swagger.v3.oas.models.PathItem)41 ArrayList (java.util.ArrayList)41 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)40 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)37 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)37 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)33