use of org.eclipse.microprofile.openapi.models.media.Schema in project wildfly-swarm by wildfly-swarm.
the class OpenApiAnnotationScanner method readSchema.
/**
* Reads a Schema annotation into a model.
* @param annotation
*/
@SuppressWarnings("unchecked")
private Schema readSchema(AnnotationInstance annotation) {
if (annotation == null) {
return null;
}
LOG.debug("Processing a single @Schema annotation.");
// Schemas can be hidden. Skip if that's the case.
Boolean isHidden = JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_HIDDEN);
if (isHidden != null && isHidden == Boolean.TRUE) {
return null;
}
Schema schema = new SchemaImpl();
schema.setNot(readClassSchema(annotation.value(OpenApiConstants.PROP_NOT), true));
schema.setOneOf(readClassSchemas(annotation.value(OpenApiConstants.PROP_ONE_OF)));
schema.setAnyOf(readClassSchemas(annotation.value(OpenApiConstants.PROP_ANY_OF)));
schema.setAllOf(readClassSchemas(annotation.value(OpenApiConstants.PROP_ALL_OF)));
schema.setTitle(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_TITLE));
schema.setMultipleOf(JandexUtil.bigDecimalValue(annotation, OpenApiConstants.PROP_MULTIPLE_OF));
schema.setMaximum(JandexUtil.bigDecimalValue(annotation, OpenApiConstants.PROP_MAXIMUM));
schema.setExclusiveMaximum(JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_EXCLUSIVE_MAXIMUM));
schema.setMinimum(JandexUtil.bigDecimalValue(annotation, OpenApiConstants.PROP_MINIMUM));
schema.setExclusiveMinimum(JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_EXCLUSIVE_MINIMUM));
schema.setMaxLength(JandexUtil.intValue(annotation, OpenApiConstants.PROP_MAX_LENGTH));
schema.setMinLength(JandexUtil.intValue(annotation, OpenApiConstants.PROP_MIN_LENGTH));
schema.setPattern(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_PATTERN));
schema.setMaxProperties(JandexUtil.intValue(annotation, OpenApiConstants.PROP_MAX_PROPERTIES));
schema.setMinProperties(JandexUtil.intValue(annotation, OpenApiConstants.PROP_MIN_PROPERTIES));
schema.setRequired(JandexUtil.stringListValue(annotation, OpenApiConstants.PROP_REQUIRED_PROPERTIES));
schema.setDescription(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_DESCRIPTION));
schema.setFormat(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_FORMAT));
schema.setRef(JandexUtil.refValue(annotation, RefType.Schema));
schema.setNullable(JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_NULLABLE));
schema.setReadOnly(JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_READ_ONLY));
schema.setWriteOnly(JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_WRITE_ONLY));
schema.setExample(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_EXAMPLE));
schema.setExternalDocs(readExternalDocs(annotation.value(OpenApiConstants.PROP_EXTERNAL_DOCS)));
schema.setDeprecated(JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_DEPRECATED));
schema.setType(JandexUtil.enumValue(annotation, OpenApiConstants.PROP_TYPE, org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.class));
schema.setEnumeration((List<Object>) (Object) JandexUtil.stringListValue(annotation, OpenApiConstants.PROP_ENUMERATION));
schema.setDefaultValue(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_DEFAULT_VALUE));
schema.setDiscriminator(readDiscriminatorMappings(annotation.value(OpenApiConstants.PROP_DISCRIMINATOR_MAPPING)));
schema.setMaxItems(JandexUtil.intValue(annotation, OpenApiConstants.PROP_MAX_ITEMS));
schema.setMinItems(JandexUtil.intValue(annotation, OpenApiConstants.PROP_MIN_ITEMS));
schema.setUniqueItems(JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_UNIQUE_ITEMS));
if (JandexUtil.isSimpleClassSchema(annotation)) {
Schema implSchema = readClassSchema(annotation.value(OpenApiConstants.PROP_IMPLEMENTATION), true);
schema = MergeUtil.mergeObjects(implSchema, schema);
} else if (JandexUtil.isSimpleArraySchema(annotation)) {
Schema implSchema = readClassSchema(annotation.value(OpenApiConstants.PROP_IMPLEMENTATION), true);
// If the @Schema annotation indicates an array type, then use the Schema
// generated from the implementation Class as the "items" for the array.
schema.setItems(implSchema);
} else {
Schema implSchema = readClassSchema(annotation.value(OpenApiConstants.PROP_IMPLEMENTATION), false);
// If there is an impl class - merge the @Schema properties *onto* the schema
// generated from the Class so that the annotation properties override the class
// properties (as required by the MP+OAI spec).
schema = MergeUtil.mergeObjects(implSchema, schema);
}
return schema;
}
use of org.eclipse.microprofile.openapi.models.media.Schema in project wildfly-swarm by wildfly-swarm.
the class OpenApiParser method readSchemas.
/**
* Reads the {@link Schema} OpenAPI nodes.
* @param node
*/
private Map<String, Schema> readSchemas(JsonNode node) {
if (node == null || !node.isObject()) {
return null;
}
Map<String, Schema> models = new LinkedHashMap<>();
for (Iterator<String> fieldNames = node.fieldNames(); fieldNames.hasNext(); ) {
String fieldName = fieldNames.next();
JsonNode childNode = node.get(fieldName);
models.put(fieldName, readSchema(childNode));
}
return models;
}
use of org.eclipse.microprofile.openapi.models.media.Schema in project wildfly-swarm by wildfly-swarm.
the class OpenApiDataObjectScanner method dfs.
// Scan depth first.
private void dfs(PathEntry rootNode) {
PathEntry currentPathEntry = rootNode;
while (!path.isEmpty()) {
ClassInfo currentClass = currentPathEntry.clazz;
Schema currentSchema = currentPathEntry.schema;
Type currentType = currentPathEntry.clazzType;
// First, handle class annotations.
currentSchema = readKlass(currentClass, currentSchema);
LOG.debugv("Getting all fields for: {0} in class: {1}", currentType, currentClass);
// Get all fields *including* inherited.
Map<FieldInfo, TypeResolver> allFields = TypeResolver.getAllFields(index, currentType, currentClass);
// Handle fields
for (Map.Entry<FieldInfo, TypeResolver> entry : allFields.entrySet()) {
FieldInfo field = entry.getKey();
TypeResolver resolver = entry.getValue();
if (!Modifier.isStatic(field.flags())) {
LOG.tracev("Iterating field {0}", field);
processField(field, resolver, currentSchema, currentPathEntry);
}
}
currentPathEntry = path.pop();
// Handle methods
// TODO put it here!
}
}
use of org.eclipse.microprofile.openapi.models.media.Schema in project wildfly-swarm by wildfly-swarm.
the class OpenApiDataObjectScanner method processField.
private Schema processField(FieldInfo field, TypeResolver typeResolver, Schema parentSchema, PathEntry currentPathEntry) {
Schema fieldSchema = new SchemaImpl();
parentSchema.addProperty(field.name(), fieldSchema);
AnnotationInstance schemaAnno = TypeUtil.getSchemaAnnotation(field);
if (schemaAnno != null) {
// 1. Handle field annotated with @Schema.
return readSchemaAnnotatedField(schemaAnno, field.name(), field.type(), typeResolver, parentSchema, fieldSchema, currentPathEntry);
} else {
// 2. Handle unannotated field and just do simple inference.
readUnannotatedField(typeResolver, field.type(), fieldSchema, currentPathEntry);
// Unannotated won't result in substitution, so just return field schema.
return fieldSchema;
}
}
use of org.eclipse.microprofile.openapi.models.media.Schema in project wildfly-swarm by wildfly-swarm.
the class SchemaFactory method readClassSchemas.
private static List<Schema> readClassSchemas(IndexView index, AnnotationValue value) {
if (value == null) {
return null;
}
Type[] classArray = value.asClassArray();
List<Schema> schemas = new ArrayList<>(classArray.length);
for (Type type : classArray) {
ClassType ctype = (ClassType) type;
Schema schema = introspectClassToSchema(index, ctype);
schemas.add(schema);
}
return schemas;
}
Aggregations