-
Notifications
You must be signed in to change notification settings - Fork 197
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
Generics: the trait bound Value: ToSchema
is not satisfied
#1128
Comments
@wuzi Yeah, this is actually due to the full generic support. Since pub struct ResponseSchema<D: utoipa::ToSchema, M = Option<serde_json::Value>> { // <-- here is the issue
...
} This should work. #[derive(ToSchema)]
struct MyJson(serde_json::Value);
pub struct ResponseSchema<D: utoipa::ToSchema, M = Option<MyJson>> {
...
} Another way would be that serde would implement |
Thank you for the quick reply @juhaku ! This solves the issue, I thought it was supported and I was forgetting to add some trait because I think it worked before. But I can work with that. Thank you. |
Anytime, yeah it has somewhat worked before because utoipa 4.x.x did not really support generics thus there was no restrictions on generic type bounds. I forgot to mention this in migration guide. And I added the note there just a moment ago. Perhaps I can try to see if I can implement ToSchema for the serde_json::Value type so there is no need wrap it, but anyway this kind of wrapping is necessary for other types that are not implementing |
This commit adds direct `ToSchema` implementation for `serde_json::Value`. Fixes #1128
This commit adds direct `ToSchema` implementation for `serde_json::Value`. Fixes #1128
Does this actually work @juhaku? #[derive(ToSchema)]
struct MyJson(serde_json::Value); I tried something similar with another crate (num-decimal). #[derive(ToSchema)]
pub struct Decimal(pub num_decimal::Num); However this errors with:
but I can't implement |
To be honest after a second thought, it should not work directly. Because new type will actually just unwrap to the inner type. And unless the type implements Only way forward in this case is by some means to create a schema for the type. More details here #507 and #790 (comment) Or you could alias Or you could try something similar to what is done here in generic schema example: utoipa/examples/generics-actix/src/main.rs Lines 16 to 30 in 31abe78
|
Hey!
When using a generic as the
body
property in path macro I'm getting two errors:Value: ToSchema
is not satisfiedValue: ComposeSchema
is not satisfiedCode (the relevant parts):
What is weird is that i swear it was working a few hours ago and it started after I updated the crate to 5.0.0. But I don't have my previous lock file to compare what changed.
I've ran cargo clean and tried in a new project as well.
Full code
```The text was updated successfully, but these errors were encountered: