Skip to content

Commit

Permalink
Add support for self referencing schema (#375)
Browse files Browse the repository at this point in the history
Previously field with type `Box<Self>` within a `ToSchema` struct or
enum did not create correct OpenAPI schema but mistakenly created a
reference to unknown type `#/components/schemas/Self`.

This commit fixes this issue and now correct type will be created when
`Self` keyword is being used withing `ToSchema` structs or enums. E.g.
now `struct Item(Box<Self>);` will create a reference like
`#/components/schemas/Item`.

This commit also makes a breaking change to `ToSchema` trait where
previously it was not possible to add a Reference directly to OpenAPI
components schemas map even this is allowed by OpenAPI spec. This is
commit will change the `ToSchema` return type to `RefOr<Schema>` to
allow returning references directly.
  • Loading branch information
juhaku committed Nov 27, 2022
1 parent 483b778 commit 63613c2
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 106 deletions.
Loading

0 comments on commit 63613c2

Please sign in to comment.