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: src/oas.md
+28-5Lines changed: 28 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -4928,19 +4928,36 @@ In the `other` document, the referenced path item has a Security Requirement for
4928
4928
A base URI within the resource's content (RFC3986 Section 5.1.1) is the highest-precedence source of a base URI.
4929
4929
For OpenAPI Documents, this source is the OpenAPI Object's `$self` field, while for Schema Objects that contain a `$id`, or are a subschema of a Schema Object containing a `$id`, the source is the `$id` field:
4930
4930
4931
+
Assume the retrieval URI of the following document is `file://home/someone/src/api/openapi.yaml`:
4932
+
4931
4933
```YAML
4932
4934
openapi: 3.2.0
4933
-
$self: https://example.com/openapi
4935
+
$self: https://example.com/api/openapi
4934
4936
info:
4935
4937
title: Example API
4936
4938
version: 1.0
4939
+
paths:
4940
+
/foo:
4941
+
get:
4942
+
requestBody:
4943
+
$ref: "shared#/components/requestBodies/Foo"
4944
+
```
4945
+
4946
+
Assume the retrieval URI for the following document is `https://git.example.com/shared/blob/main/shared/foo.yaml`:
4947
+
4948
+
```YAML
4949
+
openapi: 3.2.0
4950
+
$self: https://example.com/api/shared/foo
4951
+
info:
4952
+
title: Shared components for all APIs
4953
+
version: 1.0
4937
4954
components:
4938
4955
requestBodies:
4939
4956
Foo:
4940
4957
content:
4941
4958
application/json:
4942
4959
schema:
4943
-
$ref: schemas/foo
4960
+
$ref: ../schemas/foo
4944
4961
schemas:
4945
4962
Foo:
4946
4963
$id: https://example.com/api/schemas/foo
@@ -4952,7 +4969,12 @@ components:
4952
4969
type: string
4953
4970
```
4954
4971
4955
-
In the example above, the `$ref` in the Request Body Object is resolved using `$self` as the base URI, producing `https://example.com/schemas/foo`.
4972
+
In this example, the retrieval URIs are irrelevant because both documents define `$self`.
4973
+
4974
+
For the relative `$ref` in the first document, it is resolved against `$self` to produce `https://example.com/shared/foo#/components/requestBodies/Foo`.
4975
+
The portion of that URI before the '#' matches the `$self` of the second document, so the reference target is resolved to `#/components/requestBodies/Foo` in that second document.
4976
+
4977
+
In that document, the `$ref` in the Request Body Object is resolved using that document's `$self` as the base URI, producing `https://example.com/schemas/foo`.
4956
4978
This matches the `$id` at `#/components/schemas/Foo/$id` so it points to that Schema Object.
4957
4979
That Schema Object has a subschema with `$ref: bar`, which is resolved against the `$id` to produce `https://example.com/schemas/bar`, which matches the `$id` at `#/components/schemas/Bar/$id`.
4958
4980
@@ -4962,7 +4984,6 @@ Therefore it is RECOMMENDED that OAD authors use `$id` values to reference such
4962
4984
4963
4985
Note also that it is impossible for the reference at `#/components/schemas/Foo/properties/bar/$ref` to reference the schema at `#/components/schemas/Bar` using a JSON Pointer, as the JSON Pointer would be resolved relative to `https://example.com/schemas/foo`, not to the OpenAPI Document's base URI from `$self`.
4964
4986
4965
-
4966
4987
### Base URI From Encapsulating Entity
4967
4988
4968
4989
If no base URI can be determined within the content, the next ___location to search is any encapsulating entity (RFC3986 Section 5.1.2).
@@ -4971,6 +4992,8 @@ This is common for Schema Objects encapsulated within an OpenAPI Document.
4971
4992
An example of an OpenAPI Document itself being encapsulated in another entity would be a `multipart/related` archive ([[?RFC2557]]), such as the following `multipart/related; boundary="boundary-example"; type="application/openapi+yaml"` document.
4972
4993
Note that this is purely an example, and support for such multipart documents or any other format that could encapsulate an OpenAPI Document is not a requirement of this specification.
4973
4994
4995
+
RFC2557 was written to allow sending hyperlinked sets of documents as email attachments, in which case there would not be a retrieval URI for the multipart attachment (although the format could also be used in HTTP as well).
In this example, the URI for each part, which also serves as its base URI, comes from the part's `Content-Location` header as specified by RFC2557.
5020
5043
Since the Schema Object at `#/components/schemas/Foo` does not contain an `$id`, the reference in its subschema uses the OpenAPI Document's base URI, which is taken from the `Content-Location` header of its part within the `multipart/related` format.
5021
-
The resulting reference to `https://example.com/schemas/bar` matches the `Content-Location` header of the second part, which allows the reference target to be located within the multipart archive.
5044
+
The resulting reference to `https://example.com/schemas/bar` matches the `Content-Location` header of the second part, which according to RFC2557 allows the reference target to be located within the multipart archive.
5022
5045
5023
5046
Similarly, the `url` field of the [External Documentation Object](#external-documentation-object) is resolved against the base URI from `Content-Location`, producing `https://example.com/api/docs.html` which matches the `Content-Location` of the third part.
0 commit comments