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
Copy file name to clipboardExpand all lines: versions/3.0.md
+50-43
Original file line number
Diff line number
Diff line change
@@ -144,14 +144,15 @@ By convention, the OpenAPI Specification (OAS) file is named `openapi.json` or `
144
144
145
145
### Data Types
146
146
147
-
Primitive data types in the OAS are based on the types supported by the [JSON-Schema Draft 4](http://json-schema.org/latest/json-schema-core.html#anchor8).
148
-
Models are described using the [Schema Object](#schemaObject) which is a subset of JSON Schema Draft 4.
147
+
Primitive data types in the OAS are based on the types supported by the [JSONSchema Specification Wright Draft 00](https://tools.ietf.org/html/draft-wright-json-schema-00#section-4.2). Note that `integer` as a type is also supported and is defined as a JSON number without a fraction or exponent part. `null` is not supported as a value.
148
+
Models are described using the [Schema Object](#schemaObject) which is an extended subset of JSON Schema Specification Wright Draft 00.
149
149
150
150
<aname="dataTypeFormat"></a>Primitives have an optional modifier property `format`.
151
151
OAS uses several known formats to more finely define the data type being used.
152
152
However, the `format` property is an open `string`-valued property, and can have any value to support documentation needs.
153
153
Formats such as `"email"`, `"uuid"`, etc., can be used even though they are not defined by this specification.
154
-
Types that are not accompanied by a `format` property follow their definition from the JSON Schema.
154
+
Types that are not accompanied by a `format` property follow their definition from the JSON Schema. Tools that do not recognize a specific `format` MAY default back to the `type` alone, as if the `format` was not specified.
A simple object to allow referencing other definitions in the specification.
2234
-
It can be used to reference parameters and responses that are defined at the top level for reuse.
2234
+
A simple object to allow referencing other definitions in the specification, internally and externally.
2235
+
2236
+
The Reference Object is defined by [JSON Reference](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03) and follows the same structure, behavior and rules.
2235
2237
2236
-
The Reference Object is a [JSON Reference](http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-02) that uses a [JSON Pointer](http://tools.ietf.org/html/rfc6901) as its value.
2237
-
For this specification, only [canonical dereferencing](http://json-schema.org/latest/json-schema-core.html#anchor27) is supported.
2238
+
For this specification, reference resolution is done as defined by the JSON Reference specification and not by the JSON Schema specification.
2238
2239
2239
2240
##### Fixed Fields
2240
2241
Field Name | Type | Description
2241
2242
---|:---:|---
2242
2243
<a name="referenceRef"></a>$ref | `string` | **Required.** The reference string.
2243
2244
2245
+
This object cannot be extended with additional properties and any properties added SHALL be ignored.
2246
+
2244
2247
##### Reference Object Example
2245
2248
2246
2249
```json
2247
2250
{
2248
-
"$ref": "#/definitions/Pet"
2251
+
"$ref": "#/components/definitions/Pet"
2249
2252
}
2250
2253
```
2251
2254
2252
2255
```yaml
2253
-
$ref: '#/definitions/Pet'
2256
+
$ref: '#/components/definitions/Pet'
2254
2257
```
2255
2258
2256
2259
##### Relative Schema File Example
@@ -2261,7 +2264,7 @@ $ref: '#/definitions/Pet'
2261
2264
```
2262
2265
2263
2266
```yaml
2264
-
$ref: 'Pet.yaml'
2267
+
$ref: Pet.yaml
2265
2268
```
2266
2269
2267
2270
##### Relative Files With Embedded Schema Example
@@ -2272,25 +2275,21 @@ $ref: 'Pet.yaml'
2272
2275
```
2273
2276
2274
2277
```yaml
2275
-
$ref: 'definitions.yaml#/Pet'
2278
+
$ref: definitions.yaml#/Pet
2276
2279
```
2277
2280
2278
2281
#### <a name="schemaObject"></a>Schema Object
2279
2282
2280
2283
The Schema Object allows the definition of input and output data types.
2281
2284
These types can be objects, but also primitives and arrays.
2282
-
This object is based on the [JSON Schema Specification Draft 4](http://json-schema.org/) and uses a predefined subset of it.
2283
-
On top of this subset, there are extensions provided by this specification to allow for more complete documentation.
2285
+
This object is an extended subset of the [JSON Schema Specification Wright Draft 00](http://json-schema.org/).
2284
2286
2285
-
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).
2287
+
Further information about the properties can be found in [JSON Schema Core](https://tools.ietf.org/html/draft-wright-json-schema-00) and [JSON Schema Validation](https://tools.ietf.org/html/draft-wright-json-schema-validation-00).
2286
2288
Unless stated otherwise, the property definitions follow the JSON Schema specification as referenced here.
2287
2289
2288
2290
The following properties are taken directly from the JSON Schema definition and follow the same specifications:
2289
-
- $ref - As a [JSON Reference](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03)
2290
-
- format (See [Data Type Formats](#dataTypeFormat) for further details)
2291
+
2291
2292
- title
2292
-
- description ([CommonMark syntax](http://spec.commonmark.org/) can be used for rich text representation)
2293
-
- default (Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object)
2294
2293
- multipleOf
2295
2294
- maximum
2296
2295
- exclusiveMaximum
@@ -2306,25 +2305,33 @@ The following properties are taken directly from the JSON Schema definition and
2306
2305
- minProperties
2307
2306
- required
2308
2307
- enum
2309
-
- type
2310
-
2311
-
The following properties are taken from the JSON Schema definition but their definitions were adjusted to the OpenAPI Specification.
2312
-
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.
2313
-
- items
2314
-
- allOf
2315
-
- oneOf
2316
-
- anyOf
2317
-
- not
2318
-
- properties
2319
-
- additionalProperties
2308
+
2309
+
The following properties are taken from the JSON Schema definition but their definitions were adjusted to the OpenAPI Specification.
2310
+
- type - Value MUST be a string. Multiple types via an array are not supported.
2311
+
- allOf - Inline or referenced schema MUST be of a [Schema Object](#schemaObject) and not a standard JSON Schema.
2312
+
- oneOf - Inline or referenced schema MUST be of a [Schema Object](#schemaObject) and not a standard JSON Schema.
2313
+
- anyOf - Inline or referenced schema MUST be of a [Schema Object](#schemaObject) and not a standard JSON Schema.
2314
+
- not - Inline or referenced schema MUST be of a [Schema Object](#schemaObject) and not a standard JSON Schema.
2315
+
- 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 if the `type` is `array`.
2316
+
- properties - Property definitions MUST be a [Schema Object](#schemaObject) and not a standard JSON Schema (inline or referenced).
2317
+
- additionalProperties - Value can be boolean or object. Inline or referenced schema MUST be of a [Schema Object](#schemaObject) and not a standard JSON Schema.
2318
+
- description - [CommonMark syntax](http://spec.commonmark.org/) can be used for rich text representation.
2319
+
- 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.
2320
+
- default - The default value represents what would be assumed by the consumer of the input as the value of the schema if one is not provided. Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level. For example, of `type` is `string`, then `default` can be `"foo"`` but cannot be `1`.
2321
+
2322
+
Alternatively, any time a Scheme Object can be used, a [Reference Object](#referenceObject) can be used in its place. This allows referencing definitions in place of defining them inline.
2323
+
2324
+
Additional properties defined by the JSON Schema specification that are not mentioned here are strictly unsupported.
2320
2325
2321
2326
Other than the JSON Schema subset fields, the following fields may be used for further schema documentation.
2322
2327
2323
2328
##### Fixed Fields
2324
2329
Field Name | Type | Description
2325
2330
---|:---:|---
2326
-
<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.
2327
-
<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`.
2331
+
<a name="schemaNullable"></a>nullable | `boolean` | Allows sending a `null` value for the defined schema. Default value is `false`.
2332
+
<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.
2333
+
<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 SHOULD 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`.
2334
+
<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 SHOULD 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`.
2328
2335
<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.
2329
2336
<a name="schemaExternalDocs"></a>externalDocs | [External Documentation Object](#externalDocumentationObject) | Additional external documentation for this schema.
2330
2337
<a name="schemaExample"></a>example | Any | A free-form property to include an example of an instance for this schema.
@@ -2333,7 +2340,7 @@ Field Name | Type | Description
2333
2340
2334
2341
This object can be extended with [Specification Extensions](#specificationExtensions).
2335
2342
2336
-
###### Composition and Inheritance (Polymorphism)
2343
+
###### <a name="schemaComposition"></a>Composition and Inheritance (Polymorphism)
2337
2344
2338
2345
The OpenAPI Specification allows combining and extending model definitions using the `allOf` property of JSON Schema, in effect offering model composition.
2339
2346
`allOf`takes in an array of object definitions that are validated *independently* but together compose a single object.
@@ -2342,7 +2349,9 @@ While composition offers model extensibility, it does not imply a hierarchy betw
2342
2349
To support polymorphism, OpenAPI Specification adds the support of the `discriminator` field.
2343
2350
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.
2344
2351
As such, the `discriminator` field MUST be a required field.
2345
-
The value of the chosen property has to be the friendly name given to the model under the `definitions` property.
2352
+
There are are two ways to define the value of a discriminator for an inheriting instance.
2353
+
- Use the definition's name.
2354
+
- Override the definition's name by overriding the property with a new value. If exists, this takes precedence over the definition's name.
2346
2355
As such, inline schema definitions, which do not have a given id, *cannot* be used in polymorphism.
2347
2356
2348
2357
###### XML Modeling
@@ -2354,8 +2363,6 @@ The [XML Object](#xmlObject) contains additional information about the available
2354
2363
2355
2364
###### Primitive Sample
2356
2365
2357
-
Unlike previous versions of Swagger, OpenAPI Schema definitions can be used to describe primitive and arrays as well.
2358
-
2359
2366
```json
2360
2367
{
2361
2368
"type": "string",
@@ -2381,7 +2388,7 @@ format: email
2381
2388
"type": "string"
2382
2389
},
2383
2390
"address": {
2384
-
"$ref": "#/definitions/Address"
2391
+
"$ref": "#/components/definitions/Address"
2385
2392
},
2386
2393
"age": {
2387
2394
"type": "integer",
@@ -2400,7 +2407,7 @@ properties:
2400
2407
name:
2401
2408
type: string
2402
2409
address:
2403
-
$ref: '#/definitions/Address'
2410
+
$ref: '#/components/definitions/Address'
2404
2411
age:
2405
2412
type: integer
2406
2413
format: int32
@@ -2432,15 +2439,15 @@ For a string to model mapping:
2432
2439
{
2433
2440
"type": "object",
2434
2441
"additionalProperties": {
2435
-
"$ref": "#/definitions/ComplexModel"
2442
+
"$ref": "#/components/definitions/ComplexModel"
2436
2443
}
2437
2444
}
2438
2445
```
2439
2446
2440
2447
```yaml
2441
2448
type: object
2442
2449
additionalProperties:
2443
-
$ref: '#/definitions/ComplexModel'
2450
+
$ref: '#/components/definitions/ComplexModel'
2444
2451
```
2445
2452
2446
2453
###### Model with Example
@@ -2618,7 +2625,7 @@ definitions:
2618
2625
]
2619
2626
},
2620
2627
"Cat": {
2621
-
"description": "A representation of a cat",
2628
+
"description": "A representation of a cat. Note that `Cat` will be used as the discriminator value.",
2622
2629
"allOf": [
2623
2630
{
2624
2631
"$ref": "#/definitions/Pet"
@@ -2645,7 +2652,7 @@ definitions:
2645
2652
]
2646
2653
},
2647
2654
"Dog": {
2648
-
"description": "A representation of a dog",
2655
+
"description": "A representation of a dog. Note that `Dog` will be used as the discriminator value.",
2649
2656
"allOf": [
2650
2657
{
2651
2658
"$ref": "#/definitions/Pet"
@@ -2684,7 +2691,7 @@ definitions:
2684
2691
required:
2685
2692
- name
2686
2693
- petType
2687
-
Cat:
2694
+
Cat:## "Cat" will be used as the discriminator value
2688
2695
description: A representation of a cat
2689
2696
allOf:
2690
2697
- $ref: '#/definitions/Pet'
@@ -2701,7 +2708,7 @@ definitions:
2701
2708
- aggressive
2702
2709
required:
2703
2710
- huntingSkill
2704
-
Dog:
2711
+
Dog:## "Dog" will be used as the discriminator value
0 commit comments