# JSON Schema to TypeScript Types This directory contains JSON Schema files that are used to generate TypeScript types automatically. They can also be ported out to Java if needed. A client library will be published soon to Code Artifact to avoid copying these schema definitions to the corresponding project. A new package might be needed for all json schemas. ## Files JSON Schema files should be named using `kebab-case`. - `courses-message.json` - Schema for Courses message formats ## Generating Types To generate TypeScript types based on a single JSON schema file, run ```sh npx json-schema-to-typescript --enableConstEnums --no-additionalProperties --inferStringEnumKeysFromValues --style.singleQuote --style.bracketSpacing --style.tabWidth 4 --style.trailingComma 'es5' \ -i src/jsonschema/input.json -o src/business/types/jsonschema/output.ts ``` This will generate a definition file `src/api/modules/module/business/types/output.ts` based on the JSON schema from `src/jsonschema/input.json`. All other flags are type and style configurations that should be used to maintain consistency with the whole project. For example ```sh npx json-schema-to-typescript --enableConstEnums --no-additionalProperties --inferStringEnumKeysFromValues --style.singleQuote --style.bracketSpacing --style.tabWidth 4 --style.trailingComma 'es5' \ -i src/jsonschema/courses-message.json -o src/business/types/jsonschema/coursesMessage.ts ``` These generated files cannot have the extension `.d.ts`, as they won't be exported from `common` if they are declaration files. ## Updating Schemas 1. Modify the JSON schema file (e.g., `courses-message.json`). 2. Run the above command to regenerate TypeScript types. Never edit the generated `.ts` files. 3. Update your code to use the new types.