Class SchemaInfo

java.lang.Object
org.apache.juneau.bean.openapi3.OpenApiElement
org.apache.juneau.bean.openapi3.SchemaInfo

public class SchemaInfo extends OpenApiElement
Allows the definition of input and output data types.

The Schema Object allows the definition of input and output data types, including objects, primitives, and arrays. This object is an extended subset of the JSON Schema Specification Draft 4, with additional extensions provided by the OpenAPI Specification to allow for more complete documentation.

OpenAPI Specification:

The Schema Object supports all properties from JSON Schema Draft 4, including but not limited to:

  • type (string) - The data type. Values: "string", "number", "integer", "boolean", "array", "object"
  • format (string) - The format modifier (e.g., "int32", "int64", "float", "double", "date", "date-time")
  • title (string) - A short title for the schema
  • description (string) - A description of the schema (CommonMark syntax may be used)
  • default (any) - The default value
  • multipleOf (number) - Must be a multiple of this value
  • maximum (number) - Maximum value (inclusive by default)
  • exclusiveMaximum (boolean) - If true, maximum is exclusive
  • minimum (number) - Minimum value (inclusive by default)
  • exclusiveMinimum (boolean) - If true, minimum is exclusive
  • maxLength (integer) - Maximum string length
  • minLength (integer) - Minimum string length
  • pattern (string) - Regular expression pattern the string must match
  • maxItems (integer) - Maximum array length
  • minItems (integer) - Minimum array length
  • uniqueItems (boolean) - If true, array items must be unique
  • maxProperties (integer) - Maximum number of object properties
  • minProperties (integer) - Minimum number of object properties
  • required (array of string) - Required property names
  • enum (array) - Possible values for this schema
  • properties (map of SchemaInfo) - Object property definitions
  • items (Items) - Schema for array items
  • allOf (array of SchemaInfo) - Must validate against all schemas
  • oneOf (array of SchemaInfo) - Must validate against exactly one schema
  • anyOf (array of SchemaInfo) - Must validate against any schema
  • not (SchemaInfo) - Must not validate against this schema
  • nullable (boolean) - Allows the value to be null (OpenAPI 3.0 extension)
  • discriminator (Discriminator) - Discriminator for polymorphism (OpenAPI extension)
  • readOnly (boolean) - Relevant only for Schema properties (OpenAPI extension)
  • writeOnly (boolean) - Relevant only for Schema properties (OpenAPI extension)
  • xml (Xml) - XML representation details (OpenAPI extension)
  • externalDocs (ExternalDocumentation) - Additional external documentation (OpenAPI extension)
  • example (any) - Example value (OpenAPI extension)
  • deprecated (boolean) - Specifies that the schema is deprecated (OpenAPI extension)
Example:

// Create a schema for a Pet object SchemaInfo schema = new SchemaInfo() .setType("object") .setRequired("id", "name") .setProperties( JsonMap.of( "id", new SchemaInfo().setType("integer").setFormat("int64"), "name", new SchemaInfo().setType("string"), "tag", new SchemaInfo().setType("string") ) );

