Code Generationยค
JSON Schemas are provided for the data models.
They can be used to generate code in various languages:
It' possible to generate Python dataclasses from the JSON Schemas using datamodel-code-generator
:
- First clone the repository:
git clone https://github.com/charbonnierg/pytest-broadcastercd pytest-broadcaster
- Then install
datamodel-code-generator
:
pip install --user datamodel-code-generator
- Then generate the code:
datamodel-codegen \
--input docs/schemas/ \
--output models/ \
--input-file-type jsonschema \
--disable-timestamp \
--output-model-type=dataclasses.dataclass \
--use-field-description \
--use-schema-description
The generated code will be in the models
directory.
It' possible to generate Pydantic BaseModel classes from the JSON Schemas using datamodel-code-generator
:
- First clone the repository:
git clone https://github.com/charbonnierg/pytest-broadcastercd pytest-broadcaster
- Then install
datamodel-code-generator
:
pip install --user datamodel-code-generator
- Then generate the code:
datamodel-codegen \
--input docs/schemas/ \
--output models/ \
--input-file-type jsonschema \
--disable-timestamp \
--output-model-type=pydantic_v2.BaseModel \
--use-field-description \
--use-schema-description
The generated code will be in the models
directory.
It' possible to generate Pydantic BaseModel classes from the JSON Schemas using datamodel-code-generator
:
- First clone the repository:
git clone https://github.com/charbonnierg/pytest-broadcastercd pytest-broadcaster
- Then install
datamodel-code-generator
:
pip install --user datamodel-code-generator
- Then generate the code:
datamodel-codegen \
--input docs/schemas/ \
--output models/ \
--input-file-type jsonschema \
--disable-timestamp \
--output-model-type=pydantic_v1.BaseModel \
--use-field-description \
--use-schema-description
The generated code will be in the models/
directory.
It's possible to generate .d.ts
files for Typescript using json-schema-to-typescript
:
- First clone the repository:
git clone https://github.com/charbonnierg/pytest-broadcastercd pytest-broadcaster
- Then install
json-schema-to-typescript
:
npm install -g json-schema-to-typescript
- Then generate the code:
json2ts -i docs/schemas/ -o types/
The generated code will be in the types/
directory.