Skip to content
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

feat(python): add --pydantic-base-model option #2604

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alpoi-x
Copy link

@alpoi-x alpoi-x commented May 21, 2024

Description

Adds a python option pydantic-base-model, which will generate classes inheriting pydantic's BaseModel.

Related Issue

#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):

@zhao004
Copy link

zhao004 commented Jun 11, 2024

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 BaseModelclass Example(BaseModel)

Screenshots (if appropriate):


搜狗截图20240611112248

搜狗截图20240611111916
This option does not exist.

@alpoi-x
Copy link
Author

alpoi-x commented Jun 29, 2024

@zhao004 This is a pull request - code and changes included here are not part of the application until they are merged.

@zhao004
Copy link

zhao004 commented Jul 1, 2024

@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?

@Masked42
Copy link

Is there a timeline for this mr? We are really looking forward to this feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants