Search in sources :

Example 6 with Yaml

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

the class OpenAPI3_1DeserializationTest method deserializeChangelog3_1.

@Test
public void deserializeChangelog3_1() throws IOException {
    final String jsonString = ResourceUtils.loadClassResource(getClass(), "specFiles/3.1.0/changelog-3.1.yaml");
    final OpenAPI swagger = Yaml31.mapper().readValue(jsonString, OpenAPI.class);
    assertNotNull(swagger);
    assertEquals(swagger.getInfo().getLicense().getIdentifier(), "test");
    Yaml31.prettyPrint(swagger);
    SerializationMatchers.assertEqualsToYaml31(swagger, jsonString);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 7 with Yaml

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

the class Ticket2926Test method testExtensionsInMapDeserializeAndSerialize.

@Test
public void testExtensionsInMapDeserializeAndSerialize() throws Exception {
    String yaml = "openapi: 3.0.1\n" + "info:\n" + "  title: My title\n" + "  description: API under test\n" + "  version: 1.0.7\n" + "  x-info: test\n" + "servers:\n" + "- url: http://localhost:9999/api\n" + "  x-server: test\n" + "  description: desc\n" + "  variables: \n" + "    serVar: \n" + "      description: desc\n" + "      x-serverVariable: test\n" + "paths:\n" + "  /foo/bar:\n" + "    get:\n" + "      callbacks:\n" + "        /foo/bar:\n" + "          get:\n" + "            description: getoperation\n" + "          x-callback: test\n" + "      responses:\n" + "        default:\n" + "          description: it works!\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                title: inline_response_200\n" + "                type: object\n" + "                properties:\n" + "                  name:\n" + "                    type: string\n" + "              x-mediatype: test\n" + "          x-response: test\n" + "        x-responses: test\n" + "        x-responses-object: \n" + "          aaa: bbb\n" + "        x-responses-array: \n" + "          - aaa\n" + "          - bbb\n" + "      x-operation: test\n" + "    x-pathitem: test\n" + "  x-paths: test\n" + "x-openapi-object: \n" + "  aaa: bbb\n" + "x-openapi-array: \n" + "  - aaa\n" + "  - bbb\n" + "x-openapi: test";
    OpenAPI aa = Yaml.mapper().readValue(yaml, OpenAPI.class);
    SerializationMatchers.assertEqualsToYaml(aa, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 8 with Yaml

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

the class Ticket3063Test method testTicket3063.

@Test
public void testTicket3063() throws Exception {
    final Schema model = context.resolve(new AnnotatedType(BaseClass.class));
    assertNotNull(model);
    String yaml = "BaseClass:\n" + "  required:\n" + "  - type\n" + "  type: object\n" + "  properties:\n" + "    type:\n" + "      type: string\n" + "      description: Type\n" + "      example: AndroidDeviceRequirements\n" + "  description: test\n" + "  discriminator:\n" + "    propertyName: type\n" + "SubClass:\n" + "  required:\n" + "  - type\n" + "  type: object\n" + "  description: SubClass\n" + "  allOf:\n" + "  - $ref: '#/components/schemas/BaseClass'\n" + "  - type: object\n" + "    properties:\n" + "      additionalPropertyWhichShouldBeThere:\n" + "        type: integer\n" + "        description: Test\n" + "        format: int32";
    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 9 with Yaml

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

the class Ticket3030Test method testTicket3030.

@Test
public void testTicket3030() throws Exception {
    final Schema model = context.resolve(new AnnotatedType(Child.class));
    assertNotNull(model);
    String yaml = "Child:\n" + "  type: object\n" + "  allOf:\n" + "  - $ref: '#/components/schemas/Parent'\n" + "  - type: object\n" + "    properties:\n" + "      property:\n" + "        type: string\n" + "Parent:\n" + "  type: object\n" + "  properties:\n" + "    sharedProperty:\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 10 with Yaml

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

the class Ticket3197Test method testTicket3197AsSibling.

@Test
public void testTicket3197AsSibling() throws Exception {
    ModelResolver.composedModelPropertiesAsSibling = true;
    ModelResolver myModelResolver = new ModelResolver(new ObjectMapper());
    ModelResolver.composedModelPropertiesAsSibling = true;
    ModelConverterContextImpl myContext = new ModelConverterContextImpl(myModelResolver);
    final Schema model = myContext.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" + "  properties:\n" + "    id:\n" + "      type: integer\n" + "      format: int64\n" + "    model:\n" + "      type: string\n" + "  allOf:\n" + "  - $ref: '#/components/schemas/Car'\n" + "SportCar:\n" + "  required:\n" + "  - id\n" + "  type: object\n" + "  properties:\n" + "    id:\n" + "      type: integer\n" + "      format: int64\n" + "    model:\n" + "      type: string\n" + "  allOf:\n" + "  - $ref: '#/components/schemas/Car'\n";
    SerializationMatchers.assertEqualsToYaml(myContext.getDefinedModels(), yaml);
    ModelResolver.composedModelPropertiesAsSibling = false;
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) ModelResolver(io.swagger.v3.core.jackson.ModelResolver) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

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