Skip to content

Commit 61ac60c

Browse files
committed
Updated Schema Object
1 parent b7cdbd6 commit 61ac60c

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

versions/3.0.md

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,18 +2260,14 @@ $ref: 'definitions.yaml#/Pet'
22602260

22612261
The Schema Object allows the definition of input and output data types.
22622262
These types can be objects, but also primitives and arrays.
2263-
This object is based on the [JSON Schema Specification Draft 4](http://json-schema.org/) and uses a predefined subset of it.
2264-
On top of this subset, there are extensions provided by this specification to allow for more complete documentation.
2263+
This object is an extended subset of the [JSON Schema Specification Draft 4](http://json-schema.org/).
22652264

22662265
Further information about the properties can be found in [JSON Schema Core](http://json-schema.org/latest/json-schema-core.html) and [JSON Schema Validation](http://json-schema.org/latest/json-schema-validation.html).
22672266
Unless stated otherwise, the property definitions follow the JSON Schema specification as referenced here.
22682267

22692268
The following properties are taken directly from the JSON Schema definition and follow the same specifications:
2270-
- $ref - As a [JSON Reference](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03)
2271-
- format (See [Data Type Formats](#dataTypeFormat) for further details)
2269+
22722270
- title
2273-
- description ([CommonMark syntax](http://spec.commonmark.org/) can be used for rich text representation)
2274-
- default (Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object)
22752271
- multipleOf
22762272
- maximum
22772273
- exclusiveMaximum
@@ -2287,25 +2283,32 @@ The following properties are taken directly from the JSON Schema definition and
22872283
- minProperties
22882284
- required
22892285
- enum
2290-
- type
2291-
2292-
The following properties are taken from the JSON Schema definition but their definitions were adjusted to the OpenAPI Specification.
2293-
Their definition is the same as the one from JSON Schema, only where the original definition references the JSON Schema definition, the [Schema Object](#schemaObject) definition is used instead.
2294-
- items
2295-
- allOf
2296-
- oneOf
2297-
- anyOf
2298-
- not
2299-
- properties
2300-
- additionalProperties
2286+
2287+
The following properties are taken from the JSON Schema definition but their definitions were adjusted to the OpenAPI Specification.
2288+
- type - Value MUST be a string. Multiple types via an array are not supported.
2289+
- allOf - Inline or referenced schema MUST be of a [Schema Object](#schemaObject) and not a standard JSON Schema.
2290+
- oneOf - Inline or referenced schema MUST be of a [Schema Object](#schemaObject) and not a standard JSON Schema.
2291+
- anyOf - Inline or referenced schema MUST be of a [Schema Object](#schemaObject) and not a standard JSON Schema.
2292+
- not - Inline or referenced schema MUST be of a [Schema Object](#schemaObject) and not a standard JSON Schema.
2293+
- items - Value MUST be an object and not an array. Inline or referenced schema MUST be of a [Schema Object](#schemaObject) and not a standard JSON Schema. `items` MUST be present of the `type` is `array`.
2294+
- properties - Property definitions MUST be a [Schema Object](#schemaObject) and not a standard JSON Schema (inline or referenced).
2295+
- additionalProperties - Value can be boolean or object. If object, definition MUST be a [Schema Object](#schemaObject) and not a standard JSON Schema (inline or referenced).
2296+
- $ref - As a [Reference Object](#referenceObject).
2297+
- description ([CommonMark syntax](http://spec.commonmark.org/) can be used for rich text representation).
2298+
- format - See [Data Type Formats](#dataTypeFormat) for further details. While relying on JSON Schema's defined formats, the OAS offers a few additional predefined formats.
2299+
- default - Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object.
2300+
2301+
Additional properties defined by the JSON Schema specification that are not mentioned here are strictly unsupported.
23012302

23022303
Other than the JSON Schema subset fields, the following fields may be used for further schema documentation.
23032304

23042305
##### Fixed Fields
23052306
Field Name | Type | Description
23062307
---|:---:|---
2307-
<a name="schemaDiscriminator"></a>discriminator | `string` | Adds support for polymorphism. The discriminator is the schema property name that is used to differentiate between other schema that inherit this schema. The property name used MUST be defined at this schema and it MUST be in the `required` property list. When used, the value MUST be the name of this schema or any schema that inherits it.
2308-
<a name="schemaReadOnly"></a>readOnly | `boolean` | 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 MUST NOT be sent as part of the request. Properties marked as `readOnly` being `true` SHOULD NOT be in the `required` list of the defined schema. Default value is `false`.
2308+
<a name="schemaNullable"></a>nullable | `boolean` | Allows sending a `null` value for the defined schema. Default value is `false`.
2309+
<a name="schemaDiscriminator"></a>discriminator | `string` | Adds support for polymorphism. The discriminator is the schema property name that is used to differentiate between other schema that inherit this schema. The property name used MUST be defined at this schema and it MUST be in the `required` property list. When used, the value MUST be the name of this schema or any schema that inherits it. See [Composition and Inheritance](#schemaComposition) for more details.
2310+
<a name="schemaReadOnly"></a>readOnly | `boolean` | 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 MUST NOT be sent as part of the request. If 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`. Default value is `false`.
2311+
<a name="schemaWriteOnly"></a>writeOnly | `boolean` | Relevant only for Schema `"properties"` definitions. Declares the property as "write only". This means that it MAY be sent as part of a request but MUST NOT be sent as part of the response. If 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`. Default value is `false`.
23092312
<a name="schemaXml"></a>xml | [XML Object](#xmlObject) | This MAY be used only on properties schemas. It has no effect on root schemas. Adds Additional metadata to describe the XML representation format of this property.
23102313
<a name="schemaExternalDocs"></a>externalDocs | [External Documentation Object](#externalDocumentationObject) | Additional external documentation for this schema.
23112314
<a name="schemaExample"></a>example | Any | A free-form property to include an example of an instance for this schema.
@@ -2314,7 +2317,7 @@ Field Name | Type | Description
23142317

23152318
This object can be extended with [Specification Extensions](#specificationExtensions).
23162319

2317-
###### Composition and Inheritance (Polymorphism)
2320+
###### <a name="schemaComposition"></a>Composition and Inheritance (Polymorphism)
23182321

23192322
The OpenAPI Specification allows combining and extending model definitions using the `allOf` property of JSON Schema, in effect offering model composition.
23202323
`allOf` takes in an array of object definitions that are validated *independently* but together compose a single object.
@@ -2323,7 +2326,9 @@ While composition offers model extensibility, it does not imply a hierarchy betw
23232326
To support polymorphism, OpenAPI Specification adds the support of the `discriminator` field.
23242327
When used, the `discriminator` will be the name of the property used to decide which schema definition is used to validate the structure of the model.
23252328
As such, the `discriminator` field MUST be a required field.
2326-
The value of the chosen property has to be the friendly name given to the model under the `definitions` property.
2329+
There are are two ways to define the value of a discriminator for an inheriting instance.
2330+
- Use the definition's name.
2331+
- Override the definition's name by overriding the property with a new value. If exists, this takes precedence over the definition's name.
23272332
As such, inline schema definitions, which do not have a given id, *cannot* be used in polymorphism.
23282333

23292334
###### XML Modeling
@@ -2335,8 +2340,6 @@ The [XML Object](#xmlObject) contains additional information about the available
23352340

23362341
###### Primitive Sample
23372342

2338-
Unlike previous versions of Swagger, OpenAPI Schema definitions can be used to describe primitive and arrays as well.
2339-
23402343
```json
23412344
{
23422345
"type": "string",
@@ -2362,7 +2365,7 @@ format: email
23622365
"type": "string"
23632366
},
23642367
"address": {
2365-
"$ref": "#/definitions/Address"
2368+
"$ref": "#/components/definitions/Address"
23662369
},
23672370
"age": {
23682371
"type": "integer",
@@ -2381,7 +2384,7 @@ properties:
23812384
name:
23822385
type: string
23832386
address:
2384-
$ref: '#/definitions/Address'
2387+
$ref: '#/components/definitions/Address'
23852388
age:
23862389
type: integer
23872390
format: int32
@@ -2413,15 +2416,15 @@ For a string to model mapping:
24132416
{
24142417
"type": "object",
24152418
"additionalProperties": {
2416-
"$ref": "#/definitions/ComplexModel"
2419+
"$ref": "#/components/definitions/ComplexModel"
24172420
}
24182421
}
24192422
```
24202423

24212424
```yaml
24222425
type: object
24232426
additionalProperties:
2424-
$ref: '#/definitions/ComplexModel'
2427+
$ref: '#/components/definitions/ComplexModel'
24252428
```
24262429

24272430
###### Model with Example
@@ -2599,7 +2602,7 @@ definitions:
25992602
]
26002603
},
26012604
"Cat": {
2602-
"description": "A representation of a cat",
2605+
"description": "A representation of a cat. Note that `Cat` will be used as the discriminator value.",
26032606
"allOf": [
26042607
{
26052608
"$ref": "#/definitions/Pet"
@@ -2626,7 +2629,7 @@ definitions:
26262629
]
26272630
},
26282631
"Dog": {
2629-
"description": "A representation of a dog",
2632+
"description": "A representation of a dog. Note that `Dog` will be used as the discriminator value.",
26302633
"allOf": [
26312634
{
26322635
"$ref": "#/definitions/Pet"
@@ -2665,7 +2668,7 @@ definitions:
26652668
required:
26662669
- name
26672670
- petType
2668-
Cat:
2671+
Cat: ## "Cat" will be used as the discriminator value
26692672
description: A representation of a cat
26702673
allOf:
26712674
- $ref: '#/definitions/Pet'
@@ -2682,7 +2685,7 @@ definitions:
26822685
- aggressive
26832686
required:
26842687
- huntingSkill
2685-
Dog:
2688+
Dog: ## "Dog" will be used as the discriminator value
26862689
description: A representation of a dog
26872690
allOf:
26882691
- $ref: '#/definitions/Pet'

0 commit comments

Comments
 (0)