quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

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

Open alpoi-x opened this issue 9 months 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-x avatar May 21 '24 11:05 alpoi-x