Search in sources :

Example 31 with Paths

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

Example 32 with Paths

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

the class ReaderTest method testRequestBodyWithFilter.

@Test(description = "RequestBody with filter")
public void testRequestBodyWithFilter() {
    Components components = new Components();
    components.addRequestBodies("User", new RequestBody());
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(SimpleRequestBodyResource.class);
    OpenAPISpecFilter filterImpl = new RefRequestBodyFilter();
    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" + "      requestBody:\n" + "        $ref: '#/components/requestBodies/User'\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "      deprecated: true\n" + "components:\n" + "  schemas:\n" + "    User:\n" + "      type: object\n" + "      properties:\n" + "        id:\n" + "          type: integer\n" + "          format: int64\n" + "        username:\n" + "          type: string\n" + "        firstName:\n" + "          type: string\n" + "        lastName:\n" + "          type: string\n" + "        email:\n" + "          type: string\n" + "        password:\n" + "          type: string\n" + "        phone:\n" + "          type: string\n" + "        userStatus:\n" + "          type: integer\n" + "          description: User Status\n" + "          format: int32\n" + "      xml:\n" + "        name: User\n" + "  requestBodies:\n" + "    User: {}\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) OpenAPISpecFilter(io.swagger.v3.core.filter.OpenAPISpecFilter) 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) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Example 33 with Paths

use of io.swagger.v3.oas.models.Paths 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 34 with Paths

use of io.swagger.v3.oas.models.Paths 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 35 with Paths

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

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