Closed francis2tm closed 1 week ago
This is actually same issue as described here: https://github.com/juhaku/utoipa/issues/1162#issuecomment-2435057054 and here #1078.
Before the types implementing ToSchema
could contain fields that does not implement ToSchema
trait. However in the release version of utoipa 5.x.x with full support for generics this is a necessary limitation for types. It is required to all fields and variants to implement ToSchema
trait if type itself implements ToSchema
. This is needed to compose the possible generic schemas and correctly compose the name of the schema.
As described behind the link for the comment and since you have a struct that implements ToSchema
you can use either use utoipa-config
to define globa aliases for the type. Alternatively you can use value_type = ...
attribute over the field to locally alias the type to something else that assumably implements ToSchema
trait. With this value_type
you can create another a new type as shown below to wrap the BigDecimal and use it instead. With as = ...
You can rename it in schema to something else as well if necessary.
#[derive(ToSchema)]
#[schema(value_type = f64)] // or String, etc
struct MyDecimal(BigDecimal);
Utoipa does not have buildin support for BigDecimal but perhaps it could be evaluated in future if there is need for the support.
Got it, thanks a lot!
Cheers
Hello, Amazing project! Thank you for your work. I've just upgraded my utopia crate from
5.0.0-beta
to the latest version5.2.0
and now I have a problem:In
5.0.0-beta
I didn't have this problem. BigDecimal is from the https://github.com/akubera/bigdecimal-rs crate,v0.4.6
Thanks in advance!