Class SchemaObjectBuilder


  • public class SchemaObjectBuilder
    extends java.lang.Object

    The Schema Object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. This object is an extended subset of the JSON Schema Specification Wright Draft 00.

    For more information about the properties, see JSON Schema Core and JSON Schema Validation. Unless stated otherwise, the property definitions follow the JSON Schema.

    • Constructor Detail

      • SchemaObjectBuilder

        public SchemaObjectBuilder()
    • Method Detail

      • withTitle

        public SchemaObjectBuilder withTitle​(java.lang.String title)
        Parameters:
        title - the name of this object type
        Returns:
        this builder
      • withMultipleOf

        public SchemaObjectBuilder withMultipleOf​(java.lang.Double multipleOf)
        Restricts numeric values to be a multiple of the given value
        Parameters:
        multipleOf - the multiple
        Returns:
        this builder
      • withExclusiveMaximum

        public SchemaObjectBuilder withExclusiveMaximum​(java.lang.Boolean exclusiveMaximum)
        Parameters:
        exclusiveMaximum - true if the value specified with withMaximum(Double) is exclusive; otherwise the default false means it is an inclusive number.
        Returns:
        this builder
        See Also:
        withMaximum(Double)
      • withExclusiveMinimum

        public SchemaObjectBuilder withExclusiveMinimum​(java.lang.Boolean exclusiveMinimum)
        Parameters:
        exclusiveMinimum - true if the value specified with withMinimum(Double) is exclusive; otherwise the default false means it is an inclusive number.
        Returns:
        this builder
        See Also:
        withMinimum(Double)
      • withMaxLength

        public SchemaObjectBuilder withMaxLength​(java.lang.Integer maxLength)
        Parameters:
        maxLength - the maximum allowed length of string values
        Returns:
        this builder
      • withMinLength

        public SchemaObjectBuilder withMinLength​(java.lang.Integer minLength)
        Parameters:
        minLength - the minimum allowed length of string values
        Returns:
        this builder
      • withPattern

        public SchemaObjectBuilder withPattern​(java.util.regex.Pattern pattern)
        Parameters:
        pattern - a regular expression that string values must match against
        Returns:
        this builder
      • withMaxItems

        public SchemaObjectBuilder withMaxItems​(java.lang.Integer maxItems)
        Parameters:
        maxItems - the maximum number of items allowed in an array value
        Returns:
        this builder
      • withMinItems

        public SchemaObjectBuilder withMinItems​(java.lang.Integer minItems)
        Parameters:
        minItems - the minimum number of items allowed in an array value
        Returns:
        this builder
      • withUniqueItems

        public SchemaObjectBuilder withUniqueItems​(java.lang.Boolean uniqueItems)
        Parameters:
        uniqueItems - if true, then all items in an array value must be unique
        Returns:
        this builder
      • withMaxProperties

        public SchemaObjectBuilder withMaxProperties​(java.lang.Integer maxProperties)
        Parameters:
        maxProperties - the maximum number of properties allowed for an "object" type.
        Returns:
        this builder
      • withMinProperties

        public SchemaObjectBuilder withMinProperties​(java.lang.Integer minProperties)
        Parameters:
        minProperties - the minimum number of properties allowed for an "object" type.
        Returns:
        this builder
      • withRequired

        public SchemaObjectBuilder withRequired​(java.util.List<java.lang.String> required)
        Parameters:
        required - the list of properties that are required to have a value for an "object" type.
        Returns:
        this builder
      • withEnumValue

        public SchemaObjectBuilder withEnumValue​(java.util.List<java.lang.Object> enumValue)
        Parameters:
        enumValue - the allowed values for an "enum" type
        Returns:
        this builder
      • withType

        public SchemaObjectBuilder withType​(java.lang.String type)
        Parameters:
        type - the type of this schema object. One of string, number, integer, boolean, array or object
        Returns:
        this builder
      • withAllOf

        public SchemaObjectBuilder withAllOf​(java.util.List<SchemaObject> allOf)
        Parameters:
        allOf - the schemas that the value must match
        Returns:
        this builder
      • withOneOf

        public SchemaObjectBuilder withOneOf​(java.util.List<SchemaObject> oneOf)
        Forces a value to be one of several different schemas
        Parameters:
        oneOf - the schemas the validate against
        Returns:
        this builder
        See Also:
        withAnyOf(List)
      • withAnyOf

        public SchemaObjectBuilder withAnyOf​(java.util.List<SchemaObject> anyOf)
        Forces a value to be any of a number of different schemas
        Parameters:
        anyOf - the schemas the validate against
        Returns:
        this builder
        See Also:
        withOneOf(List)
      • withNot

        public SchemaObjectBuilder withNot​(java.util.List<SchemaObject> not)
        Parameters:
        not - schemas the value must not validate against
        Returns:
        this builder
      • withItems

        public SchemaObjectBuilder withItems​(SchemaObject items)
        Parameters:
        items - the schema that items in an array object must validate against
        Returns:
        this builder
      • withProperties

        public SchemaObjectBuilder withProperties​(java.util.Map<java.lang.String,​SchemaObject> properties)
        Parameters:
        properties - the schema objects of each property for an object type
        Returns:
        this builder
      • withAdditionalProperties

        public SchemaObjectBuilder withAdditionalProperties​(java.lang.Object additionalProperties)
        Defines how properties not covered by withProperties(Map) are handled when the type is object
        Parameters:
        additionalProperties - If false then extra properties are not allowed. If it is a schema object then any extra properties must validate against this schema.
        Returns:
        this builder
      • withDescription

        public SchemaObjectBuilder withDescription​(java.lang.String description)
        Parameters:
        description - a description of this type
        Returns:
        this builder
        See Also:
        withTitle(String)
      • withFormat

        public SchemaObjectBuilder withFormat​(java.lang.String format)
        This is used to further specify the format of string types.
        Example type/format combos
        Type Format Description
        number Any numbers.
        number float Floating-point numbers.
        number double Floating-point numbers with double precision.
        integer Integer numbers.
        integer in32 Signed 32-bit integers (commonly used integer type).
        integer int64 Signed 64-bit integers (long type).
        string date full-date notation as defined by RFC 3339, section 5.6, for example, 2021-02-12
        string date-time the date-time notation as defined by RFC 3339, section 5.6, for example, 2021-02-12T15:33:28Z
        string password a hint to UIs to mask the input
        string byte base64-encoded characters, for example, U3dhZ2dlciByb2Nrcw==
        string binary binary data, used to describe files (not text)
        string email email addresses
        string uuid UUIDs such as 93d35de9-0083-4765-8b60-822258e8ffad
        string uri URIs, for example https://muserver.io/
        string hostname A server hostname
        string ipv4 An IP4 address
        string ipv6 An IP6 address

        Custom formats may be specified too.

        Parameters:
        format - the format of the type specified by withType(String)
        Returns:
        this builder
      • withDefaultValue

        public SchemaObjectBuilder withDefaultValue​(java.lang.Object defaultValue)
        Parameters:
        defaultValue - The default value to use when none is specified
        Returns:
        this builder
      • withNullable

        public SchemaObjectBuilder withNullable​(java.lang.Boolean nullable)
        Parameters:
        nullable - A true value adds "null" to the allowed type specified by the type keyword, only if type is explicitly defined within the same Schema Object. Other Schema Object constraints retain their defined behavior, and therefore may disallow the use of null as a value. A false value leaves the specified or default type unmodified. The default value is false.
        Returns:
        The current builder
      • withDiscriminator

        public SchemaObjectBuilder withDiscriminator​(DiscriminatorObject discriminator)
        Parameters:
        discriminator - Adds support for polymorphism. The discriminator is an object name that is used to differentiate between other schemas which may satisfy the payload description.
        Returns:
        The current builder
      • withReadOnly

        public SchemaObjectBuilder withReadOnly​(java.lang.Boolean readOnly)
        Parameters:
        readOnly - Relevant only for Schema "properties" definitions. Declares the property as "read only". This means that it MAY be sent as part of a response but SHOULD NOT be sent as part of the request. If the property is marked as readOnly being true and is in the required list, the required will take effect on the response only. A property MUST NOT be marked as both readOnly and writeOnly being true. Default value is false.
        Returns:
        The current builder
      • withWriteOnly

        public SchemaObjectBuilder withWriteOnly​(java.lang.Boolean writeOnly)
        Parameters:
        writeOnly - Relevant only for Schema "properties" definitions. Declares the property as "write only". Therefore, it MAY be sent as part of a request but SHOULD NOT be sent as part of the response. If the property is marked as writeOnly being true and is in the required list, the required will take effect on the request only. A property MUST NOT be marked as both readOnly and writeOnly being true. Default value is false.
        Returns:
        The current builder
      • withXml

        public SchemaObjectBuilder withXml​(XmlObject xml)
        Parameters:
        xml - This MAY be used only on properties schemas. It has no effect on root schemas. Adds additional metadata to describe the XML representation of this property.
        Returns:
        The current builder
      • withExample

        public SchemaObjectBuilder withExample​(java.lang.Object example)
        Parameters:
        example - A free-form property to include an example of an instance for this schema. To represent examples that cannot be naturally represented in JSON or YAML, a string value can be used to contain the example with escaping where necessary.
        Returns:
        The current builder
      • withDeprecated

        public SchemaObjectBuilder withDeprecated​(java.lang.Boolean deprecated)
        Parameters:
        deprecated - Specifies that a schema is deprecated and SHOULD be transitioned out of usage. Default value is false.
        Returns:
        The current builder
      • schemaObjectFrom

        public static SchemaObjectBuilder schemaObjectFrom​(java.lang.Class<?> from)
        Creates a builder for a SchemaObject with the type and format based on the given class
        Parameters:
        from - Type type to build from, e.g. if the type is String.class then the type will be set as string.
        Returns:
        A new builder
      • schemaObjectFrom

        public static SchemaObjectBuilder schemaObjectFrom​(java.lang.Class<?> from,
                                                           java.lang.reflect.Type parameterizedType,
                                                           boolean required)
        Creates a builder for a SchemaObject with the type and format based on the given class and generic type.
        Parameters:
        from - Type type to build from, e.g. if the type is List.class then the type will be set as array.
        parameterizedType - The generic type of the class, e.g. a String if the type is List<String>
        required - True if it's a required value
        Returns:
        A new builder
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object