Search in sources :

Example 1 with Schema

use of org.eclipse.microprofile.openapi.models.media.Schema in project wildfly-swarm by wildfly-swarm.

the class OpenApiParser method readSchemaArray.

/**
 * Reads a list of schemas.
 * @param node
 */
private List<Schema> readSchemaArray(JsonNode node) {
    if (node == null || !node.isArray()) {
        return null;
    }
    List<Schema> rval = new ArrayList<>(node.size());
    ArrayNode arrayNode = (ArrayNode) node;
    for (JsonNode arrayItem : arrayNode) {
        rval.add(readSchema(arrayItem));
    }
    return rval;
}
Also used : Schema(org.eclipse.microprofile.openapi.models.media.Schema) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 2 with Schema

use of org.eclipse.microprofile.openapi.models.media.Schema in project wildfly-swarm by wildfly-swarm.

the class OpenApiDataObjectScanner method process.

/**
 * Build a Schema with PrimitiveType as root.
 *
 * @param primitive root to begin scan
 * @return the OAI schema
 */
public static Schema process(PrimitiveType primitive) {
    TypeUtil.TypeWithFormat typeFormat = TypeUtil.getTypeFormat(primitive);
    Schema primitiveSchema = new SchemaImpl();
    primitiveSchema.setType(typeFormat.getSchemaType());
    primitiveSchema.setFormat(typeFormat.getFormat().format());
    return primitiveSchema;
}
Also used : SchemaImpl(org.wildfly.swarm.microprofile.openapi.api.models.media.SchemaImpl) TypeUtil(org.wildfly.swarm.microprofile.openapi.runtime.util.TypeUtil) Schema(org.eclipse.microprofile.openapi.models.media.Schema)

Example 3 with Schema

use of org.eclipse.microprofile.openapi.models.media.Schema in project wildfly-swarm by wildfly-swarm.

the class OpenApiDataObjectScanner method preProcessSpecial.

private Schema preProcessSpecial(Type type, TypeResolver typeResolver, Schema parentSchema, PathEntry currentPathEntry) {
    Schema fieldSchema = new SchemaImpl();
    AnnotationInstance schemaAnno = TypeUtil.getSchemaAnnotation(type);
    if (schemaAnno != null) {
        // 1. Handle field annotated with @Schema.
        return readSchemaAnnotatedField(schemaAnno, type.name().toString(), type, typeResolver, parentSchema, fieldSchema, currentPathEntry);
    } else {
        // 2. Handle unannotated field and just do simple inference.
        readUnannotatedField(typeResolver, type, fieldSchema, currentPathEntry);
        // Unannotated won't result in substitution, so just return field schema.
        return fieldSchema;
    }
}
Also used : SchemaImpl(org.wildfly.swarm.microprofile.openapi.api.models.media.SchemaImpl) Schema(org.eclipse.microprofile.openapi.models.media.Schema) AnnotationInstance(org.jboss.jandex.AnnotationInstance)

Example 4 with Schema

use of org.eclipse.microprofile.openapi.models.media.Schema in project wildfly-swarm by wildfly-swarm.

the class OpenApiAnnotationScanner method introspectClassToSchema.

/**
 * Introspects the given class type to generate a Schema model.  The boolean indicates
 * whether this class type should be turned into a reference.
 * @param ctype
 * @param schemaReferenceSupported
 */
private Schema introspectClassToSchema(ClassType ctype, boolean schemaReferenceSupported) {
    if (ctype.name().equals(OpenApiConstants.DOTNAME_RESPONSE)) {
        return null;
    }
    if (schemaReferenceSupported && this.schemaRegistry.has(ctype)) {
        GeneratedSchemaInfo schemaInfo = this.schemaRegistry.lookup(ctype);
        Schema rval = new SchemaImpl();
        rval.setRef(schemaInfo.$ref);
        return rval;
    } else {
        Schema schema = OpenApiDataObjectScanner.process(index, ctype);
        if (schemaReferenceSupported && schema != null && this.index.getClassByName(ctype.name()) != null) {
            GeneratedSchemaInfo schemaInfo = this.schemaRegistry.register(ctype, schema);
            ModelUtil.components(oai).addSchema(schemaInfo.name, schema);
            Schema rval = new SchemaImpl();
            rval.setRef(schemaInfo.$ref);
            return rval;
        } else {
            return schema;
        }
    }
}
Also used : SchemaImpl(org.wildfly.swarm.microprofile.openapi.api.models.media.SchemaImpl) Schema(org.eclipse.microprofile.openapi.models.media.Schema)

