Skip to content

Commit 11fc80e

Browse files
authored
Merge pull request #3906 from handrews/implicit-304
Resolving implicit connections (3.0.4 port of #3856)
2 parents c5e6968 + 7dd7719 commit 11fc80e

File tree

1 file changed

+133
-1
lines changed

1 file changed

+133
-1
lines changed

versions/3.0.4.md

+133-1
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,50 @@ It is RECOMMENDED that the entry OpenAPI document be named: `openapi.json` or `o
166166

167167
When parsing an OAD, JSON or YAML objects are parsed into specific Objects (such as [Operation Objects](#operationObject), [Response Objects](#responseObject), [Reference Objects](#referenceObject), etc.) based on the parsing context. Depending on how references are arranged, a given JSON or YAML object can be parsed in multiple different contexts:
168168

169-
* As a full OpenAPI Description document (an [OpenAPI Object](#oasObject) taking up an entire document)
169+
* As a complete OpenAPI Description document
170170
* As the Object type implied by its parent Object within the document
171171
* As a reference target, with the Object type matching the reference source's context
172172

173173
If the same JSON/YAML object is parsed multiple times and the respective contexts require it to be parsed as _different_ Object types, the resulting behavior is _implementation defined_, and MAY be treated as an error if detected. An example would be referencing an empty Schema Object under `#/components/schemas` where a Path Item Object is expected, as an empty object is valid for both types. For maximum interoperability, it is RECOMMENDED that OpenAPI Description authors avoid such scenarios.
174174

175175
#### <a name="resolvingImplicitConnections"></a>Resolving Implicit Connections
176176

177+
Several features of this specification require resolution of non-URI-based connections to some other part of the OpenAPI Description (OAD).
178+
179+
These connections are unambiguously resolved in single-document OADs, but the resolution process in multi-document OADs is _implementation-defined_, within the constraints described in this section.
180+
In some cases, an unambiguous URI-based alternative is available, and OAD authors are RECOMMENDED to always use the alternative:
181+
182+
Source | Target | Alternative
183+
------ | ------ | -----------
184+
[Security Requirement Object](#securityRequirementObject) `{name}` | [Security Scheme Object](#securitySchemeObject) name under the [Components Object](#componentsObject) | _n/a_
185+
[Discriminator Object](#discriminatorObject) `mapping` _(implicit, or explicit name syntax)_ | [Schema Object](#schemaObject) name under the Components Object | `mapping` _(explicit URI syntax)_
186+
[Operation Object](#operationObject) `tags` | [Tag Object](#tagObject) `name` (in the Components Object) | _n/a_
187+
[Link Object](#linkObject) `operationId` | [Path Item Object](#pathItemObject) `operationId` | `operationRef`
188+
189+
A fifth implicit connection involves appending the templated URL paths of the [Paths Object](#pathsObject) to the appropriate [Server Object](#serverObject)'s `url` field.
190+
This is unambiguous because only the entry document's Paths Object contributes URLs to the described API.
191+
192+
It is RECOMMENDED to consider all Operation Objects from all parsed documents when resolving any Link Object `operationId`.
193+
This requires parsing all referenced documents prior to determining an `operationId` to be unresolvable.
194+
195+
The implicit connections in the Security Requirement Object and Discriminator Object rely on the _component name_, which is the property name holding the component in the appropriately typed sub-object of the Components Object.
196+
For example, the component name of the Schema Object at `#/components/schemas/Foo` is `Foo`.
197+
The implicit connection of `tags` in the Operation Object uses the `name` field of Tag Objects, which (like the Components Object) are found under the root OpenAPI Object.
198+
This means resolving component names and tag names both depend on starting from the correct OpenAPI Object.
199+
200+
For resolving component and tag name connections from a referenced (non-entry) document, it is RECOMMENDED that tools resolve from the entry document, rather than the current document.
201+
This allows Security Scheme Objects and Tag Objects to be defined with the API's deployment information (the top-level Server Objects), and treated as an interface for referenced documents to access.
202+
203+
The interface approach can also work for Discriminator Objects and Schema Objects, but it is also possible to keep the Discriminator Object's behavior within a single document using the relative URI-reference syntax of `mapping`.
204+
205+
There are no URI-based alternatives for the Security Requirement Object or for the Operation Object's `tags` field.
206+
These limitations are expected to be addressed in a future release.
207+
208+
See [Security Requirement in a Referenced Document](#security-requirement-in-a-referenced-document) for an example of the possible resolutions, including which one is recommended by this section.
209+
The behavior for Discrimator Object non-URI mappings and for the Operation Object's `tags` field operate on the same principles.
210+
211+
Note that no aspect of implicit connection resolution changes how [URLs are resolved](#relativeReferences), or restricts their possible targets.
212+
177213
### <a name="dataTypes"></a>Data Types
178214

179215
Primitive data types in the OAS are based on the types supported by the [JSON Schema Specification Wright Draft 00](https://tools.ietf.org/html/draft-wright-json-schema-00#section-4.2).
@@ -3768,6 +3804,102 @@ security:
37683804
- read:pets
37693805
```
37703806

3807+
###### Security Requirement in a Referenced Document
3808+
3809+
See [Resolving Implicit Connections](#resolvingImplicitConnections) for more information.
3810+
3811+
First, our entry document is where parsing begins. It defines the `MySecurity` security scheme to be JWT-based, and it defines a Path Item as a reference to a component in another document:
3812+
3813+
```HTTP
3814+
GET /api/description/openapi HTTP/1.1
3815+
Host: www.example.com
3816+
Accept: application/openapi+json
3817+
```
3818+
3819+
```json
3820+
"components": {
3821+
"securitySchemes": {
3822+
"MySecurity": {
3823+
"type": "http",
3824+
"scheme": "bearer",
3825+
"bearerFormat": "JWT"
3826+
}
3827+
}
3828+
},
3829+
"paths": {
3830+
"/foo": {
3831+
"$ref": "other#/components/pathItems/Foo"
3832+
}
3833+
}
3834+
```
3835+
3836+
```HTTP
3837+
GET /api/description/openapi HTTP/1.1
3838+
Host: www.example.com
3839+
Accept: application/openapi+yaml
3840+
```
3841+
3842+
```yaml
3843+
components:
3844+
securitySchemes:
3845+
MySecurity:
3846+
type: http
3847+
scheme: bearer
3848+
bearerFormat: JWT
3849+
paths:
3850+
/foo:
3851+
$ref: "other#/components/pathItems/Foo"
3852+
```
3853+
3854+
Next, we have our referenced document, `other`. The fact that we don't use file extensions gives the client the flexibility to choose an acceptable format on a resource-by-resource basis, assuming both representations are available:
3855+
3856+
```HTTP
3857+
GET /api/description/other HTTP/1.1
3858+
Host: www.example.com
3859+
Accept: application/openapi+json
3860+
```
3861+
3862+
```json
3863+
"components": {
3864+
"securitySchemes": {
3865+
"MySecurity": {
3866+
"type": "http",
3867+
"scheme": "basic"
3868+
}
3869+
},
3870+
"pathItems": {
3871+
"Foo": {
3872+
"get": {
3873+
"security": [
3874+
"MySecurity": []
3875+
]
3876+
}
3877+
}
3878+
}
3879+
}
3880+
```
3881+
3882+
```HTTP
3883+
GET /api/description/other HTTP/1.1
3884+
Host: www.example.com
3885+
Accept: application/openapi+yaml
3886+
```
3887+
3888+
```yaml
3889+
components:
3890+
securitySchemes:
3891+
MySecurity:
3892+
type: http
3893+
scheme: basic
3894+
pathItems:
3895+
Foo:
3896+
get:
3897+
security:
3898+
- MySecurity: []
3899+
```
3900+
3901+
In the `other` document, the referenced path item has a Security Requirement for a Security Scheme, `MySecurity`. The same Security Scheme exists in the original entry document. As outlined in [Resolving Implicit Connections](#resolvingImplicitConnections), `MySecurity` is resolved with an [implementation-defined behavior](#undefinedAndImplementationDefinedBehavior). However, documented in that section, it is RECOMMENDED that tools resolve component names from the [entry document](#documentStructure). As with all implementation-defined behavior, it is important to check tool documentation to determine which behavior is supported.
3902+
37713903
### <a name="specificationExtensions"></a>Specification Extensions
37723904

37733905
While the OpenAPI Specification tries to accommodate most use cases, additional data can be added to extend the specification at certain points.

0 commit comments

Comments
 (0)