in geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/processor/SchemaProcessor.java [112:200]
public void fillSchema(
final Supplier<org.eclipse.microprofile.openapi.models.Components>components,
final Type rawModel,
final org.eclipse.microprofile.openapi.models.media.Schema schema,
final String providedRef) {
final Type model = unwrapType(rawModel);
if (Class.class.isInstance(model)) {
if (boolean.class == model) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.BOOLEAN);
} else if (Boolean.class == model) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.BOOLEAN).nullable(true);
} else if (String.class == model || JsonString.class == model) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.STRING);
} else if (double.class == model || float.class == model) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.NUMBER);
} else if (Double.class == model || Float.class == model || JsonNumber.class == model) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.NUMBER).nullable(true);
} else if (int.class == model || short.class == model || byte.class == model || long.class == model) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.INTEGER);
} else if (Integer.class == model || Short.class == model || Byte.class == model || Long.class == model) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.INTEGER).nullable(true);
} else if (Object.class == model || responseType == model || JsonObject.class == model || JsonValue.class == model) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.OBJECT)
.nullable(true)
.properties(new HashMap<>());
} else if (BigDecimal.class == model || BigInteger.class == model) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.STRING).nullable(true);
} else if (JsonArray.class == model) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.ARRAY)
.nullable(true)
.items(new SchemaImpl()
.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.OBJECT)
.properties(new HashMap<>()));
} else if (isStringable(model)) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.STRING).nullable(true);
} else {
final Class<?> from = Class.class.cast(model);
if (from.isEnum()) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.STRING)
.enumeration(asList(from.getEnumConstants()))
.nullable(true);
} else if (from.isArray()) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.ARRAY);
final SchemaImpl items = new SchemaImpl();
fillSchema(components, from.getComponentType(), items, null);
schema.items(items);
} else if (Collection.class.isAssignableFrom(from)) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.ARRAY);
final SchemaImpl items = new SchemaImpl();
fillSchema(components, Object.class, items, null);
schema.items(items);
} else {
//if providedRef is null and the Schema name is not Empty, we set it as providedRef
final String ref = ofNullable(from.getAnnotation(Schema.class))
.filter(a -> !a.name().isEmpty())
.map(s -> {
final String sRef = s.name();
sets(components, s, schema, sRef);
return sRef;
})
.orElse(providedRef);
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.OBJECT);
final org.eclipse.microprofile.openapi.models.media.Schema objectSchema = getOrCreateReusableObjectComponent(components, from, ref);
if (schema != objectSchema) {
schema.ref(toRef(from, ref));
}
}
}
} else {
schema.items(new SchemaImpl());
if (ParameterizedType.class.isInstance(model)) {
final ParameterizedType pt = ParameterizedType.class.cast(model);
if (Class.class.isInstance(pt.getRawType()) && Map.class.isAssignableFrom(Class.class.cast(pt.getRawType()))) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.OBJECT);
} else if (pt.getActualTypeArguments().length == 1 && Class.class.isInstance(pt.getActualTypeArguments()[0])) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.ARRAY);
final SchemaImpl items = new SchemaImpl();
fillSchema(components, Class.class.cast(pt.getActualTypeArguments()[0]), items, null);
schema.items(items);
} else {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.ARRAY);
}
} else { // todo?
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.ARRAY);
}
}
}