Skip to content

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:

  1. First clone the repository:

  1. Then install datamodel-code-generator:

pip install --user datamodel-code-generator

  1. 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:

  1. First clone the repository:

  1. Then install datamodel-code-generator:

pip install --user datamodel-code-generator

  1. 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:

  1. First clone the repository:

  1. Then install datamodel-code-generator:

pip install --user datamodel-code-generator

  1. 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:

  1. First clone the repository:

  1. Then install json-schema-to-typescript:

npm install -g json-schema-to-typescript

  1. Then generate the code:

json2ts -i docs/schemas/ -o types/

The generated code will be in the types/ directory.