-
-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: JSON schema
examples
were OpenAPI formatted
The generated `examples` in *JSON schema* objects were formatted as: ```json "examples": { "some-id": { "description": "Lorem ipsum", "value": "the real beef" } } ``` However, above is OpenAPI example format, and must not be used in JSON schema objects. Schema objects follow different formatting: ```json "examples": [ "the real beef" ] ``` This is explained in https://medium.com/apis-you-wont-hate/openapi-v3-1-and-json-schema-2019-09-6862cf3db959 Schema objects spec in https://spec.openapis.org/oas/v3.1.0#schema-object. OpenAPI example format spec in https://spec.openapis.org/oas/v3.1.0#example-object. This is referenced at least from parameters, media types and components. The technical change here is to define `Schema.examples` as `list[Any]` instead of `list[Example]`. Examples can and must still be defined as `list[Example]` for OpenAPI objects (e.g. `Parameter`, `Body`) but for JSON schema `examples` the code now internally generates/converts `list[Any]` format instead. Extra confusion here comes from the OpenAPI 3.0 vs OpenAPI 3.1 difference. OpenAPI 3.0 only allowed `example` (singular) field in schema objects. OpenAPI 3.1 supports the full JSON schema 2020-12 spec and so `examples` array in schema objects. Both `example` and `examples` seem to be supported, though the former is marked as deprecated in the latest specs. This can be tested over at https://editor-next.swagger.io by loading up the OpenAPI 3.1 Pet store example. Then add `examples` in `components.schemas.Pet` using the both ways and see the Swagger UI only render the example once it's properly formatted (it ignores is otherwise).
- Loading branch information
1 parent
d292aac
commit d8606b5
Showing
10 changed files
with
49 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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