Skip to content

Commit 4c5f1d4

Browse files
committed
Refactor.
1 parent 6df6462 commit 4c5f1d4

File tree

1 file changed

+94
-32
lines changed

1 file changed

+94
-32
lines changed

draft-ietf-httpapi-rest-api-mediatypes.md

Lines changed: 94 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -352,37 +352,54 @@ This section explores the possibilities for User Agents
352352
to retrieve information about API specifications
353353
using their preferred version of OpenAPI.
354354

355-
## Scenarios
356-
{: numbered="false" removeinrfc="true"}
355+
Note:
356+
357+
- for readability, we use only YAML serialization;
358+
- we use the fictiotius media type `application/whatever+yaml`
359+
to represent definitions
360+
that are not associated with any specific registered media type;
361+
- this does not specify nor mandate a specific server behavior;
362+
the various ecosystems are free to implement a more specific
363+
behavior. See {{?RFC9205}}.
357364

358365
An API catalog exposes API specifications using OAS 3.0,
359366
and it wants to provide migration/upgrade capabilities
360-
to future versions of OAS and JSON Schema.
361-
For simplicity, we use only YAML serialization.
367+
to future versions of OAS and of the referenced resources.
362368

363369
Resource: https://example.org/openapi.yaml
364370
: is an OpenAPI Specification document
365371
that references the Foo schema located at /foo.yaml.
366372

373+
The following representation is used
374+
both when the User Agent requests OAS 3.0
375+
and as a default representation
376+
(see {{Section 15.5.7 of HTTP}}).
377+
For example, this is the response
378+
returned when the User Agent requests
379+
OAS 3.1.
380+
367381
~~~ http
368382
HTTP/1.1 200 OK
369383
Content-Location: openapi.yaml
370384
Content-Type: application/openapi+yaml; version=3.0
371385

372-
openapi: 3.0.0
386+
openapi: 3.0.4
373387
374388
components:
375389
schemas:
376390
Foo:
377391
"$ref": "/foo.yaml"
378392
~~~
379393

394+
The following representation is used
395+
when the User Agent requests OAS 3.2.
396+
380397
~~~ http
381398
HTTP/1.1 200 OK
382399
Content-Location: openapi.yaml
383400
Content-Type: application/openapi+yaml; version=3.2
384401

385-
openapi: 3.2.0
402+
openapi: 3.2.1
386403
"$self": https://example.com/openapi.yaml
387404
388405
components:
@@ -412,7 +429,7 @@ adding a `title` to each enum value.
412429
~~~ http
413430
HTTP/1.1 200 OK
414431
Content-Location: foo.yaml
415-
Content-Type: application/whatever+yaml
432+
Content-Type: application/whatever+yaml; version=https://json-schema.org/draft/2020-12/schema
416433

417434
"$schema": "https://json-schema.org/draft/2020-12/schema"
418435
"$id": "https://example.com/foo.yaml"
@@ -423,19 +440,68 @@ oneOf:
423440
title: English
424441
~~~
425442

426-
### Scenario 1
443+
## User Agent wants only OAS3.1, gets 406
427444
{: numbered="false" removeinrfc="true"}
428445