See Also:
  • Constructor Details

    • SchemaInfo

      public SchemaInfo()
      Default constructor.
    • SchemaInfo

      public SchemaInfo(SchemaInfo copyFrom)
      Copy constructor.
      Parameters:
      copyFrom - The object to copy.
  • Method Details

    • addAllOf

      public SchemaInfo addAllOf(Object... values)
      Adds one or more values to the allOf property.
      Parameters:
      values - The values to add to this property.
      Valid types:
      • Object
      • Collection<Object>
      • String - JSON array representation of Collection<Object>
        Example:

        allOf("['foo','bar']");

      • String - Individual values
        Example:

        allOf("foo", "bar");


      Ignored if null.
      Returns:
      This object
    • addAnyOf

      public SchemaInfo addAnyOf(Object... values)
      Adds one or more values to the allOf property.
      Parameters:
      values - The values to add to this property.
      Valid types:
      • Object
      • Collection<Object>
      • String - JSON array representation of Collection<Object>
        Example:

        allOf("['foo','bar']");

      • String - Individual values
        Example:

        allOf("foo", "bar");


      Ignored if null.
      Returns:
      This object
    • addEnum

      public SchemaInfo addEnum(Object... values)
      Adds one or more values to the enum property.
      Parameters:
      values - The values to add to this property.
      Valid types:
      • Object
      • Collection<Object>
      • String - JSON array representation of Collection<Object>
        Example:

        enum_("['foo','bar']");

      • String - Individual values
        Example:

        enum_("foo", "bar");


      Ignored if null.
      Returns:
      This object
    • addOneOf

      public SchemaInfo addOneOf(Object... values)
      Adds one or more values to the allOf property.
      Parameters:
      values - The values to add to this property.
      Valid types:
      • Object
      • Collection<Object>
      • String - JSON array representation of Collection<Object>
        Example:

        allOf("['foo','bar']");

      • String - Individual values
        Example:

        allOf("foo", "bar");


      Ignored if null.
      Returns:
      This object
    • addRequired

      public SchemaInfo addRequired(String... values)
      Parameters:
      values - The new value for this property.
      Valid types:
      • Collection<String>
      • String - JSON array representation of Collection<String>
        Example:

        schemes("['scheme1','scheme2']");

      • String - Individual values
        Example:

        schemes("scheme1, "scheme2");

      Returns:
      This object
    • copy

      public SchemaInfo copy()
      Make a deep copy of this object.
      Returns:
      A deep copy of this object.
    • get

      public <T> T get(String property, Class<T> type)
      Description copied from class: OpenApiElement
      Generic property getter.

      Can be used to retrieve non-standard Swagger fields such as "$ref".

      Overrides:
      get in class OpenApiElement
      Type Parameters:
      T - The datatype to cast the value to.
      Parameters:
      property - The property name to retrieve.
      type - The datatype to cast the value to.
      Returns:
      The property value, or null if the property does not exist or is not set.
    • getAdditionalProperties

      Bean property getter: additionalProperties.
      Returns:
      The property value, or null if it is not set.
    • getAllOf

      public List<Object> getAllOf()
      Bean property getter: allOf.
      Returns:
      The property value, or null if it is not set.
    • getAnyOf

      public List<Object> getAnyOf()
      Bean property getter: allOf.
      Returns:
      The property value, or null if it is not set.
    • getDefault

      public Object getDefault()
      Bean property getter: default.

      Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object.

      Returns:
      The property value, or null if it is not set.
    • getDeprecated

      Bean property getter: deprecated.
      Returns:
      The property value, or null if it is not set.
    • getDescription

      Bean property getter: description.
      Returns:
      The property value, or null if it is not set.
    • getDiscriminator

      Bean property getter: discriminator.
      Returns:
      The property value, or null if it is not set.
    • getEnum

      public List<Object> getEnum()
      Bean property getter: enum.
      Returns:
      The property value, or null if it is not set.
    • getExample

      public Object getExample()
      Bean property getter: example.
      Returns:
      The property value, or null if it is not set.
    • getExclusiveMaximum

      Bean property getter: exclusiveMaximum.
      Returns:
      The property value, or null if it is not set.
    • getExclusiveMinimum

      Bean property getter: exclusiveMinimum.
      Returns:
      The property value, or null if it is not set.
    • getExternalDocs

      Bean property getter: externalDocs.
      Returns:
      The property value, or null if it is not set.
    • getFormat

      public String getFormat()
      Bean property getter: format.
      Returns:
      The property value, or null if it is not set.
    • getItems

      public Items getItems()
      Bean property getter: items.
      Returns:
      The property value, or null if it is not set.
    • getMaximum

      public Number getMaximum()
      Bean property getter: maximum.
      Returns:
      The property value, or null if it is not set.
    • getMaxItems

      public Integer getMaxItems()
      Bean property getter: maxItems.
      Returns:
      The property value, or null if it is not set.
    • getMaxLength

      Bean property getter: maxLength.
      Returns:
      The property value, or null if it is not set.
    • getMaxProperties

      Bean property getter: maxProperties.
      Returns:
      The property value, or null if it is not set.
    • getMinimum

      public Number getMinimum()
      Bean property getter: minimum.
      Returns:
      The property value, or null if it is not set.
    • getMinItems

      public Integer getMinItems()
      Bean property getter: minItems.
      Returns:
      The property value, or null if it is not set.
    • getMinLength

      Bean property getter: minLength.
      Returns:
      The property value, or null if it is not set.
    • getMinProperties

      Bean property getter: minProperties.
      Returns:
      The property value, or null if it is not set.
    • getMultipleOf

      Bean property getter: multipleOf.
      Returns:
      The property value, or null if it is not set.
    • getNot

      public SchemaInfo getNot()
      Bean property getter: not.
      Returns:
      The property value, or null if it is not set.
    • getNullable

      public Boolean getNullable()
      Bean property getter: uniqueItems.
      Returns:
      The property value, or null if it is not set.
    • getOneOf

      public List<Object> getOneOf()
      Bean property getter: allOf.
      Returns:
      The property value, or null if it is not set.
    • getPattern

      public String getPattern()
      Bean property getter: pattern.
      Returns:
      The property value, or null if it is not set.
    • getProperties

      Bean property getter: properties.
      Returns:
      The property value, or null if it is not set.
    • getReadOnly

      public Boolean getReadOnly()
      Bean property getter: readOnly.
      Returns:
      The property value, or null if it is not set.
    • getRef

      @Beanp("$ref") public String getRef()
      Bean property getter: $ref.
      Returns:
      The property value, or null if it is not set.
    • getRequired

      public List<String> getRequired()
      Bean property getter: required.

      The list of required properties.

      Returns:
      The property value, or null if it is not set.
    • getTitle

      public String getTitle()
      Bean property getter: title.
      Returns:
      The property value, or null if it is not set.
    • getType

      public String getType()
      Bean property getter: type.
      Returns:
      The property value, or null if it is not set.
    • getUniqueItems

      Bean property getter: uniqueItems.
      Returns:
      The property value, or null if it is not set.
    • getWriteOnly

      Bean property getter: WriteOnly.
      Returns:
      The property value, or null if it is not set.
    • getXml

      public Xml getXml()
      Bean property getter: xml.
      Returns:
      The property value, or null if it is not set.
    • keySet

      public Set<String> keySet()
      Description copied from class: OpenApiElement
      Returns all the keys on this element.
      Overrides:
      keySet in class OpenApiElement
      Returns:
      All the keys on this element.
      Never null.
    • resolveRefs

      public SchemaInfo resolveRefs(OpenApi openApi, Deque<String> refStack, int maxDepth)
      Resolves any "$ref" attributes in this element.
      Parameters:
      openApi - The swagger document containing the definitions.
      refStack - Keeps track of previously-visited references so that we don't cause recursive loops.
      maxDepth - The maximum depth to resolve references.
      After that level is reached, $ref references will be left alone.
      Useful if you have very complex models and you don't want your swagger page to be overly-complex.
      Returns:
      This object with references resolved.
      May or may not be the same object.
    • set

      public SchemaInfo set(String property, Object value)
      Description copied from class: OpenApiElement
      Generic property setter.

      Can be used to set non-standard Swagger fields such as "$ref".

      Overrides:
      set in class OpenApiElement
      Parameters:
      property - The property name to set. Must not be null.
      value - The new value for the property.
      Returns:
      This object
    • setAdditionalProperties

      Bean property setter: additionalProperties.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setAllOf

      Bean property setter: allOf.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setAnyOf

      Bean property setter: allOf.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setDefault

      public SchemaInfo setDefault(Object value)
      Bean property setter: default.

      Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object.

      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setDeprecated

      Bean property setter: deprecated.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setDescription

      Bean property setter: description.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setDiscriminator

      Bean property setter: discriminator.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setEnum

      Bean property setter: enum.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setExample

      public SchemaInfo setExample(Object value)
      Bean property setter: example.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setExclusiveMaximum

      Bean property setter: exclusiveMaximum.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setExclusiveMinimum

      Bean property setter: exclusiveMinimum.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setExternalDocs

      Bean property setter: externalDocs.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setFormat

      public SchemaInfo setFormat(String value)
      Bean property setter: format.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Formats defined by the OAS include:
      • "int32"
      • "int64"
      • "float"
      • "double"
      • "byte"
      • "binary"
      • "date"
      • "date-time"
      • "password"
      Returns:
      This object
    • setItems

      public SchemaInfo setItems(Items value)
      Bean property setter: items.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setMaximum

      public SchemaInfo setMaximum(Number value)
      Bean property setter: maximum.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setMaxItems

      public SchemaInfo setMaxItems(Integer value)
      Bean property setter: maxItems.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setMaxLength

      Bean property setter: maxLength.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setMaxProperties

      Bean property setter: maxProperties.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setMinimum

      public SchemaInfo setMinimum(Number value)
      Bean property setter: minimum.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setMinItems

      public SchemaInfo setMinItems(Integer value)
      Bean property setter: minItems.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setMinLength

      Bean property setter: minLength.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setMinProperties

      Bean property setter: minProperties.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setMultipleOf

      Bean property setter: multipleOf.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setNot

      public SchemaInfo setNot(SchemaInfo value)
      Bean property setter: not.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setNullable

      public SchemaInfo setNullable(Boolean value)
      Bean property setter: nullable.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setOneOf

      Bean property setter: allOf.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setPattern

      public SchemaInfo setPattern(String value)
      Bean property setter: pattern.

      This string SHOULD be a valid regular expression.

      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setProperties

      Bean property setter: properties.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setReadOnly

      public SchemaInfo setReadOnly(Boolean value)
      Bean property setter: readOnly.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setRef

      @Beanp("$ref") public SchemaInfo setRef(Object value)
      Bean property setter: $ref.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setRequired

      Bean property setter: required.

      The list of required properties.

      Parameters:
      value - The new value for this property.
      Valid values:
      • "http"
      • "https"
      • "ws"
      • "wss"

      Can be null to unset the property.
      Returns:
      This object
    • setTitle

      public SchemaInfo setTitle(String value)
      Bean property setter: title.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setType

      public SchemaInfo setType(String value)
      Bean property setter: type.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Possible values include:
      • "object"
      • "string"
      • "number"
      • "integer"
      • "boolean"
      • "array"
      • "file"
      Returns:
      This object
    • setUniqueItems

      Bean property setter: uniqueItems.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setWriteOnly

      Bean property setter: WriteOnly.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • setXml

      public SchemaInfo setXml(Xml value)
      Bean property setter: xml.
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • strict

      public SchemaInfo strict()
      Description copied from class: OpenApiElement
      Sets strict mode on this bean.
      Overrides:
      strict in class OpenApiElement
      Returns:
      This object
    • strict

      public SchemaInfo strict(Object value)
      Description copied from class: OpenApiElement
      Sets strict mode on this bean.
      Overrides:
      strict in class OpenApiElement
      Parameters:
      value - The new value for this property.
      Non-boolean values will be converted to boolean using Boolean.valueOf(value.toString()).
      Can be null (interpreted as false).
      Returns:
      This object