tortoise-orm icon indicating copy to clipboard operation
tortoise-orm copied to clipboard

`pydantic_model_creator` should support JSONField annotation (type hints)

Open LanceMoe opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe.

The types of JSONField are all displayed as Any in swagger:

image

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:

image

Or is there any better way to achieve this?

LanceMoe avatar Aug 31 '24 19:08 LanceMoe