You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use stripe_product::{product::SearchProduct,Product};use stripe_types::SearchList;#[utoipa::path( get, path = "/stripe/get-credit-offers", responses((status = 200, description = "Account created", body = [Product]),), tag = "stripe")]pubasyncfnget_credit_offers() -> Result<Json<SearchList<Product>>,LambdaError>{ ...}
However, in 5.x.x, Product, which comes from a 3rd party crate, doesn't implement ToSchema. I found in the migration notes I would need to manually implement ToSchema, but honestly I have no idea how the type works and would like guidance on how I'm supposed to implement ToSchema manually.
The text was updated successfully, but these errors were encountered:
Yeah, this is an unfortunate necessity to support generics in the utoipa. This is a duplicate for this: #1205. While the issue and the following links inside the issue guide towards using value_type or utoipa-config for creating an alias for the type, you could also create a custom schema as well. For this you need a type to implement ToSchema for.
structFoo;implPartialSchemaforFoo{fnschema() -> RefOr<Schema>{Object::builder().property("name",Object::builder().schema_type(Type::String)).into()// or alternatively, since String implements ToSchema and PartialSchema we can directly refer the schema of a String.// Object::builder().property("name", String::schema()).into()}}implToSchemaforFoo{fnname() -> Cow<'static,str>{Cow::Borrowed("Foo")}}
In the above example there is a type Foo which implements PartialSchema that creates an OpenAPI object with one field name with type string. ToSchema implementation gives the Foo the name that is used to reference it within OpenAPI spec.
In 4.x.x, this worked:
However, in 5.x.x,
Product
, which comes from a 3rd party crate, doesn't implementToSchema
. I found in the migration notes I would need to manually implementToSchema
, but honestly I have no idea how the type works and would like guidance on how I'm supposed to implement ToSchema manually.The text was updated successfully, but these errors were encountered: