What are the best practices for defining a schema for nested or wrapped third-party types? #1297
Unanswered
vnermolaev
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi @juhaku,
I often find myself needing to create a schema for a type from a third-party crate, which can't be annotated with
#[derive(ToSchema)]
.To handle this, I usually define a function to manually create the schema for such types. For example, in the snippet below,
Owner
is a third-party type, and theowner_schema()
function explicitly defines its schema.If
Owner
is used as a field type, like inPet
, I can easily annotate it with#[schema(schema_with = owner_schema)]
, and everything works as expected.However, if
Owner
is nested inside another type, like inPet2
, or wrapped in an enum variant, this approach no longer seems to work.Is this use case supported? If not, what’s the recommended best practice for handling such scenarios?
Beta Was this translation helpful? Give feedback.
All reactions