You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When generating pydantic models with the python-fastapi generator, reserved words are escaped by prepending an underscore. This results in pydantic treating the fields as a private attribute which is ignored in validation and (de)serialization. Furthermore, as of Pydantic v2.1.0, you receive a NameError if trying to use the Field function with a private attribute.
The escaping is currently performed in AbstractPythonCodegen.escapeReservedWord(). The python client generator also generates pydantic models, but it's overriding the method prepending "var_" istead. I assume copying this implementation in PythonFastAPIServerCodegen.java would fix the issue.
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
When generating pydantic models with the python-fastapi generator, reserved words are escaped by prepending an underscore. This results in pydantic treating the fields as a private attribute which is ignored in validation and (de)serialization. Furthermore, as of Pydantic v2.1.0, you receive a NameError if trying to use the Field function with a private attribute.
openapi-generator version
latest master
OpenAPI declaration file content or url
Sample OpenApi spec
Generating models for this spec results in the following model
Generation Details
No special config
Steps to reproduce
openapi-generator generate -i sample.json -g python-fastapi -o /tmp/test/
Related issues/PRs
I have not found anything related
Suggest a fix
The escaping is currently performed in AbstractPythonCodegen.escapeReservedWord(). The
python
client generator also generates pydantic models, but it's overriding the method prepending "var_" istead. I assume copying this implementation in PythonFastAPIServerCodegen.java would fix the issue.The text was updated successfully, but these errors were encountered: