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.
This commit changes the
ToSchema
trait to be similar withToResponse
trait. It also introduces lifetimes to avoid unnecessary allocations.Prior to this commit the name that was used to register a schema to OpenAPI spec was defined in
#[openapi(components(schemas(...)))]
attribute with syntax likeschemas(path::to::Schema as path::MySchema)
. This is a bit inconvenient at least and behaved completely opposite to how response and request bodies behave when defined in#[utoipa::path]
macro.From now the name of the schema registered in OpenAPI spec will be defined by the
ToSchema
trait itself the same way asToResponse
does it. It will return a tuple of(name, component)
pair.This also introduces new feature
As
what is then used to define alternative name for the schema derived fromToSchema
if necessary. For example the below struct would be registered to the OpenAPI with namepath.to.Foo
instead of justFoo
when it is added to openapi with#[openapi(components(schemas(Foo)))]
.