Open alpoi-x opened 1 month ago
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?
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 classesHow 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
andclass Example(BaseModel)
Screenshots (if appropriate):