|
| 1 | +import type ts from "typescript"; |
| 2 | + |
1 | 3 | export interface Config { |
| 4 | + /** |
| 5 | + * Glob pattern(s) for source TypeScript files to process. |
| 6 | + * If not provided, falls back to files from tsconfig. |
| 7 | + */ |
2 | 8 | path?: string; |
| 9 | + |
| 10 | + /** |
| 11 | + * Name of the type/interface to generate schema for. |
| 12 | + * Use "*" to generate schemas for all exported types. |
| 13 | + */ |
3 | 14 | type?: string; |
| 15 | + |
| 16 | + /** |
| 17 | + * Minify the output JSON schema (no whitespace). |
| 18 | + * When false, the schema is pretty-printed with 2-space indentation. |
| 19 | + * @default false |
| 20 | + */ |
4 | 21 | minify?: boolean; |
| 22 | + |
| 23 | + /** |
| 24 | + * Sets the `$id` property in the root of the generated schema. |
| 25 | + * Used for schema identification and referencing. |
| 26 | + */ |
5 | 27 | schemaId?: string; |
| 28 | + |
| 29 | + /** |
| 30 | + * Path to a custom tsconfig.json file for TypeScript compilation. |
| 31 | + * If not provided, uses default TypeScript configuration. |
| 32 | + */ |
6 | 33 | tsconfig?: string; |
| 34 | + |
| 35 | + /** |
| 36 | + * Controls which types are exposed as definitions in the schema. |
| 37 | + * - "all": Exposes all types except type literals |
| 38 | + * - "none": Exposes no types automatically |
| 39 | + * - "export": Only exposes exported types (respects @internal JSDoc tag) |
| 40 | + * @default "export" |
| 41 | + */ |
7 | 42 | expose?: "all" | "none" | "export"; |
| 43 | + |
| 44 | + /** |
| 45 | + * Wraps the root type in a `$ref` definition. |
| 46 | + * When false, inlines the root type definition directly. |
| 47 | + * @default true |
| 48 | + */ |
8 | 49 | topRef?: boolean; |
| 50 | + |
| 51 | + /** |
| 52 | + * Controls how JSDoc comments are parsed and included in the schema. |
| 53 | + * - "none": Ignores all JSDoc annotations |
| 54 | + * - "basic": Parses standard JSON Schema JSDoc tags |
| 55 | + * - "extended": Parses all tags plus descriptions, examples, and type overrides |
| 56 | + * @default "extended" |
| 57 | + */ |
9 | 58 | jsDoc?: "none" | "extended" | "basic"; |
| 59 | + |
| 60 | + /** |
| 61 | + * Adds a `markdownDescription` field alongside `description` in the schema. |
| 62 | + * Preserves markdown formatting including newlines. |
| 63 | + * Only works with `jsDoc: "extended"`. |
| 64 | + * @default false |
| 65 | + */ |
10 | 66 | markdownDescription?: boolean; |
| 67 | + |
| 68 | + /** |
| 69 | + * Includes the complete raw JSDoc comment as `fullDescription` in the schema. |
| 70 | + * Only works with `jsDoc: "extended"`. |
| 71 | + * @default false |
| 72 | + */ |
11 | 73 | fullDescription?: boolean; |
| 74 | + |
| 75 | + /** |
| 76 | + * Sorts object properties alphabetically in the output. |
| 77 | + * @default true |
| 78 | + */ |
12 | 79 | sortProps?: boolean; |
| 80 | + |
| 81 | + /** |
| 82 | + * Controls whether tuples allow additional items beyond their defined length. |
| 83 | + * @default false |
| 84 | + */ |
13 | 85 | strictTuples?: boolean; |
| 86 | + |
| 87 | + /** |
| 88 | + * Skips TypeScript type checking to improve performance. |
| 89 | + * Speeds up generation but may miss type errors. |
| 90 | + * @default false |
| 91 | + */ |
14 | 92 | skipTypeCheck?: boolean; |
| 93 | + |
| 94 | + /** |
| 95 | + * URI-encodes `$ref` values (e.g., `#/definitions/Foo%3CBar%3E`). |
| 96 | + * When false, uses raw names in reference paths. |
| 97 | + * @default true |
| 98 | + */ |
15 | 99 | encodeRefs?: boolean; |
| 100 | + |
| 101 | + /** |
| 102 | + * Array of additional JSDoc tag names to include in the schema. |
| 103 | + * Custom tags (e.g., `@customProperty`) are parsed and included in output. |
| 104 | + * Values are parsed as JSON5. |
| 105 | + * @default [] |
| 106 | + */ |
16 | 107 | extraTags?: string[]; |
| 108 | + |
| 109 | + /** |
| 110 | + * Sets default value for `additionalProperties` on objects without index signatures. |
| 111 | + * When false, objects get `additionalProperties: false` by default. |
| 112 | + * When true, allows additional properties on all objects. |
| 113 | + * @default false |
| 114 | + */ |
17 | 115 | additionalProperties?: boolean; |
| 116 | + |
| 117 | + /** |
| 118 | + * Controls discriminator style for discriminated unions. |
| 119 | + * - "json-schema": Uses `if`/`then`/`allOf` with properties containing discriminator enum |
| 120 | + * - "open-api": Uses OpenAPI 3.x style with `discriminator: { propertyName }` and `oneOf` |
| 121 | + * @default "json-schema" |
| 122 | + */ |
18 | 123 | discriminatorType?: "json-schema" | "open-api"; |
| 124 | + |
| 125 | + /** |
| 126 | + * Controls how function types are handled in the schema. |
| 127 | + * - "fail": Throws error when encountering function types |
| 128 | + * - "comment": Generates schema with `$comment` describing the function signature |
| 129 | + * - "hide": Treats functions as NeverType (excluded from schema) |
| 130 | + * @default "comment" |
| 131 | + */ |
19 | 132 | functions?: FunctionOptions; |
| 133 | + |
| 134 | + /** |
| 135 | + * Pre-compiled TypeScript Program instance to use. |
| 136 | + * Bypasses the default setup of a TypeScript program, and so some configuration options may not be applied. |
| 137 | + * Useful for programmatic usage with existing TypeScript compilation, or for vfs scenarios where you do not want file-system representation. |
| 138 | + */ |
| 139 | + tsProgram?: ts.Program; |
20 | 140 | } |
21 | 141 |
|
22 | 142 | export type CompletedConfig = Config & typeof DEFAULT_CONFIG; |
23 | 143 |
|
24 | 144 | export type FunctionOptions = "fail" | "comment" | "hide"; |
25 | 145 |
|
26 | | -export const DEFAULT_CONFIG: Omit<Required<Config>, "path" | "type" | "schemaId" | "tsconfig"> = { |
| 146 | +export const DEFAULT_CONFIG: Omit<Required<Config>, "path" | "type" | "schemaId" | "tsconfig" | "tsProgram"> = { |
27 | 147 | expose: "export", |
28 | 148 | topRef: true, |
29 | 149 | jsDoc: "extended", |
|
0 commit comments