Package io.muserver.openapi
Class SchemaObjectBuilder
- java.lang.Object
-
- io.muserver.openapi.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 Summary
Constructors Constructor Description SchemaObjectBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
additionalProperties()
java.util.List<SchemaObject>
allOf()
java.util.List<SchemaObject>
anyOf()
SchemaObject
build()
java.lang.Object
defaultValue()
java.lang.Boolean
deprecated()
java.lang.String
description()
DiscriminatorObject
discriminator()
java.util.List<java.lang.Object>
enumValue()
java.lang.Object
example()
java.lang.Boolean
exclusiveMaximum()
java.lang.Boolean
exclusiveMinimum()
ExternalDocumentationObject
externalDocs()
java.lang.String
format()
SchemaObject
items()
java.lang.Double
maximum()
java.lang.Integer
maxItems()
java.lang.Integer
maxLength()
java.lang.Integer
maxProperties()
java.lang.Double
minimum()
java.lang.Integer
minItems()
java.lang.Integer
minLength()
java.lang.Integer
minProperties()
java.lang.Double
multipleOf()
java.util.List<SchemaObject>
not()
java.lang.Boolean
nullable()
java.util.List<SchemaObject>
oneOf()
java.util.regex.Pattern
pattern()
java.util.Map<java.lang.String,SchemaObject>
properties()
java.lang.Boolean
readOnly()
java.util.List<java.lang.String>
required()
static SchemaObjectBuilder
schemaObject()
Creates a builder for aSchemaObject
static SchemaObjectBuilder
schemaObjectFrom(java.lang.Class<?> from)
Creates a builder for aSchemaObject
with the type and format based on the given classstatic SchemaObjectBuilder
schemaObjectFrom(java.lang.Class<?> from, java.lang.reflect.Type parameterizedType, boolean required)
Creates a builder for aSchemaObject
with the type and format based on the given class and generic type.java.lang.String
title()
java.lang.String
toString()
java.lang.String
type()
java.lang.Boolean
uniqueItems()
SchemaObjectBuilder
withAdditionalProperties(java.lang.Object additionalProperties)
Defines how properties not covered bywithProperties(Map)
are handled when the type isobject
SchemaObjectBuilder
withAllOf(java.util.List<SchemaObject> allOf)
SchemaObjectBuilder
withAnyOf(java.util.List<SchemaObject> anyOf)
Forces a value to be any of a number of different schemasSchemaObjectBuilder
withDefaultValue(java.lang.Object defaultValue)
SchemaObjectBuilder
withDeprecated(java.lang.Boolean deprecated)
SchemaObjectBuilder
withDescription(java.lang.String description)
SchemaObjectBuilder
withDiscriminator(DiscriminatorObject discriminator)
SchemaObjectBuilder
withEnumValue(java.util.List<java.lang.Object> enumValue)
SchemaObjectBuilder
withExample(java.lang.Object example)
SchemaObjectBuilder
withExclusiveMaximum(java.lang.Boolean exclusiveMaximum)
SchemaObjectBuilder
withExclusiveMinimum(java.lang.Boolean exclusiveMinimum)
SchemaObjectBuilder
withExternalDocs(ExternalDocumentationObject externalDocs)
SchemaObjectBuilder
withFormat(java.lang.String format)
This is used to further specify the format ofstring
types.SchemaObjectBuilder
withItems(SchemaObject items)
SchemaObjectBuilder
withMaximum(java.lang.Double maximum)
SchemaObjectBuilder
withMaxItems(java.lang.Integer maxItems)
SchemaObjectBuilder
withMaxLength(java.lang.Integer maxLength)
SchemaObjectBuilder
withMaxProperties(java.lang.Integer maxProperties)
SchemaObjectBuilder
withMinimum(java.lang.Double minimum)
SchemaObjectBuilder
withMinItems(java.lang.Integer minItems)
SchemaObjectBuilder
withMinLength(java.lang.Integer minLength)
SchemaObjectBuilder
withMinProperties(java.lang.Integer minProperties)
SchemaObjectBuilder
withMultipleOf(java.lang.Double multipleOf)
Restricts numeric values to be a multiple of the given valueSchemaObjectBuilder
withNot(java.util.List<SchemaObject> not)
SchemaObjectBuilder
withNullable(java.lang.Boolean nullable)
SchemaObjectBuilder
withOneOf(java.util.List<SchemaObject> oneOf)
Forces a value to be one of several different schemasSchemaObjectBuilder
withPattern(java.util.regex.Pattern pattern)
SchemaObjectBuilder
withProperties(java.util.Map<java.lang.String,SchemaObject> properties)
SchemaObjectBuilder
withReadOnly(java.lang.Boolean readOnly)
SchemaObjectBuilder
withRequired(java.util.List<java.lang.String> required)
SchemaObjectBuilder
withTitle(java.lang.String title)
SchemaObjectBuilder
withType(java.lang.String type)
SchemaObjectBuilder
withUniqueItems(java.lang.Boolean uniqueItems)
SchemaObjectBuilder
withWriteOnly(java.lang.Boolean writeOnly)
SchemaObjectBuilder
withXml(XmlObject xml)
java.lang.Boolean
writeOnly()
XmlObject
xml()
-
-
-
Method Detail
-
title
public java.lang.String title()
- Returns:
- the value set by
withTitle(java.lang.String)
-
multipleOf
public java.lang.Double multipleOf()
- Returns:
- the value set by
withMultipleOf(java.lang.Double)
-
maximum
public java.lang.Double maximum()
- Returns:
- the value set by
withMaximum(java.lang.Double)
-
exclusiveMaximum
public java.lang.Boolean exclusiveMaximum()
- Returns:
- the value set by
withExclusiveMaximum(java.lang.Boolean)
-
minimum
public java.lang.Double minimum()
- Returns:
- the value set by
withMinimum(java.lang.Double)
-
exclusiveMinimum
public java.lang.Boolean exclusiveMinimum()
- Returns:
- the value set by
withExclusiveMinimum(java.lang.Boolean)
-
maxLength
public java.lang.Integer maxLength()
- Returns:
- the value set by
withMaxLength(java.lang.Integer)
-
minLength
public java.lang.Integer minLength()
- Returns:
- the value set by
withMinLength(java.lang.Integer)
-
pattern
public java.util.regex.Pattern pattern()
- Returns:
- the value set by
withPattern(java.util.regex.Pattern)
-
maxItems
public java.lang.Integer maxItems()
- Returns:
- the value set by
withMaxItems(java.lang.Integer)
-
minItems
public java.lang.Integer minItems()
- Returns:
- the value set by
withMinItems(java.lang.Integer)
-
uniqueItems
public java.lang.Boolean uniqueItems()
- Returns:
- the value set by
withUniqueItems(java.lang.Boolean)
-
maxProperties
public java.lang.Integer maxProperties()
- Returns:
- the value set by
withMaxProperties(java.lang.Integer)
-
minProperties
public java.lang.Integer minProperties()
- Returns:
- the value set by
withMinProperties(java.lang.Integer)
-
required
public java.util.List<java.lang.String> required()
- Returns:
- the value set by
withRequired(java.util.List<java.lang.String>)
-
enumValue
public java.util.List<java.lang.Object> enumValue()
- Returns:
- the value set by
withEnumValue(java.util.List<java.lang.Object>)
-
type
public java.lang.String type()
- Returns:
- the value set by
withType(java.lang.String)
-
allOf
public java.util.List<SchemaObject> allOf()
- Returns:
- the value set by
withAllOf(java.util.List<io.muserver.openapi.SchemaObject>)
-
oneOf
public java.util.List<SchemaObject> oneOf()
- Returns:
- the value set by
withOneOf(java.util.List<io.muserver.openapi.SchemaObject>)
-
anyOf
public java.util.List<SchemaObject> anyOf()
- Returns:
- the value set by
withAnyOf(java.util.List<io.muserver.openapi.SchemaObject>)
-
not
public java.util.List<SchemaObject> not()
- Returns:
- the value set by
withNot(java.util.List<io.muserver.openapi.SchemaObject>)
-
items
public SchemaObject items()
- Returns:
- the value set by
withItems(io.muserver.openapi.SchemaObject)
-
properties
public java.util.Map<java.lang.String,SchemaObject> properties()
- Returns:
- the value set by
withProperties(java.util.Map<java.lang.String, io.muserver.openapi.SchemaObject>)
-
additionalProperties
public java.lang.Object additionalProperties()
- Returns:
- the value set by
withAdditionalProperties(java.lang.Object)
-
description
public java.lang.String description()
- Returns:
- the value set by
withDescription(java.lang.String)
-
format
public java.lang.String format()
- Returns:
- the value set by
withFormat(java.lang.String)
-
defaultValue
public java.lang.Object defaultValue()
- Returns:
- the value set by
withDefaultValue(java.lang.Object)
-
nullable
public java.lang.Boolean nullable()
- Returns:
- the value set by
withNullable(java.lang.Boolean)
-
discriminator
public DiscriminatorObject discriminator()
- Returns:
- the value set by
withDiscriminator(io.muserver.openapi.DiscriminatorObject)
-
readOnly
public java.lang.Boolean readOnly()
- Returns:
- the value set by
withReadOnly(java.lang.Boolean)
-
writeOnly
public java.lang.Boolean writeOnly()
- Returns:
- the value set by
withWriteOnly(java.lang.Boolean)
-
xml
public XmlObject xml()
- Returns:
- the value set by
withXml(io.muserver.openapi.XmlObject)
-
externalDocs
public ExternalDocumentationObject externalDocs()
- Returns:
- the value set by
withExternalDocs(io.muserver.openapi.ExternalDocumentationObject)
-
example
public java.lang.Object example()
- Returns:
- the value set by
withExample(java.lang.Object)
-
deprecated
public java.lang.Boolean deprecated()
- Returns:
- the value set by
withDeprecated(java.lang.Boolean)
-
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
-
withMaximum
public SchemaObjectBuilder withMaximum(java.lang.Double maximum)
- Parameters:
maximum
- The maximum allowed value for numeric values- Returns:
- this builder
- See Also:
withExclusiveMaximum(Boolean)
-
withExclusiveMaximum
public SchemaObjectBuilder withExclusiveMaximum(java.lang.Boolean exclusiveMaximum)
- Parameters:
exclusiveMaximum
-true
if the value specified withwithMaximum(Double)
is exclusive; otherwise the defaultfalse
means it is an inclusive number.- Returns:
- this builder
- See Also:
withMaximum(Double)
-
withMinimum
public SchemaObjectBuilder withMinimum(java.lang.Double minimum)
- Parameters:
minimum
- The minimum allowed value for numeric values- Returns:
- this builder
- See Also:
withExclusiveMinimum(Boolean)
-
withExclusiveMinimum
public SchemaObjectBuilder withExclusiveMinimum(java.lang.Boolean exclusiveMinimum)
- Parameters:
exclusiveMinimum
-true
if the value specified withwithMinimum(Double)
is exclusive; otherwise the defaultfalse
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 ofstring
,number
,integer
,boolean
,array
orobject
- 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 anobject
type- Returns:
- this builder
-
withAdditionalProperties
public SchemaObjectBuilder withAdditionalProperties(java.lang.Object additionalProperties)
Defines how properties not covered bywithProperties(Map)
are handled when the type isobject
- Parameters:
additionalProperties
- Iffalse
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 ofstring
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 bywithType(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
- Atrue
value adds"null"
to the allowed type specified by thetype
keyword, only iftype
is explicitly defined within the same Schema Object. Other Schema Object constraints retain their defined behavior, and therefore may disallow the use ofnull
as a value. Afalse
value leaves the specified or defaulttype
unmodified. The default value isfalse
.- 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 asreadOnly
beingtrue
and is in therequired
list, therequired
will take effect on the response only. A property MUST NOT be marked as bothreadOnly
andwriteOnly
beingtrue
. Default value isfalse
.- 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 aswriteOnly
beingtrue
and is in therequired
list, therequired
will take effect on the request only. A property MUST NOT be marked as bothreadOnly
andwriteOnly
beingtrue
. Default value isfalse
.- 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
-
withExternalDocs
public SchemaObjectBuilder withExternalDocs(ExternalDocumentationObject externalDocs)
- Parameters:
externalDocs
- Additional external documentation for this schema.- 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 isfalse
.- Returns:
- The current builder
-
build
public SchemaObject build()
- Returns:
- A new object
-
schemaObject
public static SchemaObjectBuilder schemaObject()
Creates a builder for aSchemaObject
- Returns:
- A new builder
-
schemaObjectFrom
public static SchemaObjectBuilder schemaObjectFrom(java.lang.Class<?> from)
Creates a builder for aSchemaObject
with the type and format based on the given class- Parameters:
from
- Type type to build from, e.g. if the type isString.class
then thetype
will be set asstring
.- Returns:
- A new builder
-
schemaObjectFrom
public static SchemaObjectBuilder schemaObjectFrom(java.lang.Class<?> from, java.lang.reflect.Type parameterizedType, boolean required)
Creates a builder for aSchemaObject
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 isList.class
then thetype
will be set asarray
.parameterizedType
- The generic type of the class, e.g. a String if the type isList<String>
required
- True if it's a required value- Returns:
- A new builder
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-