-
Notifications
You must be signed in to change notification settings - Fork 435
Clearly separate compatibility rules for input and output schemas. #851
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
099c0c6
f4011dc
0e09d30
cdfec47
4208743
807ffa3
64fadf4
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 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -41,25 +41,66 @@ expected that code changes are necessary. | |||||||||||||||||||||||
| == {SHOULD} prefer compatible extensions | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| API designers should apply the following rules to evolve RESTful APIs for | ||||||||||||||||||||||||
| services in a backward-compatible way: | ||||||||||||||||||||||||
| services in a backward-compatible way. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| In general: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| * Add only optional, never mandatory fields. | ||||||||||||||||||||||||
| * Never change the semantic of fields (e.g. changing the semantic from | ||||||||||||||||||||||||
| customer-number to customer-id, as both are different unique customer keys) | ||||||||||||||||||||||||
tfrauenstein marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| * Consider <<251>> in case a URL has to change. | ||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| For schemas used in input only: | ||||||||||||||||||||||||
tfrauenstein marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| * Add only optional, never mandatory fields (and don't make optional | ||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| fields mandatory). | ||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| * Don't remove fields. | ||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| * While removing fields by itself doesn't break compatibility (if the | ||||||||||||||||||||||||
| server would still accept it, possibly ignoring it, if sent by the client), | ||||||||||||||||||||||||
| it then would allow later to add a same-named field with different type | ||||||||||||||||||||||||
| or semantic (which is harder to catch). Therefore, this is also considered | ||||||||||||||||||||||||
| a non-compatible change. | ||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| * Input fields may have (complex) constraints being validated via server-side | ||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
| business logic. Never change the validation logic to be more restrictive and | ||||||||||||||||||||||||
| 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. | ||||||||||||||||||||||||
| * `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. | ||||||||||||||||||||||||
| * `enum` ranges can be reduced when used as input, only if the server | ||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| is ready to accept and handle old range values too. | ||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| * `enum` ranges can be extended when used for input. | ||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| For schemas used in output only: | ||||||||||||||||||||||||
tfrauenstein marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| * New mandatory fields can be added, or existing optional ones be made mandatory. | ||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| * Don't remove a mandatory field, or make it optional (clients might depend | ||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| on it being filled). | ||||||||||||||||||||||||
| * Don't remove optional fields either. | ||||||||||||||||||||||||
| * While removing optional fields by itself doesn't break compatibility, | ||||||||||||||||||||||||
| it then would allow later to add a same-named field with different type | ||||||||||||||||||||||||
| or semantic (which is harder to catch). Therefore, this is also considered a non-compatible change. | ||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| * `enum` ranges can be reduced when used as output. | ||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| * `enum` ranges **cannot** be extended when used for output — clients may | ||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| not be prepared to handle it. | ||||||||||||||||||||||||
| * 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. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| For schemas used in both input and output (which is common and recommended in | ||||||||||||||||||||||||
ePaul marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| many cases), both of these rule sets combine, i.e. you can only do changes which | ||||||||||||||||||||||||
| are allowed in both input and output. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| * Add only optional, never mandatory fields. | ||||||||||||||||||||||||
| * Don't remove any fields. | ||||||||||||||||||||||||
| * Don't make mandatory fields optional or make optional fields mandatory. | ||||||||||||||||||||||||
| * Input fields may have (complex) constraints being validated via server-side | ||||||||||||||||||||||||
| business logic. Never change the validation logic to be more restrictive and | ||||||||||||||||||||||||
| make sure that all constraints are clearly defined in description. | ||||||||||||||||||||||||
| * `enum` ranges can be reduced only if the server is ready to still accept and | ||||||||||||||||||||||||
| handle old values. They **cannot** be extended. | ||||||||||||||||||||||||
| * 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. | ||||||||||||||||||||||||
|
Comment on lines
86
to
96
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is is a consequence of the sentence before, and redundant -- should be omitted.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having the redundant information makes it easier to follow, was my idea. Though I also understand the desire to keep the rules shorter. |
||||||||||||||||||||||||
| * Consider <<251>> in case a URL has to change. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Input/Output here is from the perspective of a service implementing and | ||||||||||||||||||||||||
| owning the API. For the rare case of APIs implemented by other services | ||||||||||||||||||||||||
tfrauenstein marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| (and consumed by the owning service), this turns around. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| [#109] | ||||||||||||||||||||||||
| == {SHOULD} design APIs conservatively | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.