Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upParameters for Media Types #2342
Comments
|
I'm right there with you on parameters and your examples for versioning and profile identification, but I think the hypermedia selection stuff is non-standard and we don't want to add anything non-standard to OpenAPI thats going to live in the users actual API. If we stick the a general mechanism for adding parameters to a media type, I think this could be a great idea. charset, version, etc are all good things to be able to describe as possible in an API. |
|
Thanks Phil. |
|
For consistency, if someone does take this to a PR, fields like |
|
Right. All of the examples need work. The operation Guessing at the changes that might be needed:
Revised ExamplesVersioning Accept: application/vnd.example-schema+json; version=1.0.4content:
application/vnd.example-schema+json:
parameters:
- name: version
description: Media type version for the representation.
required: false
deprecated: false
schema:
type: string
default: 1.1.0
enum:
- 1.0.3
- 1.0.4
- 1.1.0
examples:
priorVersion:
summary: The most recent prior version.
value: 1.0.4
currentVersion:
summary: The current version.
value: 1.1.0or content:
application/vnd.example-schema+json:
parameters:
- $ref: "https://schemas.example.com/example/MediaTypeVersion"Profile identification Accept: application/vnd.example-schema+json; profile=https://schemas.example.com/example/profiles/bobcontent:
application/vnd.example-schema+json:
parameters:
- name: profile
description: The profile (rfc6906) for the media type
required: false
deprecated: false
schema:
type: string
default: "https://schemas.example.com/example/profiles/alice"
enum:
- "https://schemas.example.com/example/profiles/alice"
- "https://schemas.example.com/example/profiles/bob"
examples:
BobProfile:
summary: The classic Bob profile we all know and love.
value: "https://schemas.example.com/example/profiles/bob"
AliceProfile:
summary: The new and improved.
value: "https://schemas.example.com/example/profiles/alice"Use of or content:
application/vnd.example-schema+json:
parameters:
- $ref: "https://schemas.example.com/example" |
Parameters for Media Types
Media Types can support parameters. Yet, to work with them in OpenAPI, one must define them statically against each media type. This has the unfortunate side effect of discouraging use of media type parameters by making them clumsy to manage within the API spec.
Without a way to express the parameter, it has little or no semantic value for OpenAPI. Minor variations look like completely different media types. There is little room for negotiation over content parameters unless the API author takes the time to spell out each supported parameter as its own type.
Media Type parameters could be useful in some obvious ways:
Private and vendor media types might better manage breaking changes by supporting multiple versions of representation without ever changing endpoints and methods. Perhaps there could be benefits to QA and regression test tooling, being able to validate support for the diversity of representation styles in the API contract. This could be had without having to iterate every parameter combination as a separate media type.
Examples
Versioning
Profile identification
Hypermedia style selection
Added after the original issue report
I am inspired by what I read on Roy Fielding's blog entry "REST APIs must be Hypertext Driven".
If I understand him correctly, enriching OpenAPI's ability to semantically express media type parameters would improve its ability to convey the kinds of interactions Mr. Fielding expected to be inherent in the resource or resource representation, rather than in other parts of the HTTP message. Conversely, not supporting media type parameters might limit OpenAPI's ability to articulate a nuanced RESTful concept.