429-
The User Agent only supports OAS3.0
430-
and refuses other formats,
431-
including the more generic ones
446+
The User Agent wants OAS3.1,
447+
and is not willing to accept other versions
432448
(see {{Section 12.4.3 of HTTP}}.
433449

434450
~~~ http
435451
GET /openapi.yaml HTTP/1.1
436452
Host: example.com
437453
Accept: \
438-
application/openapi+yaml; version=3.0,
454+
application/openapi+yaml; version=3.1,
455+
*/*; q=0
456+
~~~
457+
458+
The server does not have
459+
the selected representation
460+
and responds with a 406 Not Acceptable.
461+
462+
~~~ http
463+
HTTP/1.1 406 Not Acceptable
464+
Accept: \
465+
application/openapi+yaml; version=3.0, \
466+
application/openapi+yaml; version=3.2
467+
~~~
468+
469+
## User Agent prefers OAS3.1, gets OAS3.0
470+
{: numbered="false" removeinrfc="true"}
471+
472+
The User Agent prefers OAS3.1,
473+
and does not impose further constraints.
474+
475+
~~~ http
476+
GET /openapi.yaml HTTP/1.1
477+
Host: example.com
478+
Accept: application/openapi+yaml; version=3.1
479+
~~~
480+
481+
The server responds with the default representation.
482+
483+
~~~ http
484+
HTTP/1.1 200 OK
485+
Content-Type: application/openapi+yaml; version=3.0
486+
487+
openapi: 3.0.4
488+
489+
components:
490+
schemas:
491+
Foo:
492+
"$ref": /foo.yaml
493+
~~~
494+
495+
## User Agent requires OAS3.0 for entry document and compatible referenced resources
496+
{: numbered="false" removeinrfc="true"}
497+
498+
The User Agent only supports OAS3.0 entry documents.
499+
500+
~~~ http
501+
GET /openapi.yaml HTTP/1.1
502+
Host: example.com
503+
Accept: \
504+
application/openapi+yaml; version=3.0;q=1, \
439505
*/*; q=0
440506
~~~
441507

@@ -445,7 +511,7 @@ The server responds with the desired resource.
445511
HTTP/1.1 200 OK
446512
Content-Type: application/openapi+yaml; version=3.0
447513

448-
openapi: 3.0.0
514+
openapi: 3.0.4
449515
450516
components:
451517
schemas:
@@ -454,18 +520,17 @@ components:
454520
~~~
455521

456522
The User Agent processes the content
457-
and to resolve the `$ref`, requests the /foo.yaml.
458-
459-
It needs to retrieve a content compatible with
460-
the entry document.
461-
While the User Agent expects a JSON or YAML serialized content,
462-
compatible with OAS3.0,
463-
it cannot know the actual format that the server will return.
523+
and to resolve the `$ref`, requests /foo.yaml.
524+
Since it is not an entry document,
525+
the User Agent is willing to accept
526+
any content compatible with OAS3.0.
464527

465528
~~~ http
466529
GET /foo.yaml HTTP/1.1
467530
Host: example.com
468-
Accept: application/openapi+yaml; version=3.0; q=1, application/yaml; q=0.5
531+
Accept: \
532+
application/openapi+yaml; version=3.0; q=1, \
533+
application/yaml; q=0.5
469534
~~~
470535

471536
The server responds with a YAML serialized content
@@ -482,20 +547,18 @@ type: string
482547
enum: [it, en]
483548
~~~
484549

485-
### Scenario 2
550+
Q: Could the server respond with the same content
551+
using the `application/whatever+yaml` media type?
552+
553+
## User Agent prefers OAS3.2, gets JSON Schema
486554
{: numbered="false" removeinrfc="true"}
487555

488-
The User Agent prefers OAS3.2;
489-
moreover uses the `q` parameter
490-
to decline OAS3.0 documents.
491-
If it weren't so, the server
492-
could have responded with the older version
493-
if the OAS3.2 document were not available.
556+
The User Agent prefers OAS3.2.
494557

495558
~~~ http
496559
GET /openapi.yaml HTTP/1.1
497560
Host: example.com
498-
Accept: application/openapi+yaml; version=3.2, application/openapi+yaml; version=3.0;q=0
561+
Accept: application/openapi+yaml; version=3.2
499562
~~~
500563

501564
The server responds with the OAS3.2 document.
@@ -504,7 +567,7 @@ The server responds with the OAS3.2 document.
504567
HTTP/1.1 200 OK
505568
Content-Type: application/openapi+yaml; version=3.2
506569

507-
openapi: 3.0.0
570+
openapi: 3.0.4
508571
509572
components:
510573
schemas:
@@ -543,7 +606,7 @@ oneOf:
543606
title: English
544607
~~~
545608

546-
### Scenario 3
609+
## User Agent negotiates for a non-OAS media type
547610
{: numbered="false" removeinrfc="true"}
548611

549612
In this scenario:
@@ -641,7 +704,6 @@ Cons:
641704
the 406 Not Acceptable response and give up.
642705
- Requires a specific Accept value for each possible referenced resource,
643706
which may be difficult to manage.
644-
- Clients may not be able to
645707

646708

647709
# Change Log

0 commit comments

Comments
 (0)