Search in sources :

Example 1 with OpenAPISchema2JsonSchema

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

the class PatternAndSchemaPropertiesTest method testPatternAndSchemaProperties.

@Test
public void testPatternAndSchemaProperties() throws Exception {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    Schema model = context.resolve(new AnnotatedType(AnnotatedPet.class));
    assertEquals(((Schema) model.getPatternProperties().get("what.*ever")).getFormat(), "int32");
    assertEquals(((Schema) model.getPatternProperties().get("it.*takes")).get$ref(), "#/components/schemas/Category");
    assertEquals(((Schema) model.getProperties().get("anotherCategory")).get$ref(), "#/components/schemas/Category");
    assertEquals(((Schema) model.getProperties().get("anotherInteger")).getFormat(), "int32");
    SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "AnnotatedPet:\n" + "  type: object\n" + "  properties:\n" + "    id:\n" + "      type: integer\n" + "      format: int64\n" + "    category:\n" + "      $ref: '#/components/schemas/Category'\n" + "    name:\n" + "      type: string\n" + "    photoUrls:\n" + "      type: array\n" + "      xml:\n" + "        wrapped: true\n" + "      items:\n" + "        type: string\n" + "        xml:\n" + "          name: photoUrl\n" + "    tags:\n" + "      type: array\n" + "      xml:\n" + "        wrapped: true\n" + "      items:\n" + "        $ref: '#/components/schemas/Tag'\n" + "    status:\n" + "      type: string\n" + "      description: pet status in the store\n" + "      enum:\n" + "      - available\n" + "      - pending\n" + "      - sold\n" + "    anotherCategory:\n" + "      $ref: '#/components/schemas/Category'\n" + "    anotherInteger:\n" + "      maximum: 10\n" + "      type: integer\n" + "      description: prop schema 1\n" + "      format: int32\n" + "  description: Annotated Pet\n" + "  nullable: true\n" + "Category:\n" + "  type: object\n" + "  properties:\n" + "    id:\n" + "      type: integer\n" + "      format: int64\n" + "    name:\n" + "      type: string\n" + "  description: prop schema 2\n" + "  xml:\n" + "    name: Category\n" + "Tag:\n" + "  type: object\n" + "  properties:\n" + "    id:\n" + "      type: integer\n" + "      format: int64\n" + "    name:\n" + "      type: string\n" + "  xml:\n" + "    name: Tag");
    context.getDefinedModels().values().forEach(s -> new OpenAPISchema2JsonSchema().process(s));
    SerializationMatchers.assertEqualsToYaml31(context.getDefinedModels(), "AnnotatedPet:\n" + "  type:\n" + "  - object\n" + "  - \"null\"\n" + "  properties:\n" + "    id:\n" + "      type: integer\n" + "      format: int64\n" + "    category:\n" + "      $ref: '#/components/schemas/Category'\n" + "    name:\n" + "      type: string\n" + "    photoUrls:\n" + "      type: array\n" + "      xml:\n" + "        wrapped: true\n" + "      items:\n" + "        type: string\n" + "        xml:\n" + "          name: photoUrl\n" + "    tags:\n" + "      type: array\n" + "      xml:\n" + "        wrapped: true\n" + "      items:\n" + "        $ref: '#/components/schemas/Tag'\n" + "    status:\n" + "      type: string\n" + "      description: pet status in the store\n" + "      enum:\n" + "      - available\n" + "      - pending\n" + "      - sold\n" + "    anotherCategory:\n" + "      $ref: '#/components/schemas/Category'\n" + "    anotherInteger:\n" + "      maximum: 10\n" + "      type: integer\n" + "      description: prop schema 1\n" + "      format: int32\n" + "  patternProperties:\n" + "    what.*ever:\n" + "      maximum: 10\n" + "      type: integer\n" + "      description: prop schema 1\n" + "      format: int32\n" + "    it.*takes:\n" + "      $ref: '#/components/schemas/Category'\n" + "  description: Annotated Pet\n" + "Category:\n" + "  type: object\n" + "  properties:\n" + "    id:\n" + "      type: integer\n" + "      format: int64\n" + "    name:\n" + "      type: string\n" + "  description: prop schema 2\n" + "  xml:\n" + "    name: Category\n" + "Tag:\n" + "  type: object\n" + "  properties:\n" + "    id:\n" + "      type: integer\n" + "      format: int64\n" + "    name:\n" + "      type: string\n" + "  xml:\n" + "    name: Tag\n");
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) OpenAPISchema2JsonSchema(io.swagger.v3.core.util.OpenAPISchema2JsonSchema) OpenAPISchema2JsonSchema(io.swagger.v3.core.util.OpenAPISchema2JsonSchema) Schema(io.swagger.v3.oas.models.media.Schema) AnnotatedPet(io.swagger.v3.core.resolving.v31.model.AnnotatedPet) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) ModelResolver(io.swagger.v3.core.jackson.ModelResolver) Test(org.testng.annotations.Test)

Aggregations

AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)1 ModelConverterContextImpl (io.swagger.v3.core.converter.ModelConverterContextImpl)1 ModelResolver (io.swagger.v3.core.jackson.ModelResolver)1 AnnotatedPet (io.swagger.v3.core.resolving.v31.model.AnnotatedPet)1 OpenAPISchema2JsonSchema (io.swagger.v3.core.util.OpenAPISchema2JsonSchema)1 Schema (io.swagger.v3.oas.models.media.Schema)1 Test (org.testng.annotations.Test)1