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
These media types solve our long-standing problems with modeling
HTTP Link headers. We do not need to define anything beyond
noting how to use them media types in a Media Type Ojbect.
Copy file name to clipboardExpand all lines: src/oas.md
+62Lines changed: 62 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2451,6 +2451,67 @@ Using `content` with a `text/plain` media type is RECOMMENDED for headers where
2451
2451
| ---- | :----: | ---- |
2452
2452
| <aname="header-content"></a>content | Map[`string`, [Media Type Object](#media-type-object)]| A map containing the representations for the header. The key is the media type and the value describes it. The map MUST only contain one entry. |
2453
2453
2454
+
##### Modeling Link Headers
2455
+
2456
+
[[!RFC9264]] defines the `application/linkset` and `application/linkset+json` media types.
2457
+
The former is exactly the format of HTTP link header values except allowing additional whitespace for readability, while the latter is an equivalent JSON representation of such headers.
2458
+
2459
+
To use either of these media types, the `schema` in the [Media Type Object](#media-type-object) MUST describe the links as they would be structured in the `application/linkset+json` format.
2460
+
If the Media Type Object's parent key is `application/linkset+json`, then the serialization is trivial, however this format cannot be used in the HTTP `Link` header.
2461
+
If the Media Type Object's parent key is `application/linkset`, then the serialization MUST be the equivalent representation of the `schema`-modeled links in the `application/linkset` format.
2462
+
If the `application/linkset` Media Type Object is used in the `content` field of a Header Object (or a Parameter Object with `in: "header"`), the serialization MUST be made compatible with the HTTP field syntax as described by [[!RFC9264]][Section 4.1](https://www.rfc-editor.org/rfc/rfc9264.html#name-http-link-document-format-a).
2463
+
2464
+
The following example shows how the same data model can be used for a collection pagination linkset either in JSON format as message content, or in the HTTP `Link` header:
2465
+
2466
+
```yaml
2467
+
components:
2468
+
schemas:
2469
+
SimpleLinkContext:
2470
+
type: array
2471
+
items:
2472
+
type: object
2473
+
required:
2474
+
- href
2475
+
properties:
2476
+
href:
2477
+
type: string
2478
+
format: uri-reference
2479
+
CollectionLinks:
2480
+
type: object
2481
+
required:
2482
+
- linkset
2483
+
properties:
2484
+
linkset:
2485
+
type: array
2486
+
items:
2487
+
type: object
2488
+
required: [first, prev, next, last]
2489
+
properties:
2490
+
anchor:
2491
+
type: string
2492
+
format: uri
2493
+
additionalProperties:
2494
+
$ref: '#/components/schemas/SimpleLinkContext'
2495
+
responses:
2496
+
CollectionWithLinks:
2497
+
content:
2498
+
application/json:
2499
+
schema:
2500
+
type: array
2501
+
headers:
2502
+
Link:
2503
+
required: true
2504
+
content:
2505
+
application/linkset:
2506
+
schema:
2507
+
$ref: '#/components/schemas/CollectionLinks'
2508
+
StandaloneJsonLinkset:
2509
+
content:
2510
+
application/linkset+json:
2511
+
schema:
2512
+
$ref: '#/components/mediaTypes/CollectionLinks'
2513
+
```
2514
+
2454
2515
##### Header Object Example
2455
2516
2456
2517
A simple header of type `integer`:
@@ -4293,6 +4354,7 @@ This will expand to the result:
4293
4354
4294
4355
[RFC6570](https://www.rfc-editor.org/rfc/rfc6570)'s percent-encoding behavior is not always appropriate for `in: "header"` and `in: "cookie"` parameters.
4295
4356
In many cases, it is more appropriate to use `content` with a media type such as `text/plain` and require the application to assemble the correct string.
4357
+
Other media types, such as `application/linkset` (see [Modeling Link Headers](#modeling-link-headers) are directly suitable for use as `content` for specific headers.
4296
4358
4297
4359
In some cases, setting `allowReserved: true` will be sufficient to avoid incorrect encoding, however many characters are still percent-encoded with this field enabled, so care must be taken to ensure no unexpected percent-encoding will take place.
0 commit comments