Utoipa 5.0.0 Migration Guide #1124
juhaku
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Migration Guide 4.x.x -> 5.0.0
Nesting support
All new nesting support is available since utoipa 5.0.0. Nesting needs a
path
under theapi
that is going to be nested.Optionally
tags
can be provided for all routes of theNestableApi
.This allows better composition and enables users to split a single OpenApi declaration to multiple more reasonable pieces.
OpenAPI 3.1 only
Since 5.0.0 utoipa will only support OpenAPI 3.1. See more what changes in OpenAPI 3.0 -> OpenAPI 3.1 at
https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0
Enum with discrimiantor
Since 5.0.0
#[serde(tag = ...)]
will not be used as a discriminator for enum variants. This is due to nature of inlined schemaswhich does not adhere to discrimiantor and causes warnings with certain OpenAPI tooling for client generation. This issue may be revisited in future when assessment of the functionality is mature enough.
Instead utoipa will have all new
#[schema(discriminator = ...)]
support as demonstrated below. Whendiscriminator
is set, it is expectedto schemas to have a field according to the provided value.
More about discriminator https://spec.openapis.org/oas/latest.html#discriminator-object
Request bodies and Response bodies content_type
Since 5.0.0 request bodies and response bodies as well as
ToRespons
andIntoResponses
does not supportcontent_type = [...]
array syntax for defining multiple content types. Instead multiple content types need to defined via
content
attribute found inrequest_body
and responsesresponse
.Schemas auto collection
Since utoipa 5.0.0 schemas implementing
ToSchema
will get automatically collected recursively toOpenApi
from their usage point e.g.request_body
orresponse
definition. As demonstrated below there is no need call#[openapi(components(schemas(Person, ccount)))]
anymore but they will be collected via the registered pathpaths(test_collect_schema)
.Arrays and tuples with
prefixItems
In utoipa 5.0.0 the Arrays and namely tuples will not be represented as
allOf
since it cannot effectively represent a tuple with correctvalue types of an array. Instead a new Array is created with
prefixItems
to define all possible items of an array which adheres to OpenAPI 3.1 specification. See more about prefix items here https://json-schema.org/understanding-json-schema/reference/array#tupleValidation.#[utoipa::path(..)]
with multiple http operation methodsSince utoipa 5.0.0 multiple http operation methods are supported as demonstrated below. This is in addition to the old syntax that works as previously.
Utoipa path changes
Utoipa
PathItemType
is renamed toHttpMethod
to be more descriptive of what it actually is.Path
trait changesSince 5.0.0 the
Path
trait has changed to the following.In 4.x.x it was:
Real generics support
Since utoipa 5.0.0 the old
aliases
support has been removed and no longer present. Schemas need to be defined with full type declaration in their usage point as demonstrated below. Types withas = ...
will use theas
attribute value as a name prefix for the schema in whole OpenAPI thus the possible path declared inrequest_body
or responsebody
will not affect the name of the schema anymore.In order to support generic arguments all generic arguments need to implement
ToSchema
. This was not the case in the 4.x.x release which was not so restrictive. However this is necessary to be able to resolve schemas for generic types upon usage. Thus if someone uses a generic argument that does not implementToSchema
it needs to be wrapped with a new type implementingToSchema
or it needs to be implemented to the type directly.ToSchema
changesIn utoipa 5.0.0 the
ToSchema
syntax has changed toWhile it used to be following in 4.x.x
For more changes you may want to browse the utoipa CHANGELOG.md and utoipa-gen CHANGELOG.md.
Beta Was this translation helpful? Give feedback.
All reactions