Skip to content

Commit 478607b

Browse files
OAS schema dialect clarifications (#2399)
* OAS schema dialect clarifications * OAS schema dialect clarifications Signed-off-by: Mike Ralphson <[email protected]> * $schema is allowed in subschemas when bundling Co-authored-by: Ben Hutton <[email protected]> * Schema dialect clarifications from Ben Signed-off-by: Mike Ralphson <[email protected]> * Use top-level jsonSchemaDialect field Co-authored-by: Ben Hutton <[email protected]>
1 parent 1cd5687 commit 478607b

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

versions/3.1.0.md

+19-13
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ In order to preserve the ability to round-trip between YAML and JSON formats, YA
135135

136136
### <a name="documentStructure"></a>Document Structure
137137

138-
An OpenAPI document MAY be made up of a single document or be divided into multiple, connected parts at the discretion of the user. In the latter case, `$ref` fields MUST be used in the specification to reference those parts as follows from the [JSON Schema](https://json-schema.org) definitions.
138+
An OpenAPI document MAY be made up of a single document or be divided into multiple, connected parts at the discretion of the user. In the latter case, `$ref` fields MUST be used in the OAS document to reference those parts as follows from the [JSON Schema](https://json-schema.org/draft/2019-09/json-schema-core.html#references) definitions.
139139

140140
It is RECOMMENDED that the root OpenAPI document be named: `openapi.json` or `openapi.yaml`.
141141

142142
### <a name="dataTypes"></a>Data Types
143143

144-
Data types in the OAS are based on the types supported by the [JSON Schema Specification Draft 2019-09](http://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2).
144+
Data types in the OAS are based on the types supported by the [JSON Schema Specification Draft 2019-09](https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2).
145145
Note that `integer` as a type is also supported and is defined as a JSON number without a fraction or exponent part.
146146
Models are defined using the [Schema Object](#schemaObject), which is a superset of JSON Schema Specification Draft 2019-09.
147147

@@ -183,6 +183,7 @@ Field Name | Type | Description
183183
---|:---:|---
184184
<a name="oasVersion"></a>openapi | `string` | **REQUIRED**. This string MUST be the [version number](#versions) of the OpenAPI Specification that the OpenAPI document uses. The `openapi` field SHOULD be used by tooling to interpret the OpenAPI document. This is *not* related to the API [`info.version`](#infoVersion) string.
185185
<a name="oasInfo"></a>info | [Info Object](#infoObject) | **REQUIRED**. Provides metadata about the API. The metadata MAY be used by tooling as required.
186+
<a name="oasJsonSchemaDialect"></a> jsonSchemaDialect | `string` | The default value for the `$schema` keyword within [Schema Objects](#schemaObject) contained within this OAS document. MUST be in the form of a URI.
186187
<a name="oasServers"></a>servers | [[Server Object](#serverObject)] | An array of Server Objects, which provide connectivity information to a target server. If the `servers` property is not provided, or is an empty array, the default value would be a [Server Object](#serverObject) with a [url](#serverUrl) value of `/`.
187188
<a name="oasPaths"></a>paths | [Paths Object](#pathsObject) | The available paths and operations for the API.
188189
<a name="oasWebhooks"></a>webhooks | Map[`string`, [Path Item Object](#pathItemObject) \| [Reference Object](#referenceObject)] ] | The incoming webhooks that MAY be received as part of this API and that the API consumer MAY choose to implement. Closely related to the `callbacks` feature, this section describes requests initiated other than by an API call, for example by an out of band registration. The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses. An [example](../examples/v3.1/webhook-example.yaml) is available.
@@ -642,7 +643,6 @@ components:
642643
read:pets: read your pets
643644
```
644645

645-
646646
#### <a name="pathsObject"></a>Paths Object
647647

648648
Holds the relative paths to the individual endpoints and their operations.
@@ -2289,7 +2289,7 @@ $ref: definitions.yaml#/Pet
22892289
#### <a name="schemaObject"></a>Schema Object
22902290

22912291
The Schema Object allows the definition of input and output data types.
2292-
These types can be objects, but also primitives and arrays. This object is a superset of the [JSON Schema Specification Draft 2019-09](http://json-schema.org/).
2292+
These types can be objects, but also primitives and arrays. This object is a superset of the [JSON Schema Specification Draft 2019-09](https://json-schema.org/specification-links.html#2019-09-formerly-known-as-draft-8).
22932293

22942294
For more information about the properties, see [JSON Schema Core](https://json-schema.org/draft/2019-09/json-schema-core.html) and [JSON Schema Validation](https://json-schema.org/draft/2019-09/json-schema-validation.html).
22952295

@@ -2298,16 +2298,20 @@ Where JSON Schema indicates that behavior is defined by the application (e.g. fo
22982298

22992299
##### Properties
23002300

2301-
The OpenAPI Schema Object is a JSON Schema vocabulary which extends JSON Schema Core and Validation vocabularies. As such any keyword available for those vocabularies is by definition available in OpenAPI, and will work the exact same way.
2301+
The OpenAPI Schema Object [dialect](https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.3.3) is defined as requiring the [OAS base vocabulary](#baseVocabulary), in addition to the vocabularies as specified in the JSON Schema draft 2019-09 [general purpose meta-schema](http://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.8).
2302+
2303+
The OpenAPI Schema Object dialect for this version of the specification is identified by the URI `https://spec.openapis.org/oas/3.1/dialect/base` (the <a name="dialectSchemaId"></a>"OAS dialect schema id").
23022304

2303-
The following properties are taken from the JSON Schema definition but their definitions were adjusted to the OpenAPI Specification.
2305+
The following properties are taken from the JSON Schema specification but their definitions have been extended by the OAS:
23042306

23052307
- description - [CommonMark syntax](http://spec.commonmark.org/) MAY be used for rich text representation.
23062308
- 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.
23072309

2308-
In addition to the JSON Schema properties defined in the vocabularies defined in the JSON Schema Core and JSON Schema Validation specifications, any properties can be used from any vocabularies, or entirely arbitrary keywords. The OpenAPI Specification defines an additional vocabulary of keywords which MAY be used along with the JSON Schema vocabulary keywords for further schema description:
2310+
In addition to the JSON Schema properties comprising the OAS dialect, the Schema Object supports keywords from any other vocabularies, or entirely arbitrary properties.
23092311

2310-
##### Fixed Fields
2312+
The OpenAPI Specification's base vocabulary is comprised of the following keywords:
2313+
2314+
##### <a name="baseVocabulary"></a>Fixed Fields
23112315

23122316
Field Name | Type | Description
23132317
---|:---:|---
@@ -2316,7 +2320,7 @@ Field Name | Type | Description
23162320
<a name="schemaExternalDocs"></a>externalDocs | [External Documentation Object](#externalDocumentationObject) | Additional external documentation for this schema.
23172321
<a name="schemaExample"></a>example | Any | A free-form property to include an example of an instance for this schema. To represent examples that cannot be naturally represented in JSON or YAML, a string value can be used to contain the example with escaping where necessary.<br><br>**Deprecated:** The `example` property has been deprecated in favor of the JSON Schema `examples` keyword. Use of `example` is discouraged, and later versions of this specification may remove it.
23182322

2319-
This object MAY be extended with [Specification Extensions](#specificationExtensions).
2323+
This object MAY be extended with [Specification Extensions](#specificationExtensions), though as noted, additional properties MAY omit the `x-` prefix within this object.
23202324

23212325
###### <a name="schemaComposition"></a>Composition and Inheritance (Polymorphism)
23222326

@@ -2337,13 +2341,15 @@ As such, inline schema definitions, which do not have a given id, *cannot* be us
23372341
The [xml](#schemaXml) property allows extra definitions when translating the JSON definition to XML.
23382342
The [XML Object](#xmlObject) contains additional information about the available options.
23392343

2340-
###### Picking Schema Vocabularies
2344+
###### Specifiying Schema Dialects
2345+
2346+
It is important for tooling to be able to determine which dialect or meta-schema any given resource wishes to be processed with: JSON Schema Core, JSON Schema Validation, OpenAPI Schema dialect, or some custom meta-schema.
23412347

2342-
It is important for tooling to be able to detect what meta-schema any given resource wishes to be processed with: JSON Schema Core, JSON Schema Validation, OpenAPI Schema Object, or some custom meta schema.
2348+
The `$schema` keyword MAY be present in any root Schema Object, and if present MUST be used to determine which dialect should be used when processing the schema. This allows use of Schema Objects which comply with other drafts of JSON Schema than the default Draft 2019-09 support. Tooling MUST support the <a href="#dialectSchemaId">OAS dialect schema id</a>, and MAY support additional values of `$schema`.
23432349

2344-
`$schema` MAY be present in any Schema Object, and if present MUST be used to determine which dialect should be used when processing the schema.
2350+
To allow use of a different default `$schema` value for all Schema Objects contained within an OAS document, a `jsonSchemaDialect` value may be set within the <a href="#oasObject">OpenAPI Object</a>. If this default is not set, then the OAS dialact schema id MUST be used for these Schema Objects. The value of `$schema` within a Schema Object always overrides any default.
23452351

2346-
When `$schema` is not present, the default the following dialect MUST be assumed: `$schema: "https://spec.openapis.org/oas/3.1/schema-object"`.
2352+
When a Schema Object is referenced from an external resource which is not an OAS document (e.g. a bare JSON Schema resource), then the value of the `$schema` keyword for schemas within that resource MUST follow [JSON Schema rules](https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.8.1.1).
23472353

23482354
##### Schema Object Examples
23492355

0 commit comments

Comments
 (0)