Search in sources :

Example 51 with ArraySchema

use of io.swagger.v3.oas.annotations.media.ArraySchema in project flow by vaadin.

the class SchemaResolver method createArraySchema.

private Schema createArraySchema() {
    ArraySchema array = new ArraySchema();
    array.items(new SchemaResolver(type.getItemType(), usedTypes).resolve());
    return array;
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema)

Example 52 with ArraySchema

use of io.swagger.v3.oas.annotations.media.ArraySchema in project flow by vaadin.

the class SchemaResolverTest method should_ReturnArraySchema_When_GivenTypeIsAnArray.

@Test
public void should_ReturnArraySchema_When_GivenTypeIsAnArray() {
    ResolvedType arrayType = mock(ResolvedType.class);
    ResolvedArrayType arrayResolvedType = mock(ResolvedArrayType.class);
    ResolvedType stringType = mockReferencedTypeOf(String.class);
    when(arrayType.isArray()).thenReturn(true);
    when(arrayType.asArrayType()).thenReturn(arrayResolvedType);
    when(arrayResolvedType.getComponentType()).thenReturn(stringType);
    Map<String, GeneratorType> usedTypes = new HashMap<>();
    SchemaResolver schemaResolver = new SchemaResolver(new GeneratorType(arrayType), usedTypes);
    Schema schema = schemaResolver.resolve();
    Assert.assertTrue(schema instanceof ArraySchema);
    Assert.assertTrue(schema.getNullable());
    Assert.assertTrue(((ArraySchema) schema).getItems() instanceof StringSchema);
    Assert.assertTrue(usedTypes.isEmpty());
}
Also used : ResolvedArrayType(com.github.javaparser.resolution.types.ResolvedArrayType) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) HashMap(java.util.HashMap) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) Test(org.junit.Test)

Example 53 with ArraySchema

use of io.swagger.v3.oas.annotations.media.ArraySchema in project flow by vaadin.

the class CodeGenerator method getTypeDeclaration.

@Override
public String getTypeDeclaration(Schema schema) {
    String optionalSuffix = "";
    if (GeneratorUtils.isTrue(schema.getNullable())) {
        optionalSuffix = MainGenerator.OPTIONAL_SUFFIX;
    }
    if (schema instanceof ArraySchema) {
        ArraySchema arraySchema = (ArraySchema) schema;
        Schema inner = arraySchema.getItems();
        return String.format("Array<%s>%s", this.getTypeDeclaration(inner), optionalSuffix);
    } else if (GeneratorUtils.isNotBlank(schema.get$ref())) {
        return OpenAPIUtil.getSimpleRef(schema.get$ref()) + optionalSuffix;
    } else if (schema.getAdditionalProperties() != null) {
        Schema inner = (Schema) schema.getAdditionalProperties();
        return String.format("Record<string, %s>%s", getTypeDeclaration(inner), optionalSuffix);
    } else if (schema instanceof ComposedSchema) {
        return getTypeDeclarationFromComposedSchema((ComposedSchema) schema, optionalSuffix);
    } else {
        return super.getTypeDeclaration(schema) + optionalSuffix;
    }
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema)

Example 54 with ArraySchema

use of io.swagger.v3.oas.annotations.media.ArraySchema in project hippo by NHS-digital-website.

the class SchemaHelperTest method schemaWithItemsWithNoXOf.

private Schema<?> schemaWithItemsWithNoXOf() {
    final ComposedSchema items = new ComposedSchema();
    items.title("items object");
    return new ObjectSchema().properties(ImmutableMap.of("array-schema", new ArraySchema().items(items)));
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema)

Example 55 with ArraySchema

use of io.swagger.v3.oas.annotations.media.ArraySchema in project swagger-parser by swagger-api.

the class OpenAPIDeserializerTest method testIssue343Parameter.

@Test
public void testIssue343Parameter() {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + "  description: bleh\n" + "  version: 2.0.0\n" + "  title: Test\n" + "paths:\n" + "  /foo:\n" + "    post:\n" + "      parameters:\n" + "        - in: query\n" + "          name: skip\n" + "          schema:\n" + "            type: integer\n" + "            format: int32\n" + "            multipleOf: 3\n" + "      responses:\n" + "        '200':\n" + "          description: OK\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: object\n" + "              additionalProperties:\n" + "                type: string\n" + "        required: true\n" + "components:\n" + "  schemas:\n" + "    Fun:\n" + "      properties:\n" + "        id:\n" + "          type: integer\n" + "          format: int32\n" + "          multipleOf: 5\n" + "        mySet:\n" + "          type: array\n" + "          uniqueItems: true\n" + "          items:\n" + "            type: string";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(yaml, null, null);
    OpenAPI openAPI = result.getOpenAPI();
    QueryParameter qp = (QueryParameter) openAPI.getPaths().get("/foo").getPost().getParameters().get(0);
    assertEquals(new BigDecimal("3"), qp.getSchema().getMultipleOf());
    RequestBody bp = openAPI.getPaths().get("/foo").getPost().getRequestBody();
    Schema schema = bp.getContent().get("application/json").getSchema();
    assertTrue(schema.getAdditionalProperties() != null);
    IntegerSchema id = (IntegerSchema) openAPI.getComponents().getSchemas().get("Fun").getProperties().get("id");
    assertEquals(id.getMultipleOf(), new BigDecimal("5"));
    ArraySchema ap = (ArraySchema) openAPI.getComponents().getSchemas().get("Fun").getProperties().get("mySet");
    assertTrue(ap.getUniqueItems());
}
Also used : QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) BinarySchema(io.swagger.v3.oas.models.media.BinarySchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) BigDecimal(java.math.BigDecimal) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Aggregations

ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)107 Schema (io.swagger.v3.oas.models.media.Schema)85 Test (org.testng.annotations.Test)76 StringSchema (io.swagger.v3.oas.models.media.StringSchema)63 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)53 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)53 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)51 OpenAPI (io.swagger.v3.oas.models.OpenAPI)49 MapSchema (io.swagger.v3.oas.models.media.MapSchema)28 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)22 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)21 PathItem (io.swagger.v3.oas.models.PathItem)16 Parameter (io.swagger.v3.oas.models.parameters.Parameter)16 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)16 MediaType (io.swagger.v3.oas.models.media.MediaType)15 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)15 Operation (io.swagger.v3.oas.models.Operation)14 Content (io.swagger.v3.oas.models.media.Content)12 DateSchema (io.swagger.v3.oas.models.media.DateSchema)11 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)11