Search in sources :

Example 46 with Yaml

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

the class Ticket2189Test method testTicket2189.

@Test
public void testTicket2189() {
    final Schema model = context.resolve(new AnnotatedType(BaseClass.class));
    assertNotNull(model);
    String yaml = "BaseClass:\n" + "  type: object\n" + "  properties:\n" + "    property:\n" + "      type: string\n" + "    type:\n" + "      type: string\n" + "SubClass:\n" + "  type: object\n" + "  allOf:\n" + "  - $ref: '#/components/schemas/BaseClass'\n" + "  - type: object\n" + "    properties:\n" + "      subClassProperty:\n" + "        type: string";
    SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), yaml);
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 47 with Yaml

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

the class Ticket3197Test method testTicket3197.

@Test
public void testTicket3197() throws Exception {
    final Schema model = context.resolve(new AnnotatedType(Car.class));
    assertNotNull(model);
    String yaml = "Car:\n" + "  required:\n" + "  - type\n" + "  type: object\n" + "  properties:\n" + "    carMetaData:\n" + "      type: string\n" + "    type:\n" + "      type: string\n" + "  discriminator:\n" + "    propertyName: type\n" + "    mapping:\n" + "      RaceCar: '#/components/schemas/RaceCar'\n" + "      SportCar: '#/components/schemas/SportCar'\n" + "  oneOf:\n" + "  - $ref: '#/components/schemas/RaceCar'\n" + "  - $ref: '#/components/schemas/SportCar'\n" + "RaceCar:\n" + "  required:\n" + "  - carMetaData\n" + "  - id\n" + "  type: object\n" + "  allOf:\n" + "  - $ref: '#/components/schemas/Car'\n" + "  - type: object\n" + "    properties:\n" + "      id:\n" + "        type: integer\n" + "        format: int64\n" + "      model:\n" + "        type: string\n" + "SportCar:\n" + "  required:\n" + "  - id\n" + "  type: object\n" + "  allOf:\n" + "  - $ref: '#/components/schemas/Car'\n" + "  - type: object\n" + "    properties:\n" + "      id:\n" + "        type: integer\n" + "        format: int64\n" + "      model:\n" + "        type: string\n";
    SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), yaml);
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 48 with Yaml

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

the class ReaderTest method testTicket2144.

@Test(description = "non consistent overridden generic resource methods")
public void testTicket2144() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(ItemResource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /item/{id}:\n" + "    get:\n" + "      operationId: getById\n" + "      parameters:\n" + "      - name: id\n" + "        in: path\n" + "        required: true\n" + "        schema:\n" + "          type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/ItemWithChildren'\n" + "  /item/nogeneric/{id}:\n" + "    get:\n" + "      operationId: getByIdNoGeneric\n" + "      parameters:\n" + "      - name: id\n" + "        in: path\n" + "        required: true\n" + "        schema:\n" + "          type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/ItemWithChildren'\n" + "  /item/nogenericsamereturn/{id}:\n" + "    get:\n" + "      operationId: getByIdNoGenericSameReturn\n" + "      parameters:\n" + "      - name: id\n" + "        in: path\n" + "        required: true\n" + "        schema:\n" + "          type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/BaseDTO'\n" + "  /item/genericparam:\n" + "    post:\n" + "      operationId: genericParam\n" + "      requestBody:\n" + "        content:\n" + "          '*/*':\n" + "            schema:\n" + "              $ref: '#/components/schemas/ItemWithChildren'\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/BaseDTO'\n" + "components:\n" + "  schemas:\n" + "    ItemWithChildren:\n" + "      type: object\n" + "      properties:\n" + "        name:\n" + "          type: string\n" + "        names:\n" + "          type: string\n" + "    BaseDTO:\n" + "      type: object\n" + "      properties:\n" + "        name:\n" + "          type: string";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 49 with Yaml

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

the class ReaderTest method testTicket2763.

@Test(description = "Responses with array schema")
public void testTicket2763() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket2763Resource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /array:\n" + "    get:\n" + "      operationId: getArrayResponses\n" + "      responses:\n" + "        default:\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                type: array\n" + "                items:\n" + "                  $ref: https://openebench.bsc.es/monitor/tool/tool.json\n" + "  /schema:\n" + "    get:\n" + "      operationId: getSchemaResponses\n" + "      responses:\n" + "        default:\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: https://openebench.bsc.es/monitor/tool/tool.json";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 50 with Yaml

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

the class ReaderTest method testTicket3149.

@Test(description = "overridden generic resource interface default methods")
public void testTicket3149() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(MainResource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /test:\n" + "    post:\n" + "      tags:\n" + "      - Test inheritance on default implementation in interfaces\n" + "      operationId: firstEndpoint\n" + "      requestBody:\n" + "        content:\n" + "          '*/*':\n" + "            schema:\n" + "              $ref: '#/components/schemas/SampleDTO'\n" + "      responses:\n" + "        \"201\":\n" + "          description: Created\n" + "        \"400\":\n" + "          description: Bad Request\n" + "        \"403\":\n" + "          description: Forbidden\n" + "        \"404\":\n" + "          description: Not Found\n" + "  /test/{id}:\n" + "    get:\n" + "      tags:\n" + "      - Test inheritance on default implementation in interfaces\n" + "      operationId: secondEnpoint\n" + "      requestBody:\n" + "        content:\n" + "          '*/*':\n" + "            schema:\n" + "              $ref: '#/components/schemas/SampleOtherDTO'\n" + "      responses:\n" + "        \"200\":\n" + "          description: OK\n" + "        \"400\":\n" + "          description: Bad Request\n" + "        \"403\":\n" + "          description: Forbidden\n" + "        \"404\":\n" + "          description: Not Found\n" + "  /test/original/{id}:\n" + "    get:\n" + "      tags:\n" + "      - Test inheritance on default implementation in interfaces\n" + "      operationId: originalEndpoint\n" + "      requestBody:\n" + "        content:\n" + "          '*/*':\n" + "            schema:\n" + "              $ref: '#/components/schemas/SampleOtherDTO'\n" + "      responses:\n" + "        \"200\":\n" + "          description: OK\n" + "        \"400\":\n" + "          description: Bad Request\n" + "        \"403\":\n" + "          description: Forbidden\n" + "        \"404\":\n" + "          description: Not Found\n" + "components:\n" + "  schemas:\n" + "    SampleDTO:\n" + "      type: object\n" + "      properties:\n" + "        name:\n" + "          type: string\n" + "    SampleOtherDTO:\n" + "      type: object\n" + "      properties:\n" + "        label:\n" + "          type: string";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : 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