feat(python): add --pydantic-base-model option #2604
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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):