Skip to content

Commit b19e612

Browse files
authored
Merge pull request #4740 from handrews/linkset
v3.2: Add support for application/linkset[+json]
2 parents 12a8939 + 55ebffb commit b19e612

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/oas.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,6 +2450,67 @@ Using `content` with a `text/plain` media type is RECOMMENDED for headers where
24502450
| ---- | :----: | ---- |
24512451
| <a name="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. |
24522452

2453+
##### Modeling Link Headers
2454+
2455+
[[!RFC9264]] defines the `application/linkset` and `application/linkset+json` media types.
2456+
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.
2457+
2458+
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.
2459+
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.
2460+
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.
2461+
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).
2462+
2463+
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:
2464+
2465+
```yaml
2466+
components:
2467+
schemas:
2468+
SimpleLinkContext:
2469+
type: array
2470+
items:
2471+
type: object
2472+
required:
2473+
- href
2474+
properties:
2475+
href:
2476+
type: string
2477+
format: uri-reference
2478+
CollectionLinks:
2479+
type: object
2480+
required:
2481+
- linkset
2482+
properties:
2483+
linkset:
2484+
type: array
2485+
items:
2486+
type: object
2487+
required: [first, prev, next, last]
2488+
properties:
2489+
anchor:
2490+
type: string
2491+
format: uri
2492+
additionalProperties:
2493+
$ref: '#/components/schemas/SimpleLinkContext'
2494+
responses:
2495+
CollectionWithLinks:
2496+
content:
2497+
application/json:
2498+
schema:
2499+
type: array
2500+
headers:
2501+
Link:
2502+
required: true
2503+
content:
2504+
application/linkset:
2505+
schema:
2506+
$ref: '#/components/schemas/CollectionLinks'
2507+
StandaloneJsonLinkset:
2508+
content:
2509+
application/linkset+json:
2510+
schema:
2511+
$ref: '#/components/mediaTypes/CollectionLinks'
2512+
```
2513+
24532514
##### Header Object Example
24542515
24552516
A simple header of type `integer`:
@@ -4292,6 +4353,7 @@ This will expand to the result:
42924353

42934354
[RFC6570](https://www.rfc-editor.org/rfc/rfc6570)'s percent-encoding behavior is not always appropriate for `in: "header"` and `in: "cookie"` parameters.
42944355
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.
4356+
Other media types, such as `application/linkset` (see [Modeling Link Headers](#modeling-link-headers)), are directly suitable for use as `content` for specific headers.
42954357

42964358
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.
42974359

0 commit comments

Comments
 (0)