Java Code Examples for org.eclipse.microprofile.openapi.models.media.Schema#setMinItems()

The following examples show how to use org.eclipse.microprofile.openapi.models.media.Schema#setMinItems() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeanValidationScanner.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
void sizeArray(AnnotationTarget target, Schema schema) {
    AnnotationInstance constraint = getConstraint(target, BV_SIZE);

    if (constraint != null) {
        Integer min = intValue(constraint, "min");
        Integer max = intValue(constraint, "max");

        if (min != null && schema.getMinItems() == null) {
            schema.setMinItems(min);
        }

        if (max != null && schema.getMaxItems() == null) {
            schema.setMaxItems(max);
        }
    }
}
 
Example 2
Source File: BeanValidationScanner.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
void notEmptyArray(AnnotationTarget target, Schema schema) {
    AnnotationInstance constraint = getConstraint(target, BV_NOT_EMPTY);

    if (constraint != null && schema.getMinItems() == null) {
        schema.setMinItems(1);
    }
}
 
Example 3
Source File: SchemaReader.java    From smallrye-open-api with Apache License 2.0 4 votes vote down vote up
/**
 * Reads a {@link Schema} OpenAPI node.
 * 
 * @param node json node
 * @return Schema model
 */
public static Schema readSchema(final JsonNode node) {
    if (node == null || !node.isObject()) {
        return null;
    }
    IoLogging.log.singleJsonObject("Schema");
    String name = JsonUtil.stringProperty(node, SchemaConstant.PROP_NAME);

    Schema schema = new SchemaImpl(name);
    schema.setRef(JsonUtil.stringProperty(node, Referenceable.PROP_$REF));
    schema.setFormat(JsonUtil.stringProperty(node, SchemaConstant.PROP_FORMAT));
    schema.setTitle(JsonUtil.stringProperty(node, SchemaConstant.PROP_TITLE));
    schema.setDescription(JsonUtil.stringProperty(node, SchemaConstant.PROP_DESCRIPTION));
    schema.setDefaultValue(readObject(node.get(SchemaConstant.PROP_DEFAULT)));
    schema.setMultipleOf(JsonUtil.bigDecimalProperty(node, SchemaConstant.PROP_MULTIPLE_OF));
    schema.setMaximum(JsonUtil.bigDecimalProperty(node, SchemaConstant.PROP_MAXIMUM));
    schema.setExclusiveMaximum(JsonUtil.booleanProperty(node, SchemaConstant.PROP_EXCLUSIVE_MAXIMUM).orElse(null));
    schema.setMinimum(JsonUtil.bigDecimalProperty(node, SchemaConstant.PROP_MINIMUM));
    schema.setExclusiveMinimum(JsonUtil.booleanProperty(node, SchemaConstant.PROP_EXCLUSIVE_MINIMUM).orElse(null));
    schema.setMaxLength(JsonUtil.intProperty(node, SchemaConstant.PROP_MAX_LENGTH));
    schema.setMinLength(JsonUtil.intProperty(node, SchemaConstant.PROP_MIN_LENGTH));
    schema.setPattern(JsonUtil.stringProperty(node, SchemaConstant.PROP_PATTERN));
    schema.setMaxItems(JsonUtil.intProperty(node, SchemaConstant.PROP_MAX_ITEMS));
    schema.setMinItems(JsonUtil.intProperty(node, SchemaConstant.PROP_MIN_ITEMS));
    schema.setUniqueItems(JsonUtil.booleanProperty(node, SchemaConstant.PROP_UNIQUE_ITEMS).orElse(null));
    schema.setMaxProperties(JsonUtil.intProperty(node, SchemaConstant.PROP_MAX_PROPERTIES));
    schema.setMinProperties(JsonUtil.intProperty(node, SchemaConstant.PROP_MIN_PROPERTIES));
    schema.setRequired(JsonUtil.readStringArray(node.get(SchemaConstant.PROP_REQUIRED)).orElse(null));
    schema.setEnumeration(JsonUtil.readObjectArray(node.get(SchemaConstant.PROP_ENUM)).orElse(null));
    schema.setType(readSchemaType(node.get(SchemaConstant.PROP_TYPE)));
    schema.setItems(readSchema(node.get(SchemaConstant.PROP_ITEMS)));
    schema.setNot(readSchema(node.get(SchemaConstant.PROP_NOT)));
    schema.setAllOf(readSchemaArray(node.get(SchemaConstant.PROP_ALL_OF)).orElse(null));
    schema.setProperties(readSchemas(node.get(SchemaConstant.PROP_PROPERTIES)).orElse(null));
    if (node.has(SchemaConstant.PROP_ADDITIONAL_PROPERTIES)
            && node.get(SchemaConstant.PROP_ADDITIONAL_PROPERTIES).isObject()) {
        schema.setAdditionalPropertiesSchema(readSchema(node.get(SchemaConstant.PROP_ADDITIONAL_PROPERTIES)));
    } else {
        schema.setAdditionalPropertiesBoolean(
                JsonUtil.booleanProperty(node, SchemaConstant.PROP_ADDITIONAL_PROPERTIES).orElse(null));
    }
    schema.setReadOnly(JsonUtil.booleanProperty(node, SchemaConstant.PROP_READ_ONLY).orElse(null));
    schema.setXml(XmlReader.readXML(node.get(SchemaConstant.PROP_XML)));
    schema.setExternalDocs(ExternalDocsReader.readExternalDocs(node.get(ExternalDocsConstant.PROP_EXTERNAL_DOCS)));
    schema.setExample(readObject(node.get(SchemaConstant.PROP_EXAMPLE)));
    schema.setOneOf(readSchemaArray(node.get(SchemaConstant.PROP_ONE_OF)).orElse(null));
    schema.setAnyOf(readSchemaArray(node.get(SchemaConstant.PROP_ANY_OF)).orElse(null));
    schema.setNot(readSchema(node.get(SchemaConstant.PROP_NOT)));
    schema.setDiscriminator(DiscriminatorReader.readDiscriminator(node.get(SchemaConstant.PROP_DISCRIMINATOR)));
    schema.setNullable(JsonUtil.booleanProperty(node, SchemaConstant.PROP_NULLABLE).orElse(null));
    schema.setWriteOnly(JsonUtil.booleanProperty(node, SchemaConstant.PROP_WRITE_ONLY).orElse(null));
    schema.setDeprecated(JsonUtil.booleanProperty(node, SchemaConstant.PROP_DEPRECATED).orElse(null));
    ExtensionReader.readExtensions(node, schema);
    return schema;
}