Class HttpPartSchema
The schema definition can be applied to any HTTP parts such as bodies, headers, query/form parameters, and URL path parts.
The API is generic enough to apply to any path part although some attributes may only applicable for certain parts.
Schema objects are created via builders instantiated through the create() method.
Jakarta Bean Validation Support:
As of 9.2.0, this class supports Jakarta Bean Validation constraint annotations (e.g.,
@NotNull →required(true) @Size(min=x, max=y) →minLength/maxLength andminItems/maxItems @Min(value) →minimum(value) @Max(value) →maximum(value) @Pattern(regexp) →pattern(regexp) @Email →format("email") @Positive/@PositiveOrZero/@Negative/@NegativeOrZero → Corresponding min/max constraints@NotEmpty →required(true) + minLength(1)/minItems(1) @NotBlank →required(true) + minLength(1) + pattern @DecimalMin/@DecimalMax →minimum/maximum with optionalexclusiveMinimum/exclusiveMaximum
This integration uses pure reflection and does not require
Notes:
- This class is thread safe and reusable.
See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final HttpPartSchemaReusable instance of this object, all default settings.static final HttpPartSchemaArray typestatic final HttpPartSchemaComma-delimited array typestatic final HttpPartSchemaMulti-part array typestatic final HttpPartSchemaPipe-delimited array typestatic final HttpPartSchemaSpace-delimited array typestatic final HttpPartSchemaTab-delimited array typestatic final HttpPartSchemaUON-formatted array typestatic final HttpPartSchemaBinary typestatic final HttpPartSchemaSpaced binary typestatic final HttpPartSchemaBoolean typestatic final HttpPartSchemaByte typestatic final HttpPartSchemaDate typestatic final HttpPartSchemaDate-time typestatic final HttpPartSchemaDouble typestatic final HttpPartSchemaFile typestatic final HttpPartSchemaFloat typestatic final HttpPartSchemaInt32 typestatic final HttpPartSchemaInt64 typestatic final HttpPartSchemaInteger typestatic final HttpPartSchemaNo typestatic final HttpPartSchemaNumber typestatic final HttpPartSchemaObject typestatic final HttpPartSchemaUON-formated object typestatic final HttpPartSchemaString typestatic final HttpPartSchemaUON-formated simple type -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpPartSchema.Buildercreate()Instantiates a new builder for this object.static HttpPartSchemacreate(Annotation a) Finds the schema information on the specified annotation.static HttpPartSchemacreate(Annotation a, String defaultName) Finds the schema information on the specified annotation.static HttpPartSchemacreate(Class<? extends Annotation> c, Method m) Finds the schema information for the specified method return.static HttpPartSchemacreate(Class<? extends Annotation> c, Type t) Finds the schema information for the specified class.static HttpPartSchemacreate(Class<? extends Annotation> c, ParameterInfo mpi) Finds the schema information for the specified method parameter.static HttpPartSchema.BuilderShortcut for callingcreate().type(type); static HttpPartSchema.BuilderShortcut for callingcreate().type(type).format(format); Returns thecollectionFormat field of this schema.Returns thedefault field of this schema.getEnum()Returns theenum field of this schema.Returns theformat field of this schema.Returns theformat field of this schema.getItems()Returns theitems field of this schema.Returns themaximum field of this schema.Returns themaxItems field of this schema.Returns themaxLength field of this schema.Returns themaxProperties field of this schema.Returns theminimum field of this schema.Returns theminItems field of this schema.Returns theminLength field of this schema.Returns theminProperties field of this schema.Returns themultipleOf field of this schema.getName()Returns the name of the object described by this schema, for example the query or form parameter name.Class<?>Returns the default parsed type for this schema.Class<?>Returns theparser field of this schema.Returns thepattern field of this schema.getProperty(String name) Returns the schema information for the specified property.Class<?>Returns theserializer field of this schema.getType()Returns thetype field of this schema.Returns thetype field of this schema.booleanReturnstrue if this schema has properties associated with it.booleanReturns theallowEmptyValue field of this schema.booleanReturns theexclusiveMaximum field of this schema.booleanReturns theexclusiveMinimum field of this schema.booleanReturns therequired field of this schema.booleanReturns theskipIfEmpty field of this schema.booleanReturns theuniqueItems field of this schema.static HttpPartSchema.BuildertArray()Shortcut for .create ().type(HttpPartDataType.ARRAY )static HttpPartSchema.BuildertArray(HttpPartSchema.Builder items) Shortcut for .create ().type(HttpPartDataType.ARRAY ).items(items)static HttpPartSchema.BuilderShortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.CSV )static HttpPartSchema.BuildertArrayCsv(HttpPartSchema.Builder items) Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.CSV ).items(items)static HttpPartSchema.BuilderShortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.MULTI )static HttpPartSchema.BuilderShortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.MULTI ).items(items)static HttpPartSchema.BuilderShortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.PIPES )static HttpPartSchema.BuilderShortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.PIPES ).items(items)static HttpPartSchema.BuilderShortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.SSV )static HttpPartSchema.BuildertArraySsv(HttpPartSchema.Builder items) Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.SSV ).items(items)static HttpPartSchema.BuilderShortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.TSV )static HttpPartSchema.BuildertArrayTsv(HttpPartSchema.Builder items) Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.TSV ).items(items)static HttpPartSchema.BuilderShortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.UONC )static HttpPartSchema.BuildertArrayUon(HttpPartSchema.Builder items) Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.UONC ).items(items)static HttpPartSchema.BuildertBinary()Shortcut for .create ().type(HttpPartDataType.STRING ).format(HttpPartFormat.BINARY )static HttpPartSchema.BuilderShortcut for .create ().type(HttpPartDataType.STRING ).format(HttpPartFormat.BINARY_SPACED )static HttpPartSchema.BuildertBoolean()Shortcut for .create ().type(HttpPartDataType.BOOLEAN )static HttpPartSchema.BuildertByte()Shortcut for .create ().type(HttpPartDataType.STRING ).format(HttpPartFormat.BYTE )static HttpPartSchema.BuildertDate()Shortcut for .create ().type(HttpPartDataType.STRING ).format(HttpPartFormat.DATE )static HttpPartSchema.BuilderShortcut for .create ().type(HttpPartDataType.STRING ).format(HttpPartFormat.DATE_TIME )static HttpPartSchema.BuildertDouble()Shortcut for .create ().type(HttpPartDataType.NUMBER ).format(HttpPartFormat.DOUBLE )static HttpPartSchema.BuildertFile()Shortcut for .create ().type(HttpPartDataType.FILE )static HttpPartSchema.BuildertFloat()Shortcut for .create ().type(HttpPartDataType.NUMBER ).format(HttpPartFormat.FLOAT )static HttpPartSchema.BuildertInt32()Shortcut for .create ().type(HttpPartDataType.INTEGER ).format(HttpPartFormat.INT32 )static HttpPartSchema.BuildertInt64()Shortcut for .create ().type(HttpPartDataType.INTEGER ).format(HttpPartFormat.INT64 )static HttpPartSchema.BuildertInteger()Shortcut for .create ().type(HttpPartDataType.INTEGER )static HttpPartSchema.BuildertNone()Shortcut for .create ().type(HttpPartDataType.NONE )static HttpPartSchema.BuildertNumber()Shortcut for .create ().type(HttpPartDataType.NUMBER )static HttpPartSchema.BuildertObject()Shortcut for .create ().type(HttpPartDataType.OBJECT )static HttpPartSchema.BuilderShortcut for .create ().type(HttpPartDataType.OBJECT ).collectionFormat(HttpPartCollectionFormat.UON )toString()static HttpPartSchema.BuildertString()Shortcut for .create ().type(HttpPartDataType.STRING )static HttpPartSchema.BuildertUon()Shortcut for .create ().type(HttpPartDataType.STRING ).format(HttpPartFormat.UON )validateInput(String in) Throws aSchemaValidationExceptionif the specified pre-parsed input does not validate against this schema.<T> TvalidateOutput(T o) Validates the specified parsed output against this schema.
-
Field Details
-
DEFAULT
Reusable instance of this object, all default settings. -
T_BOOLEAN
Boolean type -
T_FILE
File type -
T_INTEGER
Integer type -
T_INT32
Int32 type -
T_INT64
Int64 type -
T_NONE
No type -
T_NUMBER
Number type -
T_FLOAT
Float type -
T_DOUBLE
Double type -
T_STRING
String type -
T_BYTE
Byte type -
T_BINARY
Binary type -
T_BINARY_SPACED
Spaced binary type -
T_DATE
Date type -
T_DATETIME
Date-time type -
T_UON
UON-formated simple type -
T_ARRAY
Array type -
T_ARRAY_CSV
Comma-delimited array type -
T_ARRAY_PIPES
Pipe-delimited array type -
T_ARRAY_SSV
Space-delimited array type -
T_ARRAY_TSV
Tab-delimited array type -
T_ARRAY_UON
UON-formatted array type -
T_ARRAY_MULTI
Multi-part array type -
T_OBJECT
Object type -
T_OBJECT_UON
UON-formated object type
-
-
Method Details
-
create
Instantiates a new builder for this object.- Returns:
- A new builder for this object.
-
create
Finds the schema information on the specified annotation.- Parameters:
a- The annotation to find the schema information on..
Must not benull .- Returns:
- The schema information found on the annotation. Never
null .
-
create
Finds the schema information on the specified annotation.- Parameters:
a- The annotation to find the schema information on..
Must not benull .defaultName- The default part name if not specified on the annotation. Can benull (the name from the annotation, if any, is left unchanged).- Returns:
- The schema information found on the annotation. Never
null .
-
create
Finds the schema information for the specified class.This method will gather all the schema information from the annotations on the class and all parent classes/interfaces.
- Parameters:
c- The annotation to look for.
Valid values:@Content @Header @Query @FormData @Path @Response @HasQuery @HasFormData
t- The class containing the parameter.
Can benull (no type-level annotations are applied).- Returns:
- The schema information about the parameter. Never
null .
-
create
Finds the schema information for the specified method return.This method will gather all the schema information from the annotations at the following locations:
- The method.
- The method return class.
- The method return parent classes and interfaces.
- Parameters:
c- The annotation to look for.
Valid values:@Content @Header @Query @FormData @Path @Response @HasQuery @HasFormData
m- The Java method with the return type being checked.
Must not benull .- Returns:
- The schema information about the parameter. Never
null .
-
create
Finds the schema information for the specified method parameter.This method will gather all the schema information from the annotations at the following locations:
- The method parameter.
- The method parameter class.
- The method parameter parent classes and interfaces.
- Parameters:
c- The annotation to look for.
Valid values:@Content @Header @Query @FormData @Path @Response @HasQuery @HasFormData
mpi- The Java method parameter. Must not benull .- Returns:
- The schema information about the parameter. Never
null .
-
create
Shortcut for callingcreate().type(type); - Parameters:
type- The schema type value.- Returns:
- A new builder.
-
create
Shortcut for callingcreate().type(type).format(format); - Parameters:
type- The schema type value.format- The schema format value.- Returns:
- A new builder.
-
tArray
Shortcut for .create ().type(HttpPartDataType.ARRAY )- Returns:
- A new builder for this object.
-
tArray
Shortcut for .create ().type(HttpPartDataType.ARRAY ).items(items)- Parameters:
items- The schema of the array items.- Returns:
- A new builder for this object.
-
tArrayCsv
Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.CSV )- Returns:
- A new builder for this object.
-
tArrayCsv
Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.CSV ).items(items)- Parameters:
items- The schema of the array items.- Returns:
- A new builder for this object.
-
tArrayMulti
Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.MULTI )- Returns:
- A new builder for this object.
-
tArrayMulti
Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.MULTI ).items(items)- Parameters:
items- The schema of the array items.- Returns:
- A new builder for this object.
-
tArrayPipes
Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.PIPES )- Returns:
- A new builder for this object.
-
tArrayPipes
Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.PIPES ).items(items)- Parameters:
items- The schema of the array items.- Returns:
- A new builder for this object.
-
tArraySsv
Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.SSV )- Returns:
- A new builder for this object.
-
tArraySsv
Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.SSV ).items(items)- Parameters:
items- The schema of the array items.- Returns:
- A new builder for this object.
-
tArrayTsv
Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.TSV )- Returns:
- A new builder for this object.
-
tArrayTsv
Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.TSV ).items(items)- Parameters:
items- The schema of the array items.- Returns:
- A new builder for this object.
-
tArrayUon
Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.UONC )- Returns:
- A new builder for this object.
-
tArrayUon
Shortcut for .create ().type(HttpPartDataType.ARRAY ).collectionFormat(HttpPartCollectionFormat.UONC ).items(items)- Parameters:
items- The schema of the array items.- Returns:
- A new builder for this object.
-
tBinary
Shortcut for .create ().type(HttpPartDataType.STRING ).format(HttpPartFormat.BINARY )- Returns:
- A new builder for this object.
-
tBinarySpaced
Shortcut for .create ().type(HttpPartDataType.STRING ).format(HttpPartFormat.BINARY_SPACED )- Returns:
- A new builder for this object.
-
tBoolean
Shortcut for .create ().type(HttpPartDataType.BOOLEAN )- Returns:
- A new builder for this object.
-
tByte
Shortcut for .create ().type(HttpPartDataType.STRING ).format(HttpPartFormat.BYTE )- Returns:
- A new builder for this object.
-
tDate
Shortcut for .create ().type(HttpPartDataType.STRING ).format(HttpPartFormat.DATE )- Returns:
- A new builder for this object.
-
tDateTime
Shortcut for .create ().type(HttpPartDataType.STRING ).format(HttpPartFormat.DATE_TIME )- Returns:
- A new builder for this object.
-
tDouble
Shortcut for .create ().type(HttpPartDataType.NUMBER ).format(HttpPartFormat.DOUBLE )- Returns:
- A new builder for this object.
-
tFile
Shortcut for .create ().type(HttpPartDataType.FILE )- Returns:
- A new builder for this object.
-
tFloat
Shortcut for .create ().type(HttpPartDataType.NUMBER ).format(HttpPartFormat.FLOAT )- Returns:
- A new builder for this object.
-
tInt32
Shortcut for .create ().type(HttpPartDataType.INTEGER ).format(HttpPartFormat.INT32 )- Returns:
- A new builder for this object.
-
tInt64
Shortcut for .create ().type(HttpPartDataType.INTEGER ).format(HttpPartFormat.INT64 )- Returns:
- A new builder for this object.
-
tInteger
Shortcut for .create ().type(HttpPartDataType.INTEGER )- Returns:
- A new builder for this object.
-
tNone
Shortcut for .create ().type(HttpPartDataType.NONE )- Returns:
- A new builder for this object.
-
tNumber
Shortcut for .create ().type(HttpPartDataType.NUMBER )- Returns:
- A new builder for this object.
-
tObject
Shortcut for .create ().type(HttpPartDataType.OBJECT )- Returns:
- A new builder for this object.
-
tObjectUon
Shortcut for .create ().type(HttpPartDataType.OBJECT ).collectionFormat(HttpPartCollectionFormat.UON )- Returns:
- A new builder for this object.
-
tString
Shortcut for .create ().type(HttpPartDataType.STRING )- Returns:
- A new builder for this object.
-
tUon
Shortcut for .create ().type(HttpPartDataType.STRING ).format(HttpPartFormat.UON )- Returns:
- A new builder for this object.
-
getCollectionFormat
Returns thecollectionFormat field of this schema.- Returns:
- The
collectionFormat field of this schema. Defaults toHttpPartCollectionFormat.NO_COLLECTION_FORMATif not specified. - See Also:
-
getDefault
Returns thedefault field of this schema.- Returns:
- The default value for this schema, or
null if not specified. - See Also:
-
getEnum
Returns theenum field of this schema.- Returns:
- The
enum field of this schema. Nevernull - returns an empty set if not specified. - See Also:
-
getFormat
Returns theformat field of this schema.- Returns:
- The
format field of this schema. Defaults toHttpPartFormat.NO_FORMATif not specified. - See Also:
-
getFormat
Returns theformat field of this schema.- Parameters:
cm- The class info of the object.
Used to auto-detect the format if the format was not specified.
Must not benull .- Returns:
- The
format field of this schema, or the format auto-detected from the class info, orHttpPartFormat.NO_FORMATif not specified and not auto-detectable. - See Also:
-
getItems
Returns theitems field of this schema.- Returns:
- The schema for child items of the object represented by this schema, or
null if not defined. - See Also:
-
getMaximum
Returns themaximum field of this schema.- Returns:
- The
maximum field of this schema, ornull if not specified. - See Also:
-
getMaxItems
Returns themaxItems field of this schema.- Returns:
- The
maxItems field of this schema, ornull if not specified. - See Also:
-
getMaxLength
Returns themaxLength field of this schema.- Returns:
- The
maxLength field of this schema, ornull if not specified. - See Also:
-
getMaxProperties
Returns themaxProperties field of this schema.- Returns:
- The
maxProperties field of this schema, ornull if not specified. - See Also:
-
getMinimum
Returns theminimum field of this schema.- Returns:
- The
minimum field of this schema, ornull if not specified. - See Also:
-
getMinItems
Returns theminItems field of this schema.- Returns:
- The
minItems field of this schema, ornull if not specified. - See Also:
-
getMinLength
Returns theminLength field of this schema.- Returns:
- The
minLength field of this schema, ornull if not specified. - See Also:
-
getMinProperties
Returns theminProperties field of this schema.- Returns:
- The
minProperties field of this schema, ornull if not specified. - See Also:
-
getMultipleOf
Returns themultipleOf field of this schema.- Returns:
- The
multipleOf field of this schema, ornull if not specified. - See Also:
-
getName
Returns the name of the object described by this schema, for example the query or form parameter name.- Returns:
- The name, or
null if not specified. - See Also:
-
getParsedType
Returns the default parsed type for this schema.- Returns:
- The default parsed type for this schema. Never
null .
-
getParser
Returns theparser field of this schema.- Returns:
- The
parser field of this schema, ornull if not specified. - See Also:
-
getPattern
Returns thepattern field of this schema.- Returns:
- The
pattern field of this schema, ornull if not specified. - See Also:
-
getProperty
Returns the schema information for the specified property.- Parameters:
name- The property name. Can benull (treated as an unmatched name; falls back to theadditionalProperties schema).- Returns:
- The schema information for the specified property, or the
additionalProperties schema if no matching property is defined, ornull if neither is defined.
-
getSerializer
Returns theserializer field of this schema.- Returns:
- The
serializer field of this schema, ornull if not specified. - See Also:
-
getType
Returns thetype field of this schema.- Returns:
- The
type field of this schema. Defaults toHttpPartDataType.NO_TYPEif not specified. - See Also:
-
getType
Returns thetype field of this schema.- Parameters:
cm- The class info of the object.
Used to auto-detect the type if the type was not specified.
Must not benull .- Returns:
- The
type field of this schema, or the type auto-detected from the class info if not specified. - See Also:
-
hasProperties
Returnstrue if this schema has properties associated with it.- Returns:
true if this schema has properties associated with it.
-
isAllowEmptyValue
Returns theallowEmptyValue field of this schema.- Returns:
- The
allowEmptyValue field of this schema. - See Also:
-
isExclusiveMaximum
Returns theexclusiveMaximum field of this schema.- Returns:
- The
exclusiveMaximum field of this schema. - See Also:
-
isExclusiveMinimum
Returns theexclusiveMinimum field of this schema.- Returns:
- The
exclusiveMinimum field of this schema. - See Also:
-
isRequired
Returns therequired field of this schema.- Returns:
- The
required field of this schema. - See Also:
-
isSkipIfEmpty
Returns theskipIfEmpty field of this schema.- Returns:
- The
skipIfEmpty field of this schema. - See Also:
-
isUniqueItems
Returns theuniqueItems field of this schema.- Returns:
- The
uniqueItems field of this schema. - See Also:
-
properties
-
toString
-
validateInput
Throws aSchemaValidationExceptionif the specified pre-parsed input does not validate against this schema.- Parameters:
in- The input. Can benull (only therequired check is performed; format/pattern/length checks are skipped).- Returns:
- The same object passed in.
- Throws:
SchemaValidationException- if the specified pre-parsed input does not validate against this schema.
-
validateOutput
Validates the specified parsed output against this schema.- Type Parameters:
T- The return type.- Parameters:
o- The parsed output. Can benull (only therequired check is performed; type-specific validation is skipped).- Returns:
- The same object passed in.
- Throws:
SchemaValidationException- if the specified parsed output does not validate against this schema.
-