-
Notifications
You must be signed in to change notification settings - Fork 436
Deprecate x-extensible-enum #837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
84a926b
6563e9c
c02f13c
84fb411
4b1b823
f0fd38e
aafbe04
33f3769
a7ac21d
322ed8b
6b9c0ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -51,10 +51,10 @@ services in a backward-compatible way: | |||
| make sure that all constraints are clearly defined in description. | ||||
| * `enum` ranges can be reduced when used as input parameters, only if the server | ||||
| is ready to accept and handle old range values too. The range can be reduced | ||||
| when used as output parameters. | ||||
| when used only as output parameters. | ||||
| * `enum` ranges cannot be extended when used for output parameters — clients may | ||||
| not be prepared to handle it. However, enum ranges can be extended when used | ||||
| for input parameters. | ||||
| not be prepared to handle it. However, `enum` ranges can be extended when used | ||||
| only for input parameters. | ||||
| * You <<112>> that are used for output parameters and likely to | ||||
| be extended with growing functionality. The API definition should be updated | ||||
| first before returning new values. | ||||
|
|
@@ -124,8 +124,11 @@ Service clients should apply the robustness principle: | |||
| http://martinfowler.com/bliki/TolerantReader.html["TolerantReader"] post), | ||||
| i.e. ignore new fields but do not eliminate them from payload if needed for | ||||
| subsequent {PUT} requests. | ||||
| ** Be prepared that {x-extensible-enum} return parameters (see <<112, rule 112>>) may deliver new values; | ||||
| either be agnostic or provide default behavior for unknown values, and do not eliminate them. | ||||
| ** Be prepared that <<112, extensible enum>> return parameters | ||||
| may deliver new values; | ||||
| either be agnostic or provide default behavior for unknown values, and | ||||
| do not eliminate them when passed to subsequent {PUT} requests. | ||||
| (This means you cannot simply implement it by using a limited enumeration type like a Java `enum`.) | ||||
| ** Be prepared to handle HTTP status codes not explicitly specified in endpoint | ||||
| definitions. Note also, that status codes are extensible. Default handling is | ||||
| how you would treat the corresponding {x00} code (see | ||||
|
|
@@ -289,20 +292,72 @@ level data structures, since they don't support compatible, future extensions. | |||
|
|
||||
|
|
||||
| [#112] | ||||
| == {SHOULD} use open-ended list of values (`x-extensible-enum`) for enumeration types | ||||
| == {SHOULD} use open-ended list of values (via `examples`) for enumeration types | ||||
|
|
||||
| JSON schema `enum` is per definition a closed set of values that is assumed to be | ||||
| complete and not intended for extension. This closed principle of enumerations | ||||
| imposes compatibility issues when an enumeration must be extended. To avoid | ||||
| these issues, we recommend to use an open-ended list of values instead | ||||
| of an enumeration unless: | ||||
| complete and not intended for extension. This means, extending the list of values of | ||||
| `enum` is considered an incompatible change, and needs to be aligned with all consumers | ||||
| like other incompatible changes. | ||||
|
|
||||
| 1. the API has full control of the enumeration values, i.e. the list of values | ||||
| To avoid these issues, we recommend to use `enum` only if | ||||
|
|
||||
| 1. the API owner has full control of the enumeration values, i.e. the list of values | ||||
| does not depend on any external tool or interface, and | ||||
| 2. the list of values is complete with respect to any thinkable and unthinkable | ||||
| future feature. | ||||
|
|
||||
| To specify an open-ended list of values via the {x-extensible-enum} property as follows: | ||||
| In all other cases, where additional values are imaginable our recommendation is this: | ||||
|
|
||||
| * Use `examples` with the list of (currently known) values | ||||
| * Put "Extensible enum" in the description. | ||||
|
|
||||
| This indicates that only the listed values are currently possible, but | ||||
| consumers need to be aware that this list can be extended without notice | ||||
| (see below for details). | ||||
|
|
||||
| [source,yaml] | ||||
| ---- | ||||
| delivery_method: | ||||
| type: string | ||||
| examples: | ||||
| - PARCEL | ||||
| - LETTER | ||||
| description: Extensible enum. The chosen delivery method of the invoice. | ||||
tfrauenstein marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
| ---- | ||||
|
|
||||
| See <<240>> about enum value naming conventions – these apply here too. | ||||
|
|
||||
|
|
||||
| **Important**: | ||||
|
|
||||
| * API consumers must be prepared for the fact that also other values can be returned | ||||
| with server responses (or be contained in consumed events), and implement a | ||||
| fallback / default behavior for unknown new values, see <<108>>. | ||||
| * API owners must take care to extend these extensible enums in a compatible way, i.e. | ||||
| not changing the semantics of already existing / documented values. | ||||
| * API implementations should validate the values provided with the input payload and only accept | ||||
| values listed in `examples`. The list should not be reduced for inputs (that would be an incompatible change). | ||||
| * Before additional values are accepted or returned, API owners should update the API description and extend | ||||
| the `examples` list, see <<107>>. | ||||
|
|
||||
| (Note that the last 3 bullet points do not apply for uses of `examples` _without_ the | ||||
| "Extensible enum." prefix in the description – here any value fitting the rest | ||||
| of the schema needs to be expected.) | ||||
|
|
||||
| Note that the plural `examples` on schemas was only introduced with OpenAPI 3.1 (with an update of the JSON schema version referenced). | ||||
| APIs defined with older OpenAPI versions can't use this format, and instead need to use | ||||
| the {x-extensible-enum} described below↓. | ||||
|
|
||||
| === Historic Note: `x-extensible-enum` | ||||
|
|
||||
| Previously (until October 2025), this guideline recommended a proprietary | ||||
ePaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
| {x-extensible-enum} JSON schema extension, with a similar semantic: | ||||
ePaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
|
|
||||
| > This is the *complete* list of values *currently* possible, but consumers must be | ||||
|
||||
| > This is the *complete* list of values *currently* possible, but consumers must be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you meant to remove the quoted similar semantic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I would remove it to avoid redundancies in the same rule context. I also would replace 'similar semantic' by 'same semantics'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left it in because I understood that the semantics are not quite identical.
This indicates that only the listed values are currently possible, but consumers need to be aware that this list can be extended without notice (see below for details).
vs.
This is the complete list of values currently possible, but consumers must be prepared for other values in the future.
Re-reading both now, I agree that it's actually close enough so it doesn't need to be listed again.
But I think the example should still be there, as without it it's not clear at all how to use it.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| prepared for other values in the future. |
Uh oh!
There was an error while loading. Please reload this page.