### Minimal JSON Schema Example Source: https://github.com/xddq/schema2typebox/blob/main/issue_template.md A sample JSON schema structure used to demonstrate issues with object properties, constraints, and enums. ```json { "title": "Person", "type": "object", "properties": { "name": { "type": "string", "minLength": 20 }, "age": { "type": "number", "minimum": 18, "maximum": 90 }, "hobbies": { "type": "array", "minItems": 1, "items": { "type": "string" } }, "favoriteAnimal": { "enum": ["dog", "cat", "sloth"] } }, "required": ["name", "age"] } ``` -------------------------------- ### Display CLI Help Menu Source: https://github.com/xddq/schema2typebox/blob/main/README.md Displays the help menu for the schema2typebox CLI, detailing available arguments and usage. ```text schema2typebox generates TypeBox code from JSON schemas. The generated output is formatted based on the prettier config inside your repo (or the default one, if you don't have one). Version: ${packageJson.version} Usage: schema2typebox [ARGUMENTS] Arguments: -h, --help Displays this menu. -i, --input Specifies the relative path to the file containing the JSON schema that will be used to generated typebox code. Defaults to "schema.json". -o, --output Specifies the relative path to generated file that will contain the typebox code. Defaults to "generated-typebox.ts". --output-stdout Does not generate an output file and prints the generated code to stdout instead. Has precedence over -o/--output. ``` -------------------------------- ### Handle Multi-file Schemas with $ref Source: https://github.com/xddq/schema2typebox/blob/main/README.md Demonstrates how to resolve relative file references when splitting schemas across multiple files. ```json // person.json { "title": "Person", "type": "object", "properties": { "name": { "type": "string", "maxLength": 100 }, "age": { "type": "number", "minimum": 18 } }, "required": ["name", "age"] } // status.json { "title": "Status", "enum": ["unknown", "accepted", "denied"] } // schema.json { "title": "Contract", "type": "object", "properties": { "person": { "$ref": "./person.json" }, "status": { "$ref": "./status.json" } }, "required": ["person"] } ``` ```typescript export type Contract = Static; export const Contract = Type.Object({ person: Type.Object({ name: Type.String({ maxLength: 100 }), age: Type.Number({ minimum: 18 }), }), status: Type.Optional( Type.Union([ Type.Literal("unknown"), Type.Literal("accepted"), Type.Literal("denied"), ]) ), }); ``` -------------------------------- ### Convert JSON Schema to TypeBox Source: https://github.com/xddq/schema2typebox/blob/main/README.md Transforms a standard JSON schema object into a TypeBox Type.Object definition. ```typescript { "title": "Person", "type": "object", "properties": { "name": { "type": "string", "minLength": 20 }, "age": { "type": "number", "minimum": 18, "maximum": 90 }, "hobbies": { "type": "array", "minItems": 1, "items": { "type": "string" } }, "favoriteAnimal": { "enum": ["dog", "cat", "sloth"] } }, "required": ["name", "age"] } export type Person = Static; export const Person = Type.Object({ name: Type.String({ minLength: 20 }), age: Type.Number({ minimum: 18, maximum: 90 }), hobbies: Type.Optional(Type.Array(Type.String(), { minItems: 1 })), favoriteAnimal: Type.Optional( Type.Union([ Type.Literal("dog"), Type.Literal("cat"), Type.Literal("sloth"), ]) ), }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.