Hooks which handle the exportation of Pydantic models.
Hook ID | Description |
---|---|
pydantic-to-json |
Convert instanciated pydantic models to their corresponding JSON representation |
pydantic-to-schema |
Convert pydantic model declarations to corresponding JSON schemas |
For example ...
from pydantic import BaseModel
class ExampleClass(BaseModel):
x: int
example_instance = ExampleClass(x=2)
Would export to ...
example_instance.json (pydantic-to-json) |
ExampleClass.json (pydantic-to-schema) |
---|---|
{
"x": 2
} |
{
"properties": {
"x": {
"title": "X",
"type": "integer"
}
},
"required": [
"x"
],
"title": "ExampleClass",
"type": "object"
} |
A pre-commit hook to convert instanciated pydantic classes to their respective JSON information dumps.
By default, only the Pydantic models located within changed files are exported;
this behavior is overridable using both/eitherinput
andall
Minimal usage:
repos:
- repo: https://github.com/Mermeid-Designs/pre-commit-hooks
rev: "" # can specify specific revision if needed
hooks:
- id: pydantic-to-json
args:
[
"--output",
"path/to/output/folder",
]
Parameters:
-
output
($\color{red}Required$ ):str
, path to the desired folder where you would like the exportedJSON dictionaries
to be stored. If the folder does not exist, it will be created. Any existing JSONs will be overwritten, if applicable. -
input
($Optional$ ):str
, absolute or relative path to a Python package, sub-package, or module that contains the Pydantic model class declaration(s) you wish to export. Theinput
may reference files outside the scope of the repo invoking this pre-commit call. -
all
($Optional$ ): flag denoting all Pydantic model class declaration(s) withininput
shall be exported, (not just ones within changed files).
Output: Naming convention is as follows {YourClassName}.json
📌 NOTE:
- ALL Pydantic model class declaration(s) within
input
can potentially be exported, regardless of if they are normally visible toinput
(e.g. private class declarations)--all
is necessary ifinput
references files outside the scope of the repo invoking this pre-commit call
A pre-commit hook to convert pydantic class declarations to their respective JSON schemas
By default, only the Pydantic models located within changed files are exported;
this behavior is overridable using both/eitherinput
andall
Minimal usage:
repos:
- repo: https://github.com/Mermeid-Designs/pre-commit-hooks
rev: "" # can specify specific revision if needed
hooks:
- id: pydantic-to-schema
args:
[
"--output",
"path/to/output/folder",
]
Parameters:
-
output
($\color{red}Required$ ):str
, path to the desired folder where you would like the exportedJSON dictionaries
to be stored. If the folder does not exist, it will be created. Any existing JSONs will be overwritten, if applicable. -
input
($Optional$ ):str
, absolute or relative path to a Python package, sub-package, or module that contains the Pydantic model class declaration(s) you wish to export. Theinput
may reference files outside the scope of the repo invoking this pre-commit call. -
all
($Optional$ ): flag denoting all Pydantic model class declaration(s) withininput
shall be exported, (not just ones within changed files).
Output: Naming convention is as follows {YourClassName}.json
📌 NOTE:
- ALL Pydantic model class declaration(s) within
input
can potentially be exported, regardless of if they are normally visible toinput
(e.g. private class declarations)--all
is necessary ifinput
references files outside the scope of the repo invoking this pre-commit call