Replies: 1 comment 1 reply
-
This is a bit problematic since the The only option is to use the #[derive(Serialize, Deserialize, ToSchema, Clone)]
pub struct Input {
name: String,
#[schema(value_type = Vec<Object>)]
blob: serde_json::Value,
} Thing is that with Another alternative is to use generics. Because you need to define all possible schemas beforehand and the generics would allow you to do so. #[derive(ToSchema)]
#[aliases(ValueInt = Value<i32>, ValueString = Value<String>)]
struct Value<T> {
value: T
}
#[derive(OpenApi)]
#[openapi(components(schemas(ValueInt, ValueString)))]
struct Doc; |
Beta Was this translation helpful? Give feedback.
-
I would like to include an arbitrary JSON blob in my API schema. Something like this:
This doesn't immediately work. Since
serde_json::Value
doesn't implementToSchema
, theblob
property ends up with this type in the OpenAPI schema:The best solution I have been able to find is this:
But this isn't ideal as it doesn't support other valid JSON values like arrays, strings etc.
I've had a look at the macro documentation and
ToSchema
implementation guide, but I haven't been able to figure out how to make this work. Would appreciate any ideas!Beta Was this translation helpful? Give feedback.
All reactions