Skip to content

How does this magic work? — Recursive ToSchema auto register. #1191

Answered by juhaku
enricoschaaf asked this question in Q&A
Discussion options

You must be logged in to vote

In short, there is no global state. And making one would be quite hard actually and not really sustainable (in utoipa's case).

In utoipa the so-called "state" tracking is a chain of definitions. All that needs to be registered needs to be linked to something that is linked to another thing that is eventually linked to an OpenApi. In the example shown in #1066 the Person type has reference to the Account. When ToSchema is executed for the Person struct it will create a schema reference to the Account. Later when the Person type is used in request_body it will create schema references to Person for the path test_collect_schemas. Even later when the path test_collect_schemas is added to the O…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@enricoschaaf
Comment options

@juhaku
Comment options

Answer selected by enricoschaaf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants