feat(python): add --pydantic-base-model option
Description
Adds a python option pydantic-base-model, which will generate classes inheriting pydantic's BaseModel.
Related Issue
https://github.com/glideapps/quicktype/issues/1474
Motivation and Context
Pydantic is a commonly used python module for defining schemas and dataclasses with validation. It is used in FastApi. It is a nice alternative to the builtin dataclasses module.
Previous Behaviour / Output
Quicktype generates standard classes or dataclasses (3.7+) for python
New Behaviour / Output
With the --pydantic-base-model option, it generates pydantic BaseModel classes
How Has This Been Tested?
Built and generated python from a schema, with and without --pydantic-base-model option.
Without the option included from dataclasses import dataclass and @dataclass
With the option instead included from pydantic import BaseModel and class Example(BaseModel)
Screenshots (if appropriate):
Description
添加一个 python 选项
pydantic-base-model,它将生成继承 pydantic 的 BaseModel 的类。Related Issue
#1474
Motivation 和 Context
Pydantic 是一个常用的 python 模块,用于通过验证定义模式和数据类。它在 FastApi 中使用。它是内置
dataclasses模块的一个很好的替代品。上一页 Behaviour / Output
Quicktype 为 python 生成标准类或数据类 (3.7+)
创建 Behaviour / Output
使用
--pydantic-base-model选项,它生成 pydantic BaseModel 类How Has This Been Tested?
从模式构建并生成 python,带或不带
--pydantic-base-model选项。没有包含
from dataclasses import dataclass和@dataclass选项选项包含
from pydantic import BaseModel和class Example(BaseModel)Screenshots (if appropriate):
This option does not exist.
@zhao004 This is a pull request - code and changes included here are not part of the application until they are merged.
@zhao004 This is a pull request - code and changes included here are not part of the application until they are merged.
When can the merger be completed?
Is there a timeline for this mr? We are really looking forward to this feature
👍
+1
@alpoi-x @zhao004 @inferrinizzard Any chance of getting this merged?
Will take a look in the next few days 👍
Is there an available screenshot or side-by-side example of the output with this new option compared against Python dataclasses ?
@inferrinizzard
schema | with new option | without new option
@inferrinizzard Does the quicktype.io website get these updates?
Seems to be pointing to super old python versions.