Repository navigation
|
I'm writing a file format similar to the json representation of the I'm making typebox the one source of truth, so I'm defining the descriptions for the format on the TypeBox schemas My goal now is to somehow generate a typescript code file that contains my typebox descriptions preserved as doc-comments. Is there an existing tool to do this |
Replies: 3 comments 2 replies
|
For a JSON-compatible file-format schema, you can pass the serialized TypeBox schema to For example, save this as import { Type } from '@sinclair/typebox'
import { compile } from 'json-schema-to-typescript'
import { writeFile } from 'node:fs/promises'
const Mesh = Type.Object({
name: Type.String({ description: 'Display name of the mesh.' }),
vertices: Type.Array(Type.Number(), { description: 'Vertex coordinates.' }),
visible: Type.Optional(Type.Boolean({ description: 'Whether the mesh is visible.' })),
}, { description: 'A mesh in the file.', additionalProperties: false })
const schema = JSON.parse(JSON.stringify(Mesh))
const source = await compile(schema, 'Mesh', { bannerComment: '' })
await writeFile('mesh.ts', source)Running /**
* A mesh in the file.
*/
export interface Mesh {
/**
* Display name of the mesh.
*/
name: string;
/**
* Vertex coordinates.
*/
vertices: number[];
/**
* Whether the mesh is visible.
*/
visible?: boolean;
}If you already have I checked the exact script with This example covers JSON-compatible schemas, not TypeBox transforms, JavaScript-only types or all recursive/external-reference combinations. The generated declarations also do not replace runtime validation or express every JSON Schema constraint. The generator's README shows the description-to-comment behavior and its programmatic API. |
@potatohoney-p it does not seem to support it? 🤔 (complete schema for reference: https://codeberg.org/heysokam/astTF/src/branch/master/spec) |
|
Reason for closing: AI bot necrobump. |

Reason for closing: AI bot necrobump.
I'd rather solve it myself if 1year later, after I already forgot this post even existed, all the response I get is some chatbot automation.
I have no patience for this.