quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

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

Open alpoi opened this issue 1 year ago • 4 comments

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

alpoi avatar May 21 '24 11:05 alpoi

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.

zhao004 avatar Jun 11 '24 03:06 zhao004

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

alpoi avatar Jun 29 '24 22:06 alpoi

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

zhao004 avatar Jul 01 '24 02:07 zhao004

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

Masked42 avatar Aug 16 '24 14:08 Masked42

👍

bojanstef avatar Oct 24 '24 17:10 bojanstef

+1

glebignatieff avatar Nov 12 '24 16:11 glebignatieff

@alpoi-x @zhao004 @inferrinizzard Any chance of getting this merged?

gaby avatar Jan 07 '25 00:01 gaby

Will take a look in the next few days 👍

inferrinizzard avatar Jan 11 '25 22:01 inferrinizzard

Is there an available screenshot or side-by-side example of the output with this new option compared against Python dataclasses ?

inferrinizzard avatar Jan 18 '25 15:01 inferrinizzard

@inferrinizzard schema | with new option | without new option image

alpoi avatar Jan 20 '25 16:01 alpoi

@inferrinizzard Does the quicktype.io website get these updates?

Seems to be pointing to super old python versions.

gaby avatar Jan 20 '25 18:01 gaby