Search in sources :

Example 91 with Yaml

use of io.swagger.v3.core.util.Yaml 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 92 with Yaml

use of io.swagger.v3.core.util.Yaml 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)

Example 93 with Yaml

use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.

the class AbstractAnnotationTest method compareAsYaml.

public void compareAsYaml(final Class<?> cls, final String yaml) throws IOException {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(cls);
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Reader(io.swagger.v3.jaxrs2.Reader) OpenAPI(io.swagger.v3.oas.models.OpenAPI)

Example 94 with Yaml

use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.

the class ReaderTest method testParameterWithFilter.

@Test(description = "Responses with filter")
public void testParameterWithFilter() {
    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(SimpleParameterResource.class);
    OpenAPISpecFilter filterImpl = new RefParameterFilter();
    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" + "  /:\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) OpenAPISpecFilter(io.swagger.v3.core.filter.OpenAPISpecFilter) 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) 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)

Example 95 with Yaml

use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.

the class ReaderTest method testTicket3624.

@Test(description = "Optional handling")
public void testTicket3624() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Service.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /example/model:\n" + "    get:\n" + "      tags:\n" + "      - ExampleService\n" + "      summary: ' Retrieve models for display to the user'\n" + "      operationId: getModels\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: '#/components/schemas/Response'\n" + "  /example/model/by/ids:\n" + "    get:\n" + "      tags:\n" + "      - ExampleService\n" + "      summary: ' Retrieve models by their ids'\n" + "      operationId: getModelsById\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: '#/components/schemas/ByIdResponse'\n" + "  /example/containerized/model:\n" + "    get:\n" + "      tags:\n" + "      - ExampleService\n" + "      summary: ' Retrieve review insights for a specific product'\n" + "      operationId: getContainerizedModels\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: '#/components/schemas/ContainerizedResponse'\n" + "components:\n" + "  schemas:\n" + "    Model:\n" + "      type: object\n" + "      properties:\n" + "        text:\n" + "          type: string\n" + "        title:\n" + "          type: string\n" + "        active:\n" + "          type: boolean\n" + "        schemaParent:\n" + "          $ref: '#/components/schemas/Model'\n" + "        optionalString:\n" + "          type: string\n" + "        parent:\n" + "          $ref: '#/components/schemas/Model'\n" + "        id:\n" + "          type: integer\n" + "          format: int32\n" + "    Response:\n" + "      type: object\n" + "      properties:\n" + "        count:\n" + "          type: integer\n" + "          format: int32\n" + "        models:\n" + "          type: array\n" + "          items:\n" + "            $ref: '#/components/schemas/Model'\n" + "    ByIdResponse:\n" + "      type: object\n" + "      properties:\n" + "        modelsById:\n" + "          type: object\n" + "          additionalProperties:\n" + "            $ref: '#/components/schemas/Model'\n" + "    ContainerizedResponse:\n" + "      type: object\n" + "      properties:\n" + "        totalCount:\n" + "          type: integer\n" + "          format: int32\n" + "        containerizedModels:\n" + "          type: array\n" + "          items:\n" + "            $ref: '#/components/schemas/ModelContainer'\n" + "    ModelContainer:\n" + "      type: object\n" + "      properties:\n" + "        text:\n" + "          type: string\n" + "        model:\n" + "          $ref: '#/components/schemas/Model'\n" + "        id:\n" + "          type: integer\n" + "          format: int32";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)188 OpenAPI (io.swagger.v3.oas.models.OpenAPI)151 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)121 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)94 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)62 Schema (io.swagger.v3.oas.models.media.Schema)58 StringSchema (io.swagger.v3.oas.models.media.StringSchema)49 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)47 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)43 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)42 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)38 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)35 MapSchema (io.swagger.v3.oas.models.media.MapSchema)33 BinarySchema (io.swagger.v3.oas.models.media.BinarySchema)25 DateSchema (io.swagger.v3.oas.models.media.DateSchema)25 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)25 Parameter (io.swagger.v3.oas.models.parameters.Parameter)18 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)18 Components (io.swagger.v3.oas.models.Components)15 Info (io.swagger.v3.oas.models.info.Info)14