Skip to content
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

Add support for self referencing schema #375

Merged
merged 1 commit into from
Nov 27, 2022

Conversation

juhaku
Copy link
Owner

@juhaku juhaku commented Nov 27, 2022

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.

Resolves #179

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.
@juhaku juhaku merged commit 63613c2 into master Nov 27, 2022
@juhaku juhaku deleted the feature-self-referencing-schema branch November 27, 2022 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Released
Development

Successfully merging this pull request may close these issues.

Component derive reference to Self points to wrong name
1 participant