Search in sources :

Example 31 with Yaml

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

the class ReaderTest method testCallbackWithRef.

@Test(description = "Callback with Ref")
public void testCallbackWithRef() {
    Components components = new Components();
    components.addCallbacks("Callback", new Callback().addPathItem("/post", new PathItem().description("Post Path Item")));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(RefCallbackResource.class);
    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" + "components:\n" + "  callbacks:\n" + "    Callback:\n" + "      /post:\n" + "        description: Post Path Item\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) PathItem(io.swagger.v3.oas.models.PathItem) Callback(io.swagger.v3.oas.models.callbacks.Callback) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 32 with Yaml

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

the class ReaderTest method testTicket3092.

@Test
public void testTicket3092() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(UploadResource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /upload:\n" + "    post:\n" + "      operationId: uploadWithBean\n" + "      requestBody:\n" + "        content:\n" + "          multipart/form-data:\n" + "            schema:\n" + "              type: object\n" + "              properties:\n" + "                name:\n" + "                  type: string\n" + "                picture:\n" + "                  $ref: '#/components/schemas/picture'\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json: {}\n" + "  /upload/requestbody:\n" + "    post:\n" + "      operationId: uploadWithBeanAndRequestBody\n" + "      requestBody:\n" + "        content:\n" + "          multipart/form-data:\n" + "            schema:\n" + "              $ref: '#/components/schemas/UploadRequest'\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json: {}\n" + "components:\n" + "  schemas:\n" + "    picture:\n" + "      type: object\n" + "      format: binary\n" + "    UploadRequest:\n" + "      title: Schema for Upload\n" + "      type: object\n" + "      properties:\n" + "        name:\n" + "          type: string\n" + "        picture:\n" + "          type: string\n" + "          format: binary";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 33 with Yaml

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

the class ReaderTest method testHeaderWithRef.

@Test(description = "Header with Ref")
public void testHeaderWithRef() {
    Components components = new Components();
    components.addHeaders("Header", new Header().description("Header Description"));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(RefHeaderResource.class);
    String yaml = "openapi: 3.0.1\n" + "info:\n" + "  description: info\n" + "paths:\n" + "  /path:\n" + "    get:\n" + "      summary: Simple get operation\n" + "      description: Defines a simple get operation with no inputs and a complex output\n" + "      operationId: getWithPayloadResponse\n" + "      responses:\n" + "        \"200\":\n" + "          description: voila!\n" + "          headers:\n" + "            Rate-Limit-Limit:\n" + "              description: The number of allowed requests in the current period\n" + "              $ref: '#/components/headers/Header'\n" + "              style: simple\n" + "              schema:\n" + "                type: integer\n" + "      deprecated: true\n" + "components:\n" + "  headers:\n" + "    Header:\n" + "      description: Header Description\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) Header(io.swagger.v3.oas.models.headers.Header) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 34 with Yaml

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

the class ReaderTest method testResponseWithRef.

@Test(description = "Responses with ref")
public void testResponseWithRef() {
    Components components = new Components();
    components.addResponses("invalidJWT", new ApiResponse().description("when JWT token invalid/expired"));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(RefResponsesResource.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 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" + "        \"401\":\n" + "          $ref: '#/components/responses/invalidJWT'\n" + "      deprecated: true\n" + "components:\n" + "  schemas:\n" + "    GenericError:\n" + "      type: object\n" + "    SampleResponseSchema:\n" + "      type: object\n" + "  responses:\n" + "    invalidJWT:\n" + "      description: when JWT token invalid/expired";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Example 35 with Yaml

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

the class ReaderTest method testTicket3694.

@Test(description = "overridden generic resource methods")
public void testTicket3694() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket3694ResourceExtendedType.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /foo:\n" + "    post:\n" + "      tags:\n" + "      - Foo\n" + "      summary: Foo List in Interface\n" + "      operationId: foo\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: array\n" + "              items:\n" + "                type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "  /bar:\n" + "    post:\n" + "      operationId: bar\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: array\n" + "              items:\n" + "                type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                type: string\n" + "  /another:\n" + "    post:\n" + "      operationId: another\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
    reader = new Reader(new OpenAPI());
    openAPI = reader.read(Ticket3694Resource.class);
    yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /foo:\n" + "    post:\n" + "      tags:\n" + "      - Foo\n" + "      summary: Foo List in Interface\n" + "      operationId: foo\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: array\n" + "              items:\n" + "                type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "  /bar:\n" + "    post:\n" + "      operationId: bar\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: array\n" + "              items:\n" + "                type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                type: string\n" + "  /another:\n" + "    post:\n" + "      operationId: another\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
    reader = new Reader(new OpenAPI());
    openAPI = reader.read(Ticket3694ResourceSimple.class);
    yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /bar:\n" + "    post:\n" + "      operationId: bar\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: array\n" + "              items:\n" + "                type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                type: string";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
    reader = new Reader(new OpenAPI());
    openAPI = reader.read(Ticket3694ResourceSimpleSameReturn.class);
    yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /bar:\n" + "    post:\n" + "      operationId: bar\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: array\n" + "              items:\n" + "                type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Ticket3694Resource(io.swagger.v3.jaxrs2.resources.generics.ticket3694.Ticket3694Resource) Ticket3694ResourceSimple(io.swagger.v3.jaxrs2.resources.generics.ticket3694.Ticket3694ResourceSimple) Ticket3694ResourceSimpleSameReturn(io.swagger.v3.jaxrs2.resources.generics.ticket3694.Ticket3694ResourceSimpleSameReturn) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)63 OpenAPI (io.swagger.v3.oas.models.OpenAPI)55 Schema (io.swagger.v3.oas.models.media.Schema)15 Components (io.swagger.v3.oas.models.Components)13 Info (io.swagger.v3.oas.models.info.Info)13 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)9 OpenAPISpecFilter (io.swagger.v3.core.filter.OpenAPISpecFilter)8 SpecFilter (io.swagger.v3.core.filter.SpecFilter)8 StringSchema (io.swagger.v3.oas.models.media.StringSchema)8 AfterTest (org.testng.annotations.AfterTest)6 OpenApiContext (io.swagger.v3.oas.integration.api.OpenApiContext)5 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)5 Parameter (io.swagger.v3.oas.models.parameters.Parameter)5 DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)4 AbstractSpecFilter (io.swagger.v3.core.filter.AbstractSpecFilter)4 OpenApiConfigurationException (io.swagger.v3.oas.integration.OpenApiConfigurationException)4 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)4 IOException (java.io.IOException)4 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)3 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)3