Skip to content
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

Use serialization aliases for responses in OpenAPI schema #1162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

camuthig
Copy link

When generating JSON schemas from the Pydantic types, the mode must be set in order for the correct aliases to be used. The default is to generate the schema for validation mode, which means that for building response schemas, the mode needs to be explicitly set to serialization.

This fixes issues I brought up in discussion #1132

When generating JSON schemas from the Pydantic types, the `mode` must be
set in order for the corret aliases to be used. The default is to
generate the schema for validation mode, which means that for building
response schemas, the mode needs to be explicitly set to serialization.
@pmdevita
Copy link

This might be the same thing as #1139

@camuthig
Copy link
Author

@pmdevita thanks for calling that out. There is some duplication here in that both pulls depend on leveraging the mode argument in model_json_schema. However, the other issue/pull request are also tackling a more nuanced issue around definition of "required" field.

I'm open to closing the pull request, but considering the other one is also facing some open questions of backwards compatibility, I don't want to slow down this fix because of those unrelated topics.

@nstonic
Copy link

nstonic commented Aug 29, 2024

@camuthig So, what about this PR?

@camuthig
Copy link
Author

@nstonic I'm not sure what the situation here is. @vitalik would you consider this pull request as an simpler version of the referenced #1139, that one is tackling a much deeper problem. This pull request has a smaller scope and only makes sure that the alias configurations are respected in the JSON schema generation. I think the other PR can still be considered as a progression of what this one accomplishes.

@tu-pm
Copy link

tu-pm commented Oct 2, 2024

This also fixes the problem of computed fields missing from the schema, as reported by issue #1292 and #960

@oubeichen
Copy link

@vitalik any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants