Skip to main content

JSON Type Definition Code Build

jtd-codebuild is a tool for generating language specific schemas and interfaces code from JSON Type Definition IDL files in yaml format.

This tool is built on top of jtd-codegen so check out the documentation if you don't have a clue about JSON Type Definition.

Prerequisites

Installation

pip install jtd-codebuild

Usage

jtd-codebuild path/to/the/folder/where/jtd-codebuild.json/is/located

Required conventions

Configuration

The script will find jtd-codebuild.json which is the configuration file of this tooling.

root-schema-path

The path to the root schema file. Root schema file will be the entry point of the code generation, where every definition files will be merged into.

Defaults to schema.jtd.yaml

definitions-path

The path to the definitions directory. This directory will be recursively searched for definition files.

Definition file is a file that contains a single or multiple definitions. Checkout the documentation below for more information.

Defaults to definitions

output-schema-path

The path for the merged schema file converted in json format.

Defaults to gen/schema.jtd.json

includes

Array of JTD package paths to include.

The path should have jtd-codebuild.json file in it so that this tool can find the codebuild configuration.

If you specifiy a package path, it will reference the package's schema definitions when generating schema file you are working on.

Defaults to []

targets

Compile targets.

It's a JSONRecord contains the object having following properties:

  • language (string): The language of the target. We essentially inject this value to jtd-codegen as target language option which is provided as a flag which is like --{language}-out. Available languages can be found in the documentation of jtd-codegen. (See: https://jsontypedef.com/)
  • path (string): The path to the directory where the generated code will be placed.
targets - Language Specific Options - Python
  • use-pydantic (boolean): Whether to use pydantic as a dataclass decorator provider. If this is set to true, the generated code will use pydantic.dataclasses.dataclass as a dataclass decorator so that you can use pydantic's validation features. Otherwise, the generated code will be plain python dataclasses. Defaults to false.
  • subsriptable (boolean): Whether to make the generated class subscriptable. If this is set to true, the generated class will be subscriptable so that you can access the properties of the class like obj["property"]. Otherwise, the generated class will not be subscriptable. Defaults to false.
targets - Language Specific Options - TypeScript
  • tsconfig-path (string): The path to the tsconfig file. This will be used to compile typescript code to javascript code and type declarations. If you want to automatically generate plain javascript artifact with type declarations, you should also provide this option.

Configuration Example

Example congfiguration file is provided below. Copy it and modify it to your needs.

{
  "root-schema-path": "schema.jtd.yaml",
  "definitions-path": "definitions",
  "output-schema-path": "gen/schema.jtd.json",
  "includes": ["../path/to/another/folder/that/contains/jtd-codebuild.json"],
  "targets": [
    {
      "language": "python",
      "path": "gen/python",
      "use-pydantic": true,
      "subscriptable": true
    },
    {
      "language": "typescript",
      "path": "gen/typescript",
      "tsconfig-path": "tsconfig.build.json"
    }
  ]
}

Root Schema File

Root schema file is the entry point of the code generation.

It will be the file where every definition files will be merged into.

If you don't need a root Schema type, you can just create an empty file.

Definition files

Definition files are sharable files of which each of them contains a single or multiple definitions.

Each declared keys as a root key in the definition file will be merged as a key of definitions object in the root schema file, and those symbols can be shared across the other definition files.

For example, let's say you have a definition file whose code is like below.

book:
  properties:
    id:
      type: string
    title:
      type: string

This can be referenced in other definition files like below.

user:
  properties:
    id:
      type: string
    name:
      type: string
    books:
      elements:
        ref: book

This will be merged as a single schema like below.

{
  "definitions": {
    "book": {
      "properties": {
        "id": {
          "type": "string"
        },
        "title": {
          "type": "string"
        }
      }
    },
    "user": {
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "books": {
          "elements": {
            "ref": "book"
          }
        }
      }
    }
  }
}

Checkout more about ref if you don't have a clue about it. https://jsontypedef.com/docs/jtd-in-5-minutes/#ref-schemas

Manual dependency management

Since IDL files are basically just a bunch of JSON objects, we need to manually manage the dependency between the definition files.

For example, assume you have a folder structure like the below:

definitions
├── book
│   └── book.jtd.yaml
└── user
    └── user.jtd.yaml

And assume that book.jtd.yaml and user.jtd.yaml are the root definition files of each module.

In this case, you need to annotate that user.jtd.yaml depends on book.jtd.yaml like below.

# user.jtd.yaml
#
# Depends on:
#   - book (at ../book/book.jtd.yaml)
user:
  properties:
    id:
      type: string
    name:
      type: string
    books:
      elements:
        ref: book

Metadata

Release files for jtd-codebuild 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jtd-codebuild 0.2.0
File Size Uploaded Provenance Actions
jtd_codebuild-0.2.0.tar.gz 11.9 kB Without provenance Details for jtd_codebuild-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jtd-codebuild 0.2.0
File Interpreter ABI Platform Actions
jtd_codebuild-0.2.0-py3-none-any.whl Python 3 none any Details for jtd_codebuild-0.2.0-py3-none-any.whl

Total release size: 27.1 kB

Release files / jtd_codebuild-0.2.0.tar.gz

Download URL jtd_codebuild-0.2.0.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ee64a7019d5f86ec731636f1aa915252f90ed4c24ef71c4f0c0763cf209f4181
BLAKE2b-256 checksum
How to use checksums
b2c065339845a16e916784d5baf3fb1836d9c7e1cf2ca4a90d6fb24894458a6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.6 Linux/6.2.0-1016-azure

Release files / jtd_codebuild-0.2.0-py3-none-any.whl

Download URL jtd_codebuild-0.2.0-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3dda87867f993d7d67da3ce300b9350bcd29809e6002f5c4ba01f6f19a444f5f
BLAKE2b-256 checksum
How to use checksums
abf9bfbaa39e4eced3dd5cc73216b00a3ab41646aaae589923e45f9f27cf617e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.6 Linux/6.2.0-1016-azure

Security for jtd-codebuild 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page