Search in sources :

Example 41 with ArraySchema

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

the class ModelPropertyTest method extractProperties.

@Test
public void extractProperties() {
    final Map<String, Schema> models = ModelConverters.getInstance().readAll(Family.class);
    assertEquals(models.size(), 3);
    final Schema person = models.get("Person");
    final Schema employer = (Schema) person.getProperties().get("employer");
    assertTrue(employer instanceof ArraySchema);
    final ArraySchema employerProperty = (ArraySchema) employer;
    final Schema items = employerProperty.getItems();
    assertEquals(items.get$ref(), "#/components/schemas/Employer");
    final Schema awards = (Schema) person.getProperties().get("awards");
    assertTrue(awards instanceof ArraySchema);
    assertTrue(((ArraySchema) awards).getItems() instanceof StringSchema);
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Example 42 with ArraySchema

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

the class ComposedSchemaTest method readArrayComposedSchema_ticket2616.

@Test(description = "read composed schem refs #2616")
public void readArrayComposedSchema_ticket2616() {
    Map<String, Schema> schemas = ModelConverters.getInstance().readAll(TestObject2616.class);
    Schema model = schemas.get("testObject");
    Assert.assertNotNull(model);
    Map<String, Schema> properties = model.getProperties();
    Assert.assertNotNull(properties.get("objects"));
    Assert.assertTrue(properties.get("objects") instanceof ArraySchema);
    model = schemas.get("AbstractObject");
    Assert.assertNotNull(model);
    Assert.assertTrue(model instanceof ComposedSchema);
    Assert.assertTrue(((ComposedSchema) model).getOneOf().size() == 2);
    model = schemas.get("AObject");
    Assert.assertNotNull(model);
    model = schemas.get("BObject");
    Assert.assertNotNull(model);
    model = schemas.get("objects");
    Assert.assertNull(model);
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Test(org.testng.annotations.Test)

Example 43 with ArraySchema

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

the class SwaggerAnnotationIntrospector method hasRequiredMarker.

@Override
public Boolean hasRequiredMarker(AnnotatedMember m) {
    XmlElement elem = m.getAnnotation(XmlElement.class);
    if (elem != null) {
        if (elem.required()) {
            return true;
        }
    }
    JsonProperty jsonProperty = m.getAnnotation(JsonProperty.class);
    if (jsonProperty != null) {
        if (jsonProperty.required()) {
            return true;
        }
    }
    Schema ann = m.getAnnotation(Schema.class);
    if (ann != null) {
        if (ann.required()) {
            return ann.required();
        }
    }
    ArraySchema arraySchema = m.getAnnotation(ArraySchema.class);
    if (arraySchema != null) {
        if (arraySchema.arraySchema().required()) {
            return arraySchema.arraySchema().required();
        }
        if (arraySchema.schema().required()) {
            return arraySchema.schema().required();
        }
    }
    return null;
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ArraySchema(io.swagger.v3.oas.annotations.media.ArraySchema) Schema(io.swagger.v3.oas.annotations.media.Schema) ArraySchema(io.swagger.v3.oas.annotations.media.ArraySchema) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 44 with ArraySchema

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

the class SwaggerAnnotationIntrospector method findSubtypes.

@Override
public List<NamedType> findSubtypes(Annotated a) {
    Schema schema = a.getAnnotation(Schema.class);
    if (schema == null) {
        final ArraySchema arraySchema = a.getAnnotation(ArraySchema.class);
        if (arraySchema != null) {
            schema = arraySchema.schema();
        }
    }
    if (AnnotationsUtils.hasSchemaAnnotation(schema)) {
        final Class<?>[] classes = schema.subTypes();
        final List<NamedType> names = new ArrayList<>(classes.length);
        for (Class<?> subType : classes) {
            names.add(new NamedType(subType));
        }
        if (!names.isEmpty()) {
            return names;
        }
    }
    return Collections.emptyList();
}
Also used : ArraySchema(io.swagger.v3.oas.annotations.media.ArraySchema) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) Schema(io.swagger.v3.oas.annotations.media.Schema) ArraySchema(io.swagger.v3.oas.annotations.media.ArraySchema) ArrayList(java.util.ArrayList) AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass)

Example 45 with ArraySchema

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

the class ModelSerializerTest method serializeArrayModel.

@Test(description = "it should serialize an array model")
public void serializeArrayModel() throws IOException {
    final ArraySchema model = new ArraySchema();
    model.setItems(new Schema().$ref("Pet"));
    assertEquals(m.writeValueAsString(model), "{\"type\":\"array\",\"items\":{\"$ref\":\"#/components/schemas/Pet\"}}");
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) 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