-
-
Notifications
You must be signed in to change notification settings - Fork 392
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
Make JSONField support type annotation and OpanAPI document generation #1763
Conversation
@LanceMoe Hi! Please check out CI - seems like tests are failing |
@abondar but Codacy Static Code Analysis throw a problem, the lambda is unnecessary on python >= 3.10, but is necessary for python <= 3.9 So I had to move it outside class |
Pull Request Test Coverage Report for Build 11882530003Details
💛 - Coveralls |
Make JSONField support type annotation and OpanAPI document generation
JSONField adds optional generic support, and supports OpenAPI document generation by specifying
field_type
as a pydantic BaseModelDescription
JSONField is defined as Any, which does not display properly when using FastAPI to automatically generate OpenAPI documents. #1702
This PR did two things:
field_type
enabled the document to be generated properly.Motivation and Context
I have been using FastAPI + tortoise-orm as the preferred solution for all my project.
My project front-end uses TypeScript + React, and uses
openapi-typescript
to automatically convert the OpenAPI document generated by FastAPI into a type that can be used by TypeScript. However, the JSONField of tortoise-orm does not support type hints, which requires a lot of type cast in my front-end code, so I tried to add type support to JSONField.How Has This Been Tested?
In my project, it works correctly, so I'm going to submit a PR to see if it helps with tortoise-orm.
But I'm not sure if it will pass the existing tests. I'd like to add as many tests as possible, and hope to get help from the project maintainers.(Now I have added some test cases for this PR.)
Screenshots of my project:
Checklist: