django-ninja
django-ninja copied to clipboard
Use serialization aliases for responses in OpenAPI schema
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
This might be the same thing as https://github.com/vitalik/django-ninja/pull/1139
@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.
@camuthig So, what about this PR?
@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.
This also fixes the problem of computed fields missing from the schema, as reported by issue #1292 and #960
@vitalik any update on this?