in geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/processor/SchemaProcessor.java [366:489]
private void mergeSchema(final Supplier<Components> components,
final org.eclipse.microprofile.openapi.models.media.Schema impl,
final Schema schema, final Type type) {
if (schema.deprecated()) {
impl.deprecated(schema.deprecated());
}
if (schema.type() != SchemaType.DEFAULT) {
impl.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.valueOf(schema.type().name()));
}
if (!schema.title().isEmpty()) {
impl.title(schema.title());
}
if (!schema.description().isEmpty()) {
impl.description(schema.description());
}
if (!schema.format().isEmpty()) {
impl.format(schema.format());
}
if (!schema.ref().isEmpty()) {
impl.ref(schema.ref());
}
final String example = schema.example();
if (!example.isEmpty()) {
if (type != null) {
if (type == double.class || type == Double.class ||
type == float.class || type == Float.class) {
impl.example(Double.parseDouble(example));
} else if (type == long.class || type == Long.class ||
type == int.class || type == Integer.class ||
type == short.class || type == Short.class ||
type == byte.class || type == Byte.class) {
impl.example(Integer.parseInt(example));
} else if (type == boolean.class || type == Boolean.class) {
impl.example(Boolean.parseBoolean(example));
} else if (type == String.class) {
impl.example(example);
} else if ((example.startsWith("{") && example.endsWith("}")) ||
(example.startsWith("[") && example.endsWith("}"))) {
try (final JsonReader reader = jsonReaderFactory.createReader(new StringReader(example))) {
impl.example(reader.readValue());
} catch (final Exception e) {
impl.example(example);
}
} else {
impl.example(example);
}
} else {
impl.example(example);
}
}
of(schema.not()).filter(it -> it != Void.class).ifPresent(t -> impl.not(mapSchemaFromClass(components, t)));
final List<org.eclipse.microprofile.openapi.models.media.Schema> oneOf = Stream.of(schema.oneOf())
.map(it -> mapSchemaFromClass(components, it)).collect(toList());
if (!oneOf.isEmpty()) {
impl.oneOf(oneOf);
}
final List<org.eclipse.microprofile.openapi.models.media.Schema> anyOf = Stream.of(schema.anyOf())
.map(it -> mapSchemaFromClass(components, it)).collect(toList());
if (!anyOf.isEmpty()) {
impl.anyOf(anyOf);
}
final List<org.eclipse.microprofile.openapi.models.media.Schema> allOf = Stream.of(schema.allOf())
.map(it -> mapSchemaFromClass(components, it)).collect(toList());
if (!allOf.isEmpty()) {
impl.allOf(allOf);
}
if (schema.multipleOf() != 0) {
impl.multipleOf(BigDecimal.valueOf(schema.multipleOf()));
}
impl.minimum(toBigDecimal(schema.minimum()));
impl.maximum(toBigDecimal(schema.maximum()));
if (schema.exclusiveMinimum()) {
impl.exclusiveMinimum(schema.exclusiveMinimum());
}
if (schema.exclusiveMaximum()) {
impl.exclusiveMaximum(schema.exclusiveMaximum());
}
if (schema.minLength() >= 0 && schema.minLength() != 0) {
impl.minLength(schema.minLength());
}
if (schema.maxLength() >= 0 && schema.maxLength() != Integer.MAX_VALUE) {
impl.maxLength(schema.maxLength());
}
if (!schema.pattern().isEmpty()) {
impl.pattern(schema.pattern());
}
if (schema.nullable()) {
impl.nullable(schema.nullable());
}
if (schema.minProperties() > 0) {
impl.minProperties(schema.minProperties());
}
if (schema.minProperties() > 0) {
impl.maxProperties(schema.maxProperties());
}
if (schema.minItems() < Integer.MAX_VALUE) {
impl.minItems(schema.minItems());
}
if (schema.maxItems() > Integer.MIN_VALUE) {
impl.maxItems(schema.maxItems());
}
if (schema.uniqueItems()) {
impl.uniqueItems(schema.uniqueItems());
}
if (schema.readOnly()) {
impl.readOnly(schema.readOnly());
}
if (schema.writeOnly()) {
impl.writeOnly(schema.writeOnly());
}
impl.defaultValue(toType(schema.defaultValue(), impl.getType()));
final List<String> required = Stream.of(schema.requiredProperties()).collect(toList());
if (!required.isEmpty()) {
impl.required(required);
}
if (schema.discriminatorMapping().length > 0) {
impl.discriminator(new DiscriminatorImpl().mapping(Stream.of(schema.discriminatorMapping())
.collect(toMap(DiscriminatorMapping::value, it -> it.schema().getName()))));
}
final List<Object> enums = Stream.of(schema.enumeration()).collect(toList());
if (!enums.isEmpty()) {
impl.setEnumeration(enums);
}
}