Schema objects are sometimes referred to as models, data types, or simply, schemas. This is because schema types are used to model complex data types used by an API.
A discriminator object describes how to differentiate between related schemas based on the value of a field in a request or response. See Composition and Inheritance.
A discriminator object describes how to differentiate between related schemas based on the value of a field in a request or response. See Composition and Inheritance.
Any number of extension fields can be added to the schema that can be used by tooling and vendors.
Arbitrary properties
Any
The schema object supports arbitrary properties without the
prefix. This is discouraged in favor of Extensions.
The example below illustrates three schema objects: IngredientProductCode, Ingredient, and IngredientType.
components: schemas: IngredientProductCode: description: The product code of an ingredient, only available when authenticated. type: string examples: - "AC-A2DF3" - "NAC-3F2D1" - "APM-1F2D3" Ingredient: type: object properties: name: description: The name of the ingredient. type: string examples: - Sugar Syrup - Angostura Bitters - Orange Peel type: $ref: "#/components/schemas/IngredientType" stock: description: The number of units of the ingredient in stock, only available when authenticated. type: integer examples: - 10 - 5 - 0 readOnly: true productCode: $ref: "#/components/schemas/IngredientProductCode" photo: description: A photo of the ingredient. type: string format: uri examples: - https://speakeasy.bar/ingredients/sugar_syrup.jpg - https://speakeasy.bar/ingredients/angostura_bitters.jpg - https://speakeasy.bar/ingredients/orange_peel.jpg required: - name - type IngredientType: description: The type of ingredient. type: string enum: - fresh - long-life - packaged
JSON Schema and OpenAPI
OpenAPI 3.0 was not totally compatible with JSON schema. That caused, and continues to cause, issues in tooling support. Fortunately, OpenAPI 3.1 is now a superset of JSON Schema, meaning compatibility with any valid JSon Schema document.