Class OpenAPISchema
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.
- Version:
- 3.0.0
- Author:
- Pavel Bodiachevskii
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription@Nullable ObjectThe value can be a boolean (true or false) or anOpenAPISchema.@Nullable List<OpenAPISchema> OpenAPI lets you combine and extend model definitions using the allOf keyword.@Nullable List<OpenAPISchema> Use the anyOf keyword to validate the data against any amount of the given subschemas.@Nullable ObjectDefault value.@Nullable BooleanYou can mark OpenAPI Schema as deprecated, by setting deprecated: true@Nullable StringThe value of these keyword MUST be a string.@Nullable DiscriminatorYou can use the enum keyword to specify possible values of a request parameter or a model property.@Nullable ObjectYou can add examples to parameters, properties and objects to make OpenAPI specification of your web service clearer.@Nullable BooleanThe word “exclusive” inexclusiveMinimumandexclusiveMaximummeans the corresponding boundary is excluded: Keyword Description exclusiveMinimum: false or not included value ≥ minimum exclusiveMinimum: true value > minimum exclusiveMaximum: false or not included value ≤ maximum exclusiveMaximum: true value < maximum@Nullable BooleanThe word “exclusive” inexclusiveMinimumandexclusiveMaximummeans the corresponding boundary is excluded: Keyword Description exclusiveMinimum: false or not included value ≥ minimum exclusiveMinimum: true value > minimum exclusiveMaximum: false or not included value ≤ maximum exclusiveMaximum: true value < maximum@Nullable ExternalDocumentationExternal resource for extended documentation@Nullable StringFormat modifier serves as a hint at the contents and format of the string.@Nullable BigDecimal@Nullable IntegerYou can define the minimum and maximum length of an array like so:@Nullable Integer@Nullable IntegerTheminPropertiesandmaxPropertieskeywords let you restrict the number of properties allowed in an object.@Nullable BigDecimal@Nullable IntegerYou can define the minimum and maximum length of an array like so:@Nullable Integer@Nullable IntegerTheminPropertiesandmaxPropertieskeywords let you restrict the number of properties allowed in an object.@Nullable BigDecimalUse the multipleOf keyword to specify that a number must be the multiple of another number:Schema name.@Nullable OpenAPISchemaThe not keyword does not exactly combine schemas, but as all of the keywords mentioned above it helps you to modify your schemas and make them more specific.@Nullable BooleanOpenAPI 3.0 does not have an explicit null type as in JSON Schema, but you can use nullable: true to specify that the value may be null.@Nullable List<OpenAPISchema> oneOf matches exactly one subschema, andanyOfcan match one or more subschemas.@Nullable StringThe pattern keyword lets you define a regular expression template for the string value.@Nullable Map<String, OpenAPISchema> The properties keyword is used to define the object properties – you need to list the property names and specify a schema for each property.@Nullable Boolean@Nullable StringReference to OpenAPI Schema definition.By default, all object properties are optional.@Nullable StringThe value of these keyword MUST be a string.@Nullable StringThe data type of a schema is defined by the type keyword, for example, type: string.@Nullable BooleanYou can use uniqueItems: true to specify that all items in the array must be unique:@Nullable Boolean@Nullable XMLIn your API specification, you can describe data in both XML and JSON formats as they are easily interchangeable.Fields inherited from class com.asyncapi.schemas.openapi.v3._0_0.properties.Extensions
extensions -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class com.asyncapi.schemas.openapi.v3._0_0.properties.Extensions
readExtensionProperty
-
Field Details
-
name
Schema name. -
title
The value of these keyword MUST be a string.This keywords can be used to decorate a user interface with information about the data produced by this user interface.
A title will preferably be short
- See Also:
-
multipleOf
Use the multipleOf keyword to specify that a number must be the multiple of another number:
The example above matches 10, 20, 30, 0, -10, -20, and so on.type: integer multipleOf: 10multipleOf may be used with floating-point numbers, but in practice this can be unreliable due to the limited precision or floating point math.
The value of multipleOf MUST be a positive number, that is, you cannot use multipleOf: -5.type: number multipleOf: 2.5- See Also:
-
maximum
Use theminimumandmaximumkeywords to specify the range of possible values:
By default, the minimum and maximum values are included in the range, that is:type: integer minimum: 1 maximum: 20
To exclude the boundary values, specifyminimum ≤ value ≤ maximumexclusiveMinimum: true andexclusiveMaximum: true.
For example, you can define a floating-point number range as 0–50 and exclude the 0 value:exclusiveMinimum: true exclusiveMaximum: true- See Also:
-
exclusiveMaximum
The word “exclusive” inexclusiveMinimumandexclusiveMaximummeans the corresponding boundary is excluded:Keyword Description exclusiveMinimum: false or not included value ≥ minimum exclusiveMinimum: true value > minimum exclusiveMaximum: false or not included value ≤ maximum exclusiveMaximum: true value < maximum - See Also:
-
minimum
Use theminimumandmaximumkeywords to specify the range of possible values:
By default, the minimum and maximum values are included in the range, that is:type: integer minimum: 1 maximum: 20
To exclude the boundary values, specifyminimum ≤ value ≤ maximumexclusiveMinimum: true andexclusiveMaximum: true.
For example, you can define a floating-point number range as 0–50 and exclude the 0 value:exclusiveMinimum: true exclusiveMaximum: true- See Also:
-
exclusiveMinimum
The word “exclusive” inexclusiveMinimumandexclusiveMaximummeans the corresponding boundary is excluded:Keyword Description exclusiveMinimum: false or not included value ≥ minimum exclusiveMinimum: true value > minimum exclusiveMaximum: false or not included value ≤ maximum exclusiveMaximum: true value < maximum - See Also:
-
maxLength
String length can be restricted usingminLengthandmaxLength:type: string minLength: 3 maxLength: 20- See Also:
-
minLength
String length can be restricted usingminLengthandmaxLength:type: string minLength: 3 maxLength: 20- See Also:
-
pattern
The pattern keyword lets you define a regular expression template for the string value.Only the values that match this template will be accepted. The regular expression syntax used is from JavaScript (more specifically, ECMA 262).
Regular expressions are case-sensitive, that is, [a-z] and [A-Z] are different expressions.
For example, the following pattern matches a Social Security Number (SSN) in the 123-45-6789 format:
- See Also:
-
maxItems
You can define the minimum and maximum length of an array like so:type: array items: type: integer minItems: 1 maxItems: 10- See Also:
-
minItems
You can define the minimum and maximum length of an array like so:type: array items: type: integer minItems: 1 maxItems: 10- See Also:
-
uniqueItems
You can use uniqueItems: true to specify that all items in the array must be unique:type: array items: type: integer uniqueItems: true # [1, 2, 3] – valid # [1, 1, 3] – not valid # [ ] – valid -
maxProperties
TheminPropertiesandmaxPropertieskeywords let you restrict the number of properties allowed in an object. This can be useful when usingadditionalPropertiesor free-form objects.type: object minProperties: 2 maxProperties: 10- See Also:
-
minProperties
TheminPropertiesandmaxPropertieskeywords let you restrict the number of properties allowed in an object. This can be useful when usingadditionalPropertiesor free-form objects.type: object minProperties: 2 maxProperties: 10- See Also:
-
required
By default, all object properties are optional. You can specify the required properties in the required list:
Note that required is an object-level attribute, not a property attribute:type: object properties: id: type: integer username: type: string name: type: string required: - id - usernametype: object properties: id: type: integer required: true # Wrong! required: # Correct - id- See Also:
-
type
The data type of a schema is defined by the type keyword, for example, type: string.OpenAPI defines the following basic types:
- string (this includes dates and files)
- number
- integer
- boolean
- array
- object
Note that there is no null type; instead, the
nullableattribute is used as a modifier of the base type.Additional type-specific keywords can be used to refine the data type, for example, limit the string length or specify an enum of possible values.
- See Also:
-
allOf
OpenAPI lets you combine and extend model definitions using the allOf keyword. allOf takes an array of object definitions that are used for independent validation but together compose a single object.Still, it does not imply a hierarchy between the models. For that purpose, you should include the
discriminator.To be valid against allOf, the data provided by the client must be valid against all of the given subschemas. In the following example, allOf acts as a tool for combining schemas used in specific cases with the general one.
For more clearness,
oneOfis also used with adiscriminator.
As you can see, this example validates the request body content to make sure it includes all the information needed to update a pet item with the PUT operation.components: schemas: Pet: type: object required: - pet_type properties: pet_type: type: string discriminator: propertyName: pet_type Dog: # "Dog" is a value for the pet_type property (the discriminator value) allOf: # Combines the main `Pet` schema with `Dog`-specific properties - $ref: '#/components/schemas/Pet' - type: object # all other properties specific to a `Dog` properties: bark: type: boolean breed: type: string enum: [Dingo, Husky, Retriever, Shepherd] Cat: # "Cat" is a value for the pet_type property (the discriminator value) allOf: # Combines the main `Pet` schema with `Cat`-specific properties - $ref: '#/components/schemas/Pet' - type: object # all other properties specific to a `Cat` properties: hunts: type: boolean age: type: integerIt requires user to specify which type of the item should be updated, and validates against the specified schema according to their choice. Note the inline or referenced schema must be a schema object, not a standard JSON schema.
For that example, all of the following request bodies are valid:
{ "pet_type": "Cat", "age": 3 }{ "pet_type": "Dog", "bark": true }
The following request bodies are not valid:{ "pet_type": "Dog", "bark": false, "breed": "Dingo" }{ "age": 3 # Does not include the pet_type property }{ "pet_type": "Cat", "bark": true # The `Cat` schema does not have the `bark` property }- See Also:
-
anyOf
Use the anyOf keyword to validate the data against any amount of the given subschemas. That is, the data may be valid against one or more subschemas at the same time.
Note the inline or referenced schema must be a schema object, not a standard JSON schema. With this example, the following JSON request bodies are valid:paths: /pets: patch: requestBody: content: application/json: schema: anyOf: - $ref: '#/components/schemas/PetByAge' - $ref: '#/components/schemas/PetByType' responses: '200': description: Updated components: schemas: PetByAge: type: object properties: age: type: integer nickname: type: string required: - age PetByType: type: object properties: pet_type: type: string enum: [Cat, Dog] hunts: type: boolean required: - pet_type{ "age": 1 }{ "pet_type": "Cat", "hunts": true }
The following example is not valid, because it does not contain any of the required properties for both of the schemas:{ "nickname": "Fido", "pet_type": "Dog", "age": 4 }{ "nickname": "Mr. Paws", "hunts": false }- See Also:
-
oneOf
oneOf matches exactly one subschema, andanyOfcan match one or more subschemas.To better understand the difference, use the
anyOfexample but replace anyOf with oneOf. When using oneOf, the following request body is not valid because it matches both schemas and not just one:{ "nickname": "Fido", "pet_type": "Dog", "age": 4 }- See Also:
-
not
The not keyword does not exactly combine schemas, but as all of the keywords mentioned above it helps you to modify your schemas and make them more specific.
In this example, user should specify the pet_type value of any type except integer (that is, it should be an array, boolean, number, object, or string). The following request body is valid:paths: /pets: patch: requestBody: content: application/json: schema: $ref: '#/components/schemas/PetByType' responses: '200': description: Updated components: schemas: PetByType: type: object properties: pet_type: not: type: integer required: - pet_type
And the following is not valid:{ "pet_type": "Cat" }{ "pet_type": 11 }- See Also:
-
properties
The properties keyword is used to define the object properties – you need to list the property names and specify a schema for each property.type: object properties: id: type: integer name: type: string- See Also:
-
additionalProperties
The value can be a boolean (true or false) or anOpenAPISchema.type: object additionalProperties: truetype: object additionalProperties: {} -
description
The value of these keyword MUST be a string.This keywords can be used to decorate a user interface with information about the data produced by this user interface.
A description will provide explanation about the purpose of the instance described by this schema.
- See Also:
-
format
Format modifier serves as a hint at the contents and format of the string.- See Also:
-
ref
Reference to OpenAPI Schema definition. -
nullable
OpenAPI 3.0 does not have an explicit null type as in JSON Schema, but you can use nullable: true to specify that the value may be null. Note that null is different from an empty string "".# Correct type: integer nullable: true # Incorrect type: null # Incorrect as well type: - integer - null- See Also:
-
readOnly
You can use thereadOnlyandwriteOnlykeywords to mark specific properties as read-only or write-only.This is useful, for example, when GET returns more properties than used in POST – you can use the same schema in both GET and POST and mark the extra properties as readOnly.
readOnlyproperties are included in responses but not in requests, andwriteOnlyproperties may be sent in requests but not in responses.
If atype: object properties: id: # Returned by GET, not used in POST/PUT/PATCH type: integer readOnly: true username: type: string password: # Used in POST/PUT/PATCH, not returned by GET type: string writeOnly: truereadOnlyorwriteOnlyproperty is included in the required list, required affects just the relevant scope – responses only or requests only.That is, read-only required properties apply to responses only, and write-only required properties – to requests only.
- See Also:
-
writeOnly
You can use thereadOnlyandwriteOnlykeywords to mark specific properties as read-only or write-only.This is useful, for example, when GET returns more properties than used in POST – you can use the same schema in both GET and POST and mark the extra properties as readOnly.
readOnlyproperties are included in responses but not in requests, andwriteOnlyproperties may be sent in requests but not in responses.
If atype: object properties: id: # Returned by GET, not used in POST/PUT/PATCH type: integer readOnly: true username: type: string password: # Used in POST/PUT/PATCH, not returned by GET type: string writeOnly: truereadOnlyorwriteOnlyproperty is included in the required list, required affects just the relevant scope – responses only or requests only.That is, read-only required properties apply to responses only, and write-only required properties – to requests only.
- See Also:
-
example
You can add examples to parameters, properties and objects to make OpenAPI specification of your web service clearer. Examples can be read by tools and libraries that process your API in some way.For example, an API mocking tool can use sample values to generate mock requests. You can specify examples for objects, individual properties and operation parameters
parameters: - in: query name: status schema: type: string enum: [approved, pending, closed, new] example: approved # Example of a parameter valueparameters: - in: query name: limit schema: type: integer maximum: 50 example: zero: # Distinct name value: 0 # Example value summary: A sample limit value # Optional description -
externalDocs
External resource for extended documentation -
deprecated
You can mark OpenAPI Schema as deprecated, by setting deprecated: true -
xml
In your API specification, you can describe data in both XML and JSON formats as they are easily interchangeable.For example, the following declaration —
— is represented in the following way in JSON and XML:components: schemas: book: type: object properties: id: type: integer title: type: string author: type: string
JSON
XML{ "id": 0, "title": "string", "author": "string" }
As you can see, in XML representation, the object name serves as a parent element and properties are translated to child elements.<book> <id>0</id> <title>string</title> <author>string</author> </book>The OpenAPI 3 format offers a special xml object to help you fine-tune representation of XML data. You can use this object to transform some properties to attributes rather than elements, to change element names, to add namespaces and to control transformations of array items.
- See Also:
-
enumValue
You can use the enum keyword to specify possible values of a request parameter or a model property.For example, the sort parameter in GET /items?sort=[asc|desc] can be described as:
A nullable enum can be defined as follows:paths: /items: get: parameters: - in: query name: sort description: Sort order schema: type: string enum: [asc, desc]type: string nullable: true # <--- enum: - asc - desc - null # <--- without quotes, i.e. null not "null"- See Also:
-
defaultValue
Default value. -
discriminator
-
-
Constructor Details
-
OpenAPISchema
public OpenAPISchema()
-