use of io.swagger.v3.oas.models.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.models.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.models.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.models.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\"}}");
}
use of io.swagger.v3.oas.models.media.ArraySchema in project swagger-core by swagger-api.
the class ModelSerializerTest method deserializeArrayModel.
@Test(description = "it should deserialize an array model")
public void deserializeArrayModel() throws IOException {
final String json = "{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/Pet\"}}";
final Schema p = m.readValue(json, Schema.class);
assertTrue(p instanceof ArraySchema);
assertEquals(m.writeValueAsString(p), json);
}
Aggregations