Package io.muserver.openapi
Class SchemaObjectBuilder
- java.lang.Object
-
- io.muserver.openapi.SchemaObjectBuilder
-
public class SchemaObjectBuilder extends java.lang.ObjectThe 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.ObjectadditionalProperties()java.util.List<SchemaObject>allOf()java.util.List<SchemaObject>anyOf()SchemaObjectbuild()java.lang.ObjectdefaultValue()java.lang.Booleandeprecated()java.lang.Stringdescription()DiscriminatorObjectdiscriminator()java.util.List<java.lang.Object>enumValue()java.lang.Objectexample()java.lang.BooleanexclusiveMaximum()java.lang.BooleanexclusiveMinimum()ExternalDocumentationObjectexternalDocs()java.lang.Stringformat()SchemaObjectitems()java.lang.Doublemaximum()java.lang.IntegermaxItems()java.lang.IntegermaxLength()java.lang.IntegermaxProperties()java.lang.Doubleminimum()java.lang.IntegerminItems()java.lang.IntegerminLength()java.lang.IntegerminProperties()java.lang.DoublemultipleOf()java.util.List<SchemaObject>not()java.lang.Booleannullable()java.util.List<SchemaObject>oneOf()java.util.regex.Patternpattern()java.util.Map<java.lang.String,SchemaObject>properties()java.lang.BooleanreadOnly()java.util.List<java.lang.String>required()static SchemaObjectBuilderschemaObject()Creates a builder for aSchemaObjectstatic SchemaObjectBuilderschemaObjectFrom(java.lang.Class<?> from)Creates a builder for aSchemaObjectwith the type and format based on the given classstatic SchemaObjectBuilderschemaObjectFrom(java.lang.Class<?> from, java.lang.reflect.Type parameterizedType, boolean required)Creates a builder for aSchemaObjectwith the type and format based on the given class and generic type.java.lang.Stringtitle()java.lang.StringtoString()java.lang.Stringtype()java.lang.BooleanuniqueItems()SchemaObjectBuilderwithAdditionalProperties(java.lang.Object additionalProperties)Defines how properties not covered bywithProperties(Map)are handled when the type isobjectSchemaObjectBuilderwithAllOf(java.util.List<SchemaObject> allOf)SchemaObjectBuilderwithAnyOf(java.util.List<SchemaObject> anyOf)Forces a value to be any of a number of different schemasSchemaObjectBuilderwithDefaultValue(java.lang.Object defaultValue)SchemaObjectBuilderwithDeprecated(java.lang.Boolean deprecated)SchemaObjectBuilderwithDescription(java.lang.String description)SchemaObjectBuilderwithDiscriminator(DiscriminatorObject discriminator)SchemaObjectBuilderwithEnumValue(java.util.List<java.lang.Object> enumValue)SchemaObjectBuilderwithExample(java.lang.Object example)SchemaObjectBuilderwithExclusiveMaximum(java.lang.Boolean exclusiveMaximum)SchemaObjectBuilderwithExclusiveMinimum(java.lang.Boolean exclusiveMinimum)SchemaObjectBuilderwithExternalDocs(ExternalDocumentationObject externalDocs)SchemaObjectBuilderwithFormat(java.lang.String format)This is used to further specify the format ofstringtypes.SchemaObjectBuilderwithItems(SchemaObject items)SchemaObjectBuilderwithMaximum(java.lang.Double maximum)SchemaObjectBuilderwithMaxItems(java.lang.Integer maxItems)SchemaObjectBuilderwithMaxLength(java.lang.Integer maxLength)SchemaObjectBuilderwithMaxProperties(java.lang.Integer maxProperties)SchemaObjectBuilderwithMinimum(java.lang.Double minimum)SchemaObjectBuilderwithMinItems(java.lang.Integer minItems)SchemaObjectBuilderwithMinLength(java.lang.Integer minLength)SchemaObjectBuilderwithMinProperties(java.lang.Integer minProperties)SchemaObjectBuilderwithMultipleOf(java.lang.Double multipleOf)Restricts numeric values to be a multiple of the given valueSchemaObjectBuilderwithNot(java.util.List<SchemaObject> not)SchemaObjectBuilderwithNullable(java.lang.Boolean nullable)SchemaObjectBuilderwithOneOf(java.util.List<SchemaObject> oneOf)Forces a value to be one of several different schemasSchemaObjectBuilderwithPattern(java.util.regex.Pattern pattern)SchemaObjectBuilderwithProperties(java.util.Map<java.lang.String,SchemaObject> properties)SchemaObjectBuilderwithReadOnly(java.lang.Boolean readOnly)SchemaObjectBuilderwithRequired(java.util.List<java.lang.String> required)SchemaObjectBuilderwithTitle(java.lang.String title)SchemaObjectBuilderwithType(java.lang.String type)SchemaObjectBuilderwithUniqueItems(java.lang.Boolean uniqueItems)SchemaObjectBuilderwithWriteOnly(java.lang.Boolean writeOnly)SchemaObjectBuilderwithXml(XmlObject xml)java.lang.BooleanwriteOnly()XmlObjectxml()
-
-
-
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-trueif the value specified withwithMaximum(Double)is exclusive; otherwise the defaultfalsemeans 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-trueif the value specified withwithMinimum(Double)is exclusive; otherwise the defaultfalsemeans 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,arrayorobject- 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 anobjecttype- 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- Iffalsethen 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 ofstringtypes.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-12string date-time the date-time notation as defined by RFC 3339, section 5.6, for example, 2021-02-12T15:33:28Zstring 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-822258e8ffadstring 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- Atruevalue adds"null"to the allowed type specified by thetypekeyword, only iftypeis explicitly defined within the same Schema Object. Other Schema Object constraints retain their defined behavior, and therefore may disallow the use ofnullas a value. Afalsevalue leaves the specified or defaulttypeunmodified. 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 asreadOnlybeingtrueand is in therequiredlist, therequiredwill take effect on the response only. A property MUST NOT be marked as bothreadOnlyandwriteOnlybeingtrue. 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 aswriteOnlybeingtrueand is in therequiredlist, therequiredwill take effect on the request only. A property MUST NOT be marked as bothreadOnlyandwriteOnlybeingtrue. 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 aSchemaObjectwith the type and format based on the given class- Parameters:
from- Type type to build from, e.g. if the type isString.classthen thetypewill 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 aSchemaObjectwith 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.classthen thetypewill 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:
toStringin classjava.lang.Object
-
-