You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Schema Object allows the definition of input and output data types.
2262
2262
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/).
2265
2264
2266
2265
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).
2267
2266
Unless stated otherwise, the property definitions follow the JSON Schema specification as referenced here.
2268
2267
2269
2268
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
+
2272
2270
- 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)
2275
2271
- multipleOf
2276
2272
- maximum
2277
2273
- exclusiveMaximum
@@ -2287,25 +2283,32 @@ The following properties are taken directly from the JSON Schema definition and
2287
2283
- minProperties
2288
2284
- required
2289
2285
- 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.
2301
2302
2302
2303
Other than the JSON Schema subset fields, the following fields may be used for further schema documentation.
2303
2304
2304
2305
##### Fixed Fields
2305
2306
Field Name | Type | Description
2306
2307
---|:---:|---
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`.
2309
2312
<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.
2310
2313
<a name="schemaExternalDocs"></a>externalDocs | [External Documentation Object](#externalDocumentationObject) | Additional external documentation for this schema.
2311
2314
<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
2314
2317
2315
2318
This object can be extended with [Specification Extensions](#specificationExtensions).
2316
2319
2317
-
###### Composition and Inheritance (Polymorphism)
2320
+
###### <a name="schemaComposition"></a>Composition and Inheritance (Polymorphism)
2318
2321
2319
2322
The OpenAPI Specification allows combining and extending model definitions using the `allOf` property of JSON Schema, in effect offering model composition.
2320
2323
`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
2323
2326
To support polymorphism, OpenAPI Specification adds the support of the `discriminator` field.
2324
2327
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.
2325
2328
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.
2327
2332
As such, inline schema definitions, which do not have a given id, *cannot* be used in polymorphism.
2328
2333
2329
2334
###### XML Modeling
@@ -2335,8 +2340,6 @@ The [XML Object](#xmlObject) contains additional information about the available
2335
2340
2336
2341
###### Primitive Sample
2337
2342
2338
-
Unlike previous versions of Swagger, OpenAPI Schema definitions can be used to describe primitive and arrays as well.
2339
-
2340
2343
```json
2341
2344
{
2342
2345
"type": "string",
@@ -2362,7 +2365,7 @@ format: email
2362
2365
"type": "string"
2363
2366
},
2364
2367
"address": {
2365
-
"$ref": "#/definitions/Address"
2368
+
"$ref": "#/components/definitions/Address"
2366
2369
},
2367
2370
"age": {
2368
2371
"type": "integer",
@@ -2381,7 +2384,7 @@ properties:
2381
2384
name:
2382
2385
type: string
2383
2386
address:
2384
-
$ref: '#/definitions/Address'
2387
+
$ref: '#/components/definitions/Address'
2385
2388
age:
2386
2389
type: integer
2387
2390
format: int32
@@ -2413,15 +2416,15 @@ For a string to model mapping:
2413
2416
{
2414
2417
"type": "object",
2415
2418
"additionalProperties": {
2416
-
"$ref": "#/definitions/ComplexModel"
2419
+
"$ref": "#/components/definitions/ComplexModel"
2417
2420
}
2418
2421
}
2419
2422
```
2420
2423
2421
2424
```yaml
2422
2425
type: object
2423
2426
additionalProperties:
2424
-
$ref: '#/definitions/ComplexModel'
2427
+
$ref: '#/components/definitions/ComplexModel'
2425
2428
```
2426
2429
2427
2430
###### Model with Example
@@ -2599,7 +2602,7 @@ definitions:
2599
2602
]
2600
2603
},
2601
2604
"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.",
2603
2606
"allOf": [
2604
2607
{
2605
2608
"$ref": "#/definitions/Pet"
@@ -2626,7 +2629,7 @@ definitions:
2626
2629
]
2627
2630
},
2628
2631
"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.",
2630
2633
"allOf": [
2631
2634
{
2632
2635
"$ref": "#/definitions/Pet"
@@ -2665,7 +2668,7 @@ definitions:
2665
2668
required:
2666
2669
- name
2667
2670
- petType
2668
-
Cat:
2671
+
Cat:## "Cat" will be used as the discriminator value
2669
2672
description: A representation of a cat
2670
2673
allOf:
2671
2674
- $ref: '#/definitions/Pet'
@@ -2682,7 +2685,7 @@ definitions:
2682
2685
- aggressive
2683
2686
required:
2684
2687
- huntingSkill
2685
-
Dog:
2688
+
Dog:## "Dog" will be used as the discriminator value
0 commit comments