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);
}
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);
}
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;
}
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();
}
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\"}}");
}
Aggregations