tortoise / tortoise/tortoise-orm
`pydantic_model_creator` should support JSONField annotation (type hints)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Is your feature request related to a problem? Please describe.
The types of JSONField are all displayed as Any in swagger:
I need to import openapi.json into a TypeScript project for use, and this makes the generated openapi.json very poor in usability.
Describe the solution you'd like
I found in tortoise/contrib/pydantic/creator.py has
# Json fields
elif field_type is JSONField:
properties[fname] = Any
I think we can avoid any by adding an optional type json_schema when defining the field, like this:
Or is there any better way to achieve this?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in tortoise/contrib/pydantic/creator.py at the JSONField branch that currently assigns Any. Read how field annotations are defined and how generated schemas become OpenAPI, then determine how an optional JSONField type hint should be represented. Done means JSONField annotations produce more useful types in the generated openapi.json instead of Any.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100