Top Description Inners Methods
org.eclipse.microprofile.openapi.annotations.media

public @Interface Schema

extends Annotation
Annotations
@Target:FIELD, METHOD, PARAMETER, TYPE
@Retention:RUNTIME
@Inherited
Imports
java.lang.annotation.ElementType, .Inherited, .Retention, .RetentionPolicy, .Target, org.eclipse.microprofile.openapi.annotations.ExternalDocumentation, org.eclipse.microprofile.openapi.annotations.enums.SchemaType, org.eclipse.microprofile.openapi.annotations.extensions.Extension

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 draft specification 2020-12.

Defining subschemas

Some of the parameters on this annotation correspond to parts of an OpenAPI document where a subschema is expected, for example allOf(), contains() and propertyNames(). Due to limitations in the Java language, we can't use a second @Schema annotation, so instead we allow a class to be provided. A schema will be generated from that class by introspecting its annotations, methods and fields.

In addition, several special values can be used:

See Also
OpenAPI Specification Schema Object

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Schema.False

Marker class to indicate that a boolean false schema should be used.

public static class
Schema.True

Marker class to indicate that a boolean true schema should be used.

Method Summary

Modifier and TypeMethod and Description
public Class<?>

Returns:

a class that describes the allowable schema for additional properties not explicitly defined
additionalProperties
()

Provides a Java class as implementation for additional properties that may be present in instances of this schema.

public Class<?>[]

Returns:

the list of classes to match
allOf
()

Provides an array of java class implementations which can be used to describe multiple acceptable schemas.

public Class<?>[]

Returns:

the list of possible class matches
anyOf
()

Provides an array of java class implementations which can be used to describe multiple acceptable schemas.

public String

Returns:

the comment
comment
()

A comment to be included in the schema

This value is set in the $comment property of the schema object

public String

Returns:

the value which the instance must be equal to, expressed according to the type of the schema
constValue
()

Requires that the instance must be a specific value.

public Class<?>

Returns:

a class used to create a schema which at least one element of an array instance must validate against
contains
()

A schema which at least one element of an array instance must validate against.

public String

Returns:

the encoding
contentEncoding
()

The encoding used to allow binary data to be stored in a string.

public String

Returns:

the media type of the data in a string
contentMediaType
()

The media type of the data in a string.

public Class<?>

Returns:

a class used to create a schema used to validate the data in a string
contentSchema
()

The schema that data in a string must validate against.

public String

Returns:

the default value of this schema
defaultValue
()

Provides a default value.

public DependentRequired[]

Returns:

the properties required if certain other properties are present
dependentRequired
()

Specifies that certain properties must be present if other properties are present.

public DependentSchema[]

Returns:

an array of DependentSchema entries
dependentSchemas
()

Schemas which an instance must validate against if the instance has certain properties.

public boolean

Returns:

whether or not this schema is deprecated
deprecated
()

Specifies that a schema is deprecated and SHOULD be transitioned out of usage.

public String

Returns:

this schema's description
description
()

A description of the schema.

public DiscriminatorMapping[]

Returns:

the discriminator mappings for this schema
discriminatorMapping
()

An array of discriminator mappings.

public String

Returns:

the discriminator property
discriminatorProperty
()

Provides a discriminator property value.

public Class<?>

Returns:

a class used to create the else schema
elseSchema
()

A class used to create a schema that an instance must validate against if it does not validate against the if schema.

public String[]

Returns:

a list of allowed schema values
enumeration
()

Provides a list of enum values.

public String

Returns:

an example of this schema
example
()
Deprecated since 4.0. use examples()

A free-form property to include an example of an instance for this schema.

public String[]

Returns:

an array of examples of this schema
examples
()

A free-form property to include examples of an instance for this schema.

public boolean

Returns:

the exclusive maximum value for this schema
exclusiveMaximum
()

If true, makes the maximum value exclusive, or a less-than criteria.

public boolean

Returns:

the exclusive minimum value for this schema
exclusiveMinimum
()

If true, makes the minimum value exclusive, or a greater-than criteria.

public Extension[]

Returns:

array of extensions
extensions
()

List of extensions to be added to the Schema model corresponding to the containing annotation.

public ExternalDocumentation

Returns:

additional schema documentation
externalDocs
()

Additional external documentation for this schema.

public String

Returns:

this schema's format
format
()

Provides an optional override for the format.

public boolean

Returns:

whether or not this schema is hidden
hidden
()

Allows schema to be marked as hidden.

public Class<?>

Returns:

a class used to create the if schema
ifSchema
()

A class used to create a schema used to control conditional evaluation.

public Class<?>

Returns:

a class that implements this schema
implementation
()

Provides a java class as implementation for this schema.

public int

Returns:

the maximum number of elements which may validate against the contains() schema
maxContains
()

Specifies the maximum number of elements which may validate against the contains() schema.

public String

Returns:

the maximum value for this schema
maximum
()

Sets the maximum numeric value for a property.

public int

Returns:

the maximum number of items in this array
maxItems
()

Only applicable if type=array.

public int

Returns:

the maximum length of this schema
maxLength
()

Sets the maximum length of a string value.

public int

Returns:

the maximum number of properties for this schema
maxProperties
()

Constrains the number of arbitrary properties when additionalProperties is defined.

public int

Returns:

the minimum number of elements which must validate against the contains() schema
minContains
()

Specifies the minimum number of elements which must validate against the contains() schema.

public String

Returns:

the minimum value for this schema
minimum
()

Sets the minimum numeric value for a property.

public int

Returns:

the minimum number of items in this array
minItems
()

Only applicable if type=array.

public int

Returns:

the minimum length of this schema
minLength
()

Sets the minimum length of a string value.

public int

Returns:

the minimum number of properties for this schema
minProperties
()

Constrains the number of arbitrary properties when additionalProperties is defined.

public double

Returns:

the multiplier constraint of the schema
multipleOf
()

Constrains a value such that when divided by the multipleOf, the result must be an integer.

public String

Returns:

the name of the schema
name
()

The name of the schema or property.

public Class<?>

Returns:

a class with disallowed properties
not
()

Provides a java class to be used to disallow matching properties.

public boolean

Returns:

whether or not this schema is nullable
nullable
()

Allows sending a null value for the defined schema.

public Class<?>[]

Returns:

the list of possible classes for a single match
oneOf
()

Provides an array of java class implementations which can be used to describe multiple acceptable schemas.

public String

Returns:

the ECMA-262 regular expression to match against
pattern
()

A regular expression that the value must satisfy.

public PatternProperty[]

Returns:

a mapping from regular expressions to schemas
patternProperties
()

Applies subschemas against properties matched by regular expressions.

public Class<?>[]

Returns:

an array of classes used to create an array of schemas used to validate the leading elements of an array instance
prefixItems
()

Schemas which the leading elements of an array instance must validate against.

public SchemaProperty[]

Returns:

a list of defined properties
properties
()

Provides a list of properties present in this schema.

public Class<?>

Returns:

a schema that property names must validate against
propertyNames
()

A schema which the names of properties of an object instance must validate against.

public boolean

Returns:

whether or not this schema is read only
readOnly
()

Declares the property as "read only".

public String

Returns:

a reference to a schema definition
ref
()

Reference value to a Schema definition.

public boolean

Returns:

whether or not this schema is required
required
()

Specifies whether the annotated item is required or not.

public String[]

Returns:

the list of required schema properties
requiredProperties
()

Allows multiple properties in an object to be marked as required.

public Class<?>

Returns:

a class used to create the then schema
thenSchema
()

A class used to create a schema that an instance must validate against if it validates against the if schema.

public String

Returns:

the title of the schema
title
()

A title to explain the purpose of the schema.

public SchemaType

Returns:

the type of this schema
type
()

Provides an override for the basic type of the schema.

public boolean

Returns:

whether the items in this array are unique
uniqueItems
()

Only applicable if type=array.

public boolean

Returns:

whether or not this schema is write only
writeOnly
()

Declares the property as "write only".

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

additionalPropertiesback to summary
public Class<?> additionalProperties()

Provides a Java class as implementation for additional properties that may be present in instances of this schema.

If no additional properties are allowed, the value of this property should be set to False.class which will be rendered as boolean false in the resulting OpenAPI document.

The default value Void.class will result in no additionalProperties attribute being generated in the resulting OpenAPI document. The effective value in that case is true per the OpenAPI specification.

Implementations MAY ignore this property if this schema's type is not OBJECT, either explicitly or as derived by the placement of the annotation.

Returns:Class<?>

a class that describes the allowable schema for additional properties not explicitly defined

Since
3.1
See Also
True, False
allOfback to summary
public Class<?>[] allOf()

Provides an array of java class implementations which can be used to describe multiple acceptable schemas. If all match, the schema will be considered valid.

Returns:Class<?>[]

the list of classes to match

anyOfback to summary
public Class<?>[] anyOf()

Provides an array of java class implementations which can be used to describe multiple acceptable schemas. If any match, the schema will be considered valid.

Returns:Class<?>[]

the list of possible class matches

commentback to summary
public String comment()

A comment to be included in the schema

This value is set in the $comment property of the schema object

Returns:String

the comment

Since
4.0
constValueback to summary
public String constValue()

Requires that the instance must be a specific value. No other values are permitted.

The value is parsed as JSON if the schema type is anything other than STRING.

Returns:String

the value which the instance must be equal to, expressed according to the type of the schema

Since
4.0
containsback to summary
public Class<?> contains()

A schema which at least one element of an array instance must validate against.

The class is used to create a schema. If the instance is an array, then at least one element of the array must validate against the schema.

Returns:Class<?>

a class used to create a schema which at least one element of an array instance must validate against

Since
4.0
contentEncodingback to summary
public String contentEncoding()

The encoding used to allow binary data to be stored in a string.

If the instance is a string, this property specifies that it contains binary data encoded as text using the specified encoding (e.g. base64).

Returns:String

the encoding

Since
4.0
contentMediaTypeback to summary
public String contentMediaType()

The media type of the data in a string.

If the instance is a string, this property specifies the media type of the data it contains. If contentEncoding() is also set, it specifies the media type of the decoded string.

Returns:String

the media type of the data in a string

Since
4.0
contentSchemaback to summary
public Class<?> contentSchema()

The schema that data in a string must validate against.

The class is used to create a schema. If the instance is a string and contentMediaType() is set, the data must validate against the schema when interpreted as the given media type.

Returns:Class<?>

a class used to create a schema used to validate the data in a string

Since
4.0
defaultValueback to summary
public String defaultValue()

Provides a default value. The default value represents what would be assumed by the consumer of the input as the value of the schema if one is not provided.

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

For example, if type is string, then default can be "foo" but cannot be 1.
Returns:String

the default value of this schema

dependentRequiredback to summary
public DependentRequired[] dependentRequired()

Specifies that certain properties must be present if other properties are present.

For each DependentRequired entry in the list, if the instance is an object and has a property named DependentRequired#name() then it must also have property named for each entry of DependentRequired#requires() to validate against this schema.

Returns:DependentRequired[]

the properties required if certain other properties are present

Since
4.0
dependentSchemasback to summary
public DependentSchema[] dependentSchemas()

Schemas which an instance must validate against if the instance has certain properties.

For each DependentSchema listed, if the instance is an object which has a property named name() then the instance must validate against the schema created from schema().

Returns:DependentSchema[]

an array of DependentSchema entries

Since
4.0
deprecatedback to summary
public boolean deprecated()

Specifies that a schema is deprecated and SHOULD be transitioned out of usage.

Returns:boolean

whether or not this schema is deprecated

descriptionback to summary
public String description()

A description of the schema.

Returns:String

this schema's description

discriminatorMappingback to summary
public DiscriminatorMapping[] discriminatorMapping()

An array of discriminator mappings.

Returns:DiscriminatorMapping[]

the discriminator mappings for this schema

discriminatorPropertyback to summary
public String discriminatorProperty()

Provides a discriminator property value. 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:String

the discriminator property

elseSchemaback to summary
public Class<?> elseSchema()

A class used to create a schema that an instance must validate against if it does not validate against the if schema.

Returns:Class<?>

a class used to create the else schema

Since
4.0
See Also
ifSchema(), thenSchema()
enumerationback to summary
public String[] enumeration()

Provides a list of enum values. Corresponds to the enum property in the OAS schema and the enumeration property in the schema model.

Returns:String[]

a list of allowed schema values

exampleback to summary
public String example()

Deprecated

since 4.0.

use examples()

A free-form property to include an example of an instance for this schema.

Returns:String

an example of this schema

Annotations
@Deprecated
since:4.0
examplesback to summary
public String[] examples()

A free-form property to include examples of an instance for this schema.

Each example SHOULD validate against this schema.

If the schema type() is STRING, the value will be interpreted as a literal string, otherwise it will be parsed as JSON.

Returns:String[]

an array of examples of this schema

Since
4.0
exclusiveMaximumback to summary
public boolean exclusiveMaximum()

If true, makes the maximum value exclusive, or a less-than criteria.

Returns:boolean