Example 5 with Schema

use of org.eclipse.microprofile.openapi.models.media.Schema in project wildfly-swarm by wildfly-swarm.

the class SchemaFactory method readSchema.

@SuppressWarnings("unchecked")
public static Schema readSchema(IndexView index, Schema schema, AnnotationInstance annotation, Map<String, Object> overrides) {
    if (annotation == null) {
        return schema;
    }
    // Schemas can be hidden. Skip if that's the case.
    Boolean isHidden = JandexUtil.booleanValue(annotation, PROP_HIDDEN);
    if (isHidden != null && isHidden == Boolean.TRUE) {
        return schema;
    }
    // schema.setDescription(JandexUtil.stringValue(annotation, ModelConstants.OpenApiConstants.PROP_DESCRIPTION));  IMPLEMENTATION
    schema.setNot((Schema) overrides.getOrDefault(PROP_NOT, readClassSchema(index, annotation.value(PROP_NOT))));
    schema.setOneOf((List<Schema>) overrides.getOrDefault(PROP_ONE_OF, readClassSchemas(index, annotation.value(PROP_ONE_OF))));
    schema.setAnyOf((List<Schema>) overrides.getOrDefault(PROP_ANY_OF, readClassSchemas(index, annotation.value(PROP_ANY_OF))));
    schema.setAllOf((List<Schema>) overrides.getOrDefault(PROP_ALL_OF, readClassSchemas(index, annotation.value(PROP_ALL_OF))));
    schema.setTitle((String) overrides.getOrDefault(PROP_TITLE, JandexUtil.stringValue(annotation, PROP_TITLE)));
    schema.setMultipleOf((BigDecimal) overrides.getOrDefault(PROP_MULTIPLE_OF, JandexUtil.bigDecimalValue(annotation, PROP_MULTIPLE_OF)));
    schema.setMaximum((BigDecimal) overrides.getOrDefault(PROP_MAXIMUM, JandexUtil.bigDecimalValue(annotation, PROP_MAXIMUM)));
    schema.setExclusiveMaximum((Boolean) overrides.getOrDefault(PROP_EXCLUSIVE_MAXIMUM, JandexUtil.booleanValue(annotation, PROP_EXCLUSIVE_MAXIMUM)));
    schema.setMinimum((BigDecimal) overrides.getOrDefault(PROP_MINIMUM, JandexUtil.bigDecimalValue(annotation, PROP_MINIMUM)));
    schema.setExclusiveMinimum((Boolean) overrides.getOrDefault(PROP_EXCLUSIVE_MINIMUM, JandexUtil.booleanValue(annotation, PROP_EXCLUSIVE_MINIMUM)));
    schema.setMaxLength((Integer) overrides.getOrDefault(PROP_MAX_LENGTH, JandexUtil.intValue(annotation, PROP_MAX_LENGTH)));
    schema.setMinLength((Integer) overrides.getOrDefault(PROP_MIN_LENGTH, JandexUtil.intValue(annotation, PROP_MIN_LENGTH)));
    schema.setPattern((String) overrides.getOrDefault(PROP_PATTERN, JandexUtil.stringValue(annotation, PROP_PATTERN)));
    schema.setMaxProperties((Integer) overrides.getOrDefault(PROP_MAX_PROPERTIES, JandexUtil.intValue(annotation, PROP_MAX_PROPERTIES)));
    schema.setMinProperties((Integer) overrides.getOrDefault(PROP_MIN_PROPERTIES, JandexUtil.intValue(annotation, PROP_MIN_PROPERTIES)));
    schema.setRequired((List<String>) overrides.getOrDefault(PROP_REQUIRED_PROPERTIES, JandexUtil.stringListValue(annotation, PROP_REQUIRED_PROPERTIES)));
    schema.setDescription((String) overrides.getOrDefault(PROP_DESCRIPTION, JandexUtil.stringValue(annotation, PROP_DESCRIPTION)));
    schema.setFormat((String) overrides.getOrDefault(PROP_FORMAT, JandexUtil.stringValue(annotation, PROP_FORMAT)));
    schema.setRef((String) overrides.getOrDefault(PROP_REF, JandexUtil.stringValue(annotation, PROP_REF)));
    schema.setNullable((Boolean) overrides.getOrDefault(PROP_NULLABLE, JandexUtil.booleanValue(annotation, PROP_NULLABLE)));
    schema.setReadOnly((Boolean) overrides.getOrDefault(PROP_READ_ONLY, JandexUtil.booleanValue(annotation, PROP_READ_ONLY)));
    schema.setWriteOnly((Boolean) overrides.getOrDefault(PROP_WRITE_ONLY, JandexUtil.booleanValue(annotation, PROP_WRITE_ONLY)));
    schema.setExample(overrides.getOrDefault(PROP_EXAMPLE, JandexUtil.stringValue(annotation, PROP_EXAMPLE)));
    schema.setExternalDocs(readExternalDocs(annotation.value(OpenApiConstants.PROP_EXTERNAL_DOCS)));
    schema.setDeprecated((Boolean) overrides.getOrDefault(PROP_DEPRECATED, JandexUtil.booleanValue(annotation, PROP_DEPRECATED)));
    schema.setType((Schema.SchemaType) overrides.getOrDefault(PROP_TYPE, JandexUtil.enumValue(annotation, PROP_TYPE, Schema.SchemaType.class)));
    schema.setEnumeration((List<Object>) overrides.getOrDefault(PROP_ENUM, JandexUtil.stringListValue(annotation, PROP_ENUM)));
    schema.setDefaultValue(overrides.getOrDefault(PROP_DEFAULT_VALUE, JandexUtil.stringValue(annotation, PROP_DEFAULT_VALUE)));
    // schema.setDiscriminator(readDiscriminatorMappings(annotation.value(OpenApiConstants.PROP_DISCRIMINATOR_MAPPING)));
    schema.setMaxItems((Integer) overrides.getOrDefault(PROP_MAX_ITEMS, JandexUtil.intValue(annotation, PROP_MAX_ITEMS)));
    schema.setMinItems((Integer) overrides.getOrDefault(PROP_MIN_ITEMS, JandexUtil.intValue(annotation, PROP_MIN_ITEMS)));
    schema.setUniqueItems((Boolean) overrides.getOrDefault(PROP_UNIQUE_ITEMS, JandexUtil.booleanValue(annotation, PROP_UNIQUE_ITEMS)));
    Schema implSchema = readClassSchema(index, annotation.value(PROP_IMPLEMENTATION));
    if (schema.getType() == Schema.SchemaType.ARRAY && implSchema != null) {
        // 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 {
        // 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;
}
Also used : Schema(org.eclipse.microprofile.openapi.models.media.Schema)

Aggregations

Schema (org.eclipse.microprofile.openapi.models.media.Schema)51 Type (org.jboss.jandex.Type)15 Test (org.junit.Test)15 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)10 ClassType (org.jboss.jandex.ClassType)10 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)7 ArrayList (java.util.ArrayList)5 Parameter (org.eclipse.microprofile.openapi.models.parameters.Parameter)5 AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)5 SchemaImpl (org.wildfly.swarm.microprofile.openapi.api.models.media.SchemaImpl)5 RequestBodyImpl (fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)4 LinkedHashMap (java.util.LinkedHashMap)4 List (java.util.List)4 DMNType (org.kie.dmn.api.core.DMNType)4 Components (org.eclipse.microprofile.openapi.models.Components)3 Operation (org.eclipse.microprofile.openapi.models.Operation)3 Callback (org.eclipse.microprofile.openapi.models.callbacks.Callback)3 SchemaType (org.eclipse.microprofile.openapi.models.media.Schema.SchemaType)3 APIResponse (org.eclipse.microprofile.openapi.models.responses.APIResponse)3 APIResponses (org.eclipse.microprofile.openapi.models.responses.APIResponses)3