-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
099c0c6
Clearly separate compatibility rules for input and output schemas.
f4011dc
Apply suggestions from code review
ePaul 0e09d30
Apply suggestions from code review
ePaul cdfec47
Apply suggestions from code review
ePaul 4208743
Apply suggestions from code review
ePaul 807ffa3
common and recommended → typical
ePaul 64fadf4
Merge branch 'main' into compatibility-separately-for-input-output
7921ec6
Merge branch 'main' into compatibility-separately-for-input-output
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -41,25 +41,63 @@ 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
|
||||||
| The compatibility of schema changes depends on whether the input and/or output objects are defined. | ||||||
|
|
||||||
| For schemas used in input only: | ||||||
tfrauenstein marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| * Add optional fields, but never mandatory fields. | ||||||
| * Make mandatory fields optional, but not vice-versa. | ||||||
| * Don't remove fields(*). | ||||||
| * 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 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 | ||||||
| only for input parameters. | ||||||
| * `enum` ranges can be reduced, only if the server | ||||||
| continues to accept and handle old range values. | ||||||
| * `enum` ranges can be extended. | ||||||
|
|
||||||
| (*) Hint: Removing a field can be considered as a compatible change that does not break clients, in case the service still accepts and possibly ignores it if sent by the client. However, removed fields allow later adding a same-named field with different type or semantic (which is harder to catch). We therefore define field removal as non-compatible. | ||||||
|
|
||||||
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
|
||||||
|
|
||||||
| * Add (mandatory or optional) fields. | ||||||
| * Make optional fields mandatory, but not vice-versa. | ||||||
| * Don't remove fields (*). | ||||||
| * `enum` ranges can be reduced. | ||||||
| * `enum` ranges *cannot* be extended — clients may | ||||||
| not be prepared to handle it. | ||||||
| * You <<112>> that are used for output parameters and likely to | ||||||
| be extended with growing functionality. The API specification should be updated | ||||||
| first before returning new values. | ||||||
| * Consider <<251>> in case a URL has to change. | ||||||
|
|
||||||
ePaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| (*) Hint: Removing an optional field can be considered as a compatible change that does not break clients. However, removed fields allow later adding a same-named field with different type or semantic (which is harder to catch). We therefore define optional field removal as non-compatible. | ||||||
|
|
||||||
| For schemas used in both input and output (which is typical in | ||||||
| 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. | ||||||
|
|
||||||
| 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 | ||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.