the exclusive maximum value for this schema

exclusiveMinimumback to summary
public boolean exclusiveMinimum()

If true, makes the minimum value exclusive, or a greater-than criteria.

Returns:boolean

the exclusive minimum value for this schema

extensionsback to summary
public Extension[] extensions()

List of extensions to be added to the Schema model corresponding to the containing annotation.

Returns:Extension[]

array of extensions

Since
3.1
externalDocsback to summary
public ExternalDocumentation externalDocs()

Additional external documentation for this schema.

Returns:ExternalDocumentation

additional schema documentation

formatback to summary
public String format()

Provides an optional override for the format.

If a consumer is unaware of the meaning of the format, they shall fall back to using the basic type without format. For example, if \"type: integer, format: int128\" were used to designate a very large integer, most consumers will not understand how to handle it, and fall back to simply \"type: integer\"

Returns:String

this schema's format

hiddenback to summary
public boolean hidden()

Allows schema to be marked as hidden.

Returns:boolean

whether or not this schema is hidden

ifSchemaback to summary
public Class<?> ifSchema()

A class used to create a schema used to control conditional evaluation. If an instance validates against the if schema then it must also validate against the then schema. Otherwise it must validate against the else schema.

Returns:Class<?>

a class used to create the if schema

Since
4.0
See Also
thenSchema(), elseSchema()
implementationback to summary
public Class<?> implementation()

Provides a java class as implementation for this schema. When provided, additional information in the Schema annotation (except for type information) will augment the java class after introspection.

Returns:Class<?>

a class that implements this schema

maxContainsback to summary
public int maxContains()

Specifies the maximum number of elements which may validate against the contains() schema.

If more than this number of elements of an array instance match the contains schema, the instance does not validate against this schema.

Returns:int

the maximum number of elements which may validate against the contains() schema

Since
4.0
maximumback to summary
public String maximum()

Sets the maximum numeric value for a property. Value must be a valid number. Ignored if the value is an empty string or not a number.

Returns:String

the maximum value for this schema

maxItemsback to summary
public int maxItems()

Only applicable if type=array. Sets the maximum number of items in an array. This integer MUST be greater than, or equal to, 0.

An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword.

Ignored if value is Integer.MIN_VALUE.
Returns:int

the maximum number of items in this array

maxLengthback to summary
public int maxLength()

Sets the maximum length of a string value. Ignored if the value is negative.

Returns:int

the maximum length of this schema

maxPropertiesback to summary
public int maxProperties()

Constrains the number of arbitrary properties when additionalProperties is defined. Ignored if value is 0.

Returns:int

the maximum number of properties for this schema

minContainsback to summary
public int minContains()

Specifies the minimum number of elements which must validate against the contains() schema.

If fewer than this number of elements of an array instance match the contains schema, the instance does not validate against this schema.

Returns:int

the minimum number of elements which must validate against the contains() schema

Since
4.0
minimumback to summary
public String minimum()

Sets the minimum numeric value for a property. Value must be a valid number. Ignored if the value is an empty string or not a number.

Returns:String

the minimum value for this schema

minItemsback to summary
public int minItems()

Only applicable if type=array. Sets the minimum number of items in an array. This integer MUST be greater than, or equal to, 0.

An array instance is valid against "minItems" if its size is greater than, or equal to, the value of this keyword.

Ignored if value is Integer.MAX_VALUE.
Returns:int

the minimum number of items in this array

minLengthback to summary
public int minLength()

Sets the minimum length of a string value. Ignored if the value is negative.

Returns:int

the minimum length of this schema

minPropertiesback to summary
public int minProperties()

Constrains the number of arbitrary properties when additionalProperties is defined. Ignored if value is 0.

Returns:int

the minimum number of properties for this schema

multipleOfback to summary
public double multipleOf()

Constrains a value such that when divided by the multipleOf, the result must be an integer. Ignored if the value is 0.

Returns:double

the multiplier constraint of the schema

nameback to summary
public String name()

The name of the schema or property.

The name is REQUIRED when the schema is defined within org.eclipse.microprofile.openapi.annotations.Components. The name will be used as the key to add this schema to the 'schemas' map for reuse.

Returns:String

the name of the schema

notback to summary
public Class<?> not()

Provides a java class to be used to disallow matching properties. Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema.

Returns:Class<?>

a class with disallowed properties

nullableback to summary
public boolean nullable()

Allows sending a null value for the defined schema.

Returns:boolean

whether or not this schema is nullable

oneOfback to summary
public Class<?>[] oneOf()

Provides an array of java class implementations which can be used to describe multiple acceptable schemas. If more than one match the derived schemas, a validation error will occur.

Returns:Class<?>[]

the list of possible classes for a single match

patternback to summary
public String pattern()

A regular expression that the value must satisfy. Ignored if the value is an empty string.

If the instance is a string, the regular expression must match the instance.

Returns:String

the ECMA-262 regular expression to match against

patternPropertiesback to summary
public PatternProperty[] patternProperties()

Applies subschemas against properties matched by regular expressions.

For each PatternProperty listed, for each property whose name matches | regex(), its value must validate against the schema created from schema().

Returns:PatternProperty[]

a mapping from regular expressions to schemas

Since
4.0
prefixItemsback to summary
public Class<?>[] prefixItems()

Schemas which the leading elements of an array instance must validate against.

The array of classes is used to create an array of schemas. If an instance is an array, the first element of the array must validate against the first schema, the second element must validate against the second schema and so on.

Returns:Class<?>[]

an array of classes used to create an array of schemas used to validate the leading elements of an array instance

Since
4.0
propertiesback to summary
public SchemaProperty[] properties()

Provides a list of properties present in this schema. Use of the properties list does not preclude the annotation scanning runtime from also including other properties found in the scan process. For example, if an implementation is also specified, the final set of properties used by the annotation scanner will include properties from both this list and those found from introspection of the implementation class, if any.

In the case where properties are specified here in addition to an implementation, the attributes given for a property using a SchemaProperty will override the same attributes scanned (or derived) from the implementation class.

Example:

 @Schema(properties = {
   @SchemaProperty(name = "creditCard", example = "4567100043210001"),
   @SchemaProperty(name = "departureFlight", description = "The departure flight information."),
   @SchemaProperty(name = "returningFlight")
})
 
Returns:SchemaProperty[]

a list of defined properties

Since
2.0
propertyNamesback to summary
public Class<?> propertyNames()

A schema which the names of properties of an object instance must validate against.

The class is used to create a schema. If the instance is an object, then the name of each property in the instance must validate against the schema.

Returns:Class<?>

a schema that property names must validate against

Since
4.0
readOnlyback to summary
public boolean readOnly()

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.

Returns:boolean

whether or not this schema is read only

refback to summary
public String ref()

Reference value to a Schema definition.

This property provides a reference to an object defined elsewhere.

Unlike ref on most MP OpenAPI annotations, this property is not mutually exclusive with other properties.

Returns:String

a reference to a schema definition

requiredback to summary
public boolean required()

Specifies whether the annotated item is required or not.

Returns:boolean

whether or not this schema is required

requiredPropertiesback to summary
public String[] requiredProperties()

Allows multiple properties in an object to be marked as required.

Returns:String[]

the list of required schema properties

thenSchemaback to summary
public Class<?> thenSchema()

A class used to create a schema that an instance must validate against if it validates against the if schema.

Returns:Class<?>

a class used to create the then schema

Since
4.0
See Also
ifSchema(), elseSchema()
titleback to summary
public String title()

A title to explain the purpose of the schema.

Returns:String

the title of the schema

typeback to summary
public SchemaType type()

Provides an override for the basic type of the schema.

Value MUST be a string. Multiple types via an array are not supported.

MUST be a valid type per the OpenAPI Specification.
Returns:SchemaType

the type of this schema

uniqueItemsback to summary
public boolean uniqueItems()

Only applicable if type=array. Determines if the items in the array SHOULD be unique.

If false, the instance validates successfully. If true, the instance validates successfully if all of its elements are unique.

Returns:boolean

whether the items in this array are unique

writeOnlyback to summary
public boolean writeOnly()

Declares the property as "write only". This means that 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.

Returns:boolean

whether or not this schema is write only

org.eclipse.microprofile.openapi.annotations.media back to summary

public final Class Schema.False

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.microprofile.openapi.annotations.media.Schema.False

Marker class to indicate that a boolean false schema should be used.
Since
3.1

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Falseback to summary
private False()
org.eclipse.microprofile.openapi.annotations.media back to summary

public final Class Schema.True

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.microprofile.openapi.annotations.media.Schema.True

Marker class to indicate that a boolean true schema should be used.
Since
3.1

Constructor Summary

AccessConstructor and Description
private
True()

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Trueback to summary
private True()