{"_id":"@bytemain/ts-json-schema-generator","_rev":"1-103592c7c8124f70285f1f1091982979","name":"@bytemain/ts-json-schema-generator","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.1":{"name":"@bytemain/ts-json-schema-generator","version":"1.0.1","description":"Generate JSON schema from your Typescript sources","main":"dist/index.js","types":"dist/index.d.ts","bin":{"ts-json-schema-generator":"bin/ts-json-schema-generator"},"author":{"name":"Alexander Evtushenko","email":"aevtushenko@xiag.ch"},"contributors":[{"name":"Dominik Moritz","email":"domoritz@gmail.com"},{"name":"MooYeol Prescott Lee","email":"mooyoul@gmail.com"}],"repository":{"type":"git","url":"git+https://github.com/vega/ts-json-schema-generator.git"},"license":"MIT","keywords":["ts","typescript","json","schema","jsonschema"],"engines":{"node":">=10.0.0"},"dependencies":{"@types/json-schema":"^7.0.11","commander":"^10.0.0","glob":"^8.0.3","json5":"^2.2.3","normalize-path":"^3.0.0","safe-stable-stringify":"^2.4.2","typescript":"~5.0.2"},"devDependencies":{"@auto-it/conventional-commits":"^10.43.0","@auto-it/first-time-contributor":"^10.43.0","@babel/core":"^7.21.3","@babel/preset-env":"^7.20.2","@babel/preset-typescript":"^7.21.0","@types/glob":"^8.1.0","@types/jest":"^29.5.0","@types/node":"^20.1.0","@types/normalize-path":"^3.0.0","@typescript-eslint/eslint-plugin":"^5.55.0","@typescript-eslint/parser":"^5.55.0","ajv":"^8.12.0","ajv-formats":"^2.1.1","auto":"^10.43.0","chai":"^4.3.7","cross-env":"^7.0.3","eslint":"^8.36.0","eslint-config-prettier":"^8.7.0","eslint-plugin-prettier":"^4.2.1","jest":"^29.5.0","jest-junit":"^16.0.0","prettier":"^2.8.4","ts-node":"^10.9.1","vega":"^5.22.1","vega-lite":"^5.6.0"},"scripts":{"prepublishOnly":"yarn build","build":"tsc","watch":"tsc -w","lint":"eslint \"{src,test,factory}/**/*.ts\"","format":"yarn lint --fix","test":"jest test/ --verbose","test:fast":"cross-env FAST_TEST=1 jest test/ --verbose","test:coverage":"yarn jest test/ --collectCoverage=true","test:update":"cross-env UPDATE_SCHEMA=true yarn test:fast","debug":"node -r ts-node/register --inspect-brk ts-json-schema-generator.ts","run":"ts-node-transpile-only ts-json-schema-generator.ts","release":"yarn build && auto shipit"},"gitHead":"144145790d4a8e658ee4685059f747792f32691e","bugs":{"url":"https://github.com/vega/ts-json-schema-generator/issues"},"homepage":"https://github.com/vega/ts-json-schema-generator#readme","_id":"@bytemain/ts-json-schema-generator@1.0.1","_nodeVersion":"16.20.0","_npmVersion":"8.19.4","dist":{"integrity":"sha512-b7GxiNhk8f4ZkNC1XxQtkxaucpaV9/QQbBwQSx6wLe2uzggBrveUckm0ee/9kE4xITXSG03c9av7VPzrr+cT+Q==","shasum":"462f2cba235516e74de4b08ba4bda03a3f8b8d03","tarball":"https://registry.npmjs.org/@bytemain/ts-json-schema-generator/-/ts-json-schema-generator-1.0.1.tgz","fileCount":720,"unpackedSize":891212,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAox0nX5M6ENTlNNTSYKYrNi2TX4Bk1efLQPT2kvtPf9AiEA8rpIfBoRBVQ4shVSALkHL6lEsUiIRXHauI6qWTE6do4="}]},"_npmUser":{"name":"lengthmin","email":"lengthmin@gmail.com"},"directories":{},"maintainers":[{"name":"lengthmin","email":"lengthmin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ts-json-schema-generator_1.0.1_1684982161873_0.5002020299644803"},"_hasShrinkwrap":false},"1.0.2":{"name":"@bytemain/ts-json-schema-generator","version":"1.0.2","description":"Generate JSON schema from your Typescript sources","main":"dist/index.js","types":"dist/index.d.ts","bin":{"ts-json-schema-generator":"bin/ts-json-schema-generator"},"author":{"name":"Alexander Evtushenko","email":"aevtushenko@xiag.ch"},"contributors":[{"name":"Dominik Moritz","email":"domoritz@gmail.com"},{"name":"MooYeol Prescott Lee","email":"mooyoul@gmail.com"}],"repository":{"type":"git","url":"git+https://github.com/vega/ts-json-schema-generator.git"},"license":"MIT","keywords":["ts","typescript","json","schema","jsonschema"],"engines":{"node":">=10.0.0"},"dependencies":{"@types/json-schema":"^7.0.11","commander":"^10.0.0","glob":"^8.0.3","json5":"^2.2.3","normalize-path":"^3.0.0","safe-stable-stringify":"^2.4.2","typescript":"~5.0.2"},"devDependencies":{"@auto-it/conventional-commits":"^10.43.0","@auto-it/first-time-contributor":"^10.43.0","@babel/core":"^7.21.3","@babel/preset-env":"^7.20.2","@babel/preset-typescript":"^7.21.0","@types/glob":"^8.1.0","@types/jest":"^29.5.0","@types/node":"^20.1.0","@types/normalize-path":"^3.0.0","@typescript-eslint/eslint-plugin":"^5.55.0","@typescript-eslint/parser":"^5.55.0","ajv":"^8.12.0","ajv-formats":"^2.1.1","auto":"^10.43.0","chai":"^4.3.7","cross-env":"^7.0.3","eslint":"^8.36.0","eslint-config-prettier":"^8.7.0","eslint-plugin-prettier":"^4.2.1","jest":"^29.5.0","jest-junit":"^16.0.0","prettier":"^2.8.4","ts-node":"^10.9.1","vega":"^5.22.1","vega-lite":"^5.6.0"},"scripts":{"prepublishOnly":"yarn build","build":"tsc","watch":"tsc -w","lint":"eslint \"{src,test,factory}/**/*.ts\"","format":"yarn lint --fix","test":"jest test/ --verbose","test:fast":"cross-env FAST_TEST=1 jest test/ --verbose","test:coverage":"yarn jest test/ --collectCoverage=true","test:update":"cross-env UPDATE_SCHEMA=true yarn test:fast","debug":"node -r ts-node/register --inspect-brk ts-json-schema-generator.ts","run":"ts-node-transpile-only ts-json-schema-generator.ts","release":"yarn build && auto shipit"},"gitHead":"e01b7cd752a43c6f2bfdb8095a085eef72208603","bugs":{"url":"https://github.com/vega/ts-json-schema-generator/issues"},"homepage":"https://github.com/vega/ts-json-schema-generator#readme","_id":"@bytemain/ts-json-schema-generator@1.0.2","_nodeVersion":"16.20.0","_npmVersion":"8.19.4","dist":{"integrity":"sha512-cBpM6TC1nkgWL0HaY7zcl8cpBcuhw2A9xtD+CxPVq9DsI5hxkLMDD3q6Me7+OZkAyIGHSKwL607gyhi75aROjQ==","shasum":"364f76b5d09f603101c84d840e7e22faad03f2a3","tarball":"https://registry.npmjs.org/@bytemain/ts-json-schema-generator/-/ts-json-schema-generator-1.0.2.tgz","fileCount":720,"unpackedSize":891169,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE5hAx63SZw2JNxdKAHzh83NYQ+EjEuRsB8sCMqIGqUQAiEA7qOGH+suLlH/0E7hq7dA2FdVEkbWP0JzMLeR1xJ7Rq8="}]},"_npmUser":{"name":"lengthmin","email":"lengthmin@gmail.com"},"directories":{},"maintainers":[{"name":"lengthmin","email":"lengthmin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ts-json-schema-generator_1.0.2_1684984275652_0.31640996156285617"},"_hasShrinkwrap":false}},"time":{"created":"2023-05-25T02:36:01.804Z","1.0.1":"2023-05-25T02:36:02.207Z","modified":"2023-05-25T03:11:16.078Z","1.0.2":"2023-05-25T03:11:15.926Z"},"maintainers":[{"name":"lengthmin","email":"lengthmin@gmail.com"}],"description":"Generate JSON schema from your Typescript sources","homepage":"https://github.com/vega/ts-json-schema-generator#readme","keywords":["ts","typescript","json","schema","jsonschema"],"repository":{"type":"git","url":"git+https://github.com/vega/ts-json-schema-generator.git"},"contributors":[{"name":"Dominik Moritz","email":"domoritz@gmail.com"},{"name":"MooYeol Prescott Lee","email":"mooyoul@gmail.com"}],"author":{"name":"Alexander Evtushenko","email":"aevtushenko@xiag.ch"},"bugs":{"url":"https://github.com/vega/ts-json-schema-generator/issues"},"license":"MIT","readme":"# ts-json-schema-generator\n\n![Test](https://github.com/vega/ts-json-schema-generator/workflows/Test/badge.svg)\n[![codecov](https://codecov.io/gh/vega/ts-json-schema-generator/branch/master/graph/badge.svg)](https://codecov.io/gh/vega/ts-json-schema-generator)\n[![npm version](https://img.shields.io/npm/v/ts-json-schema-generator.svg)](https://www.npmjs.com/package/ts-json-schema-generator)\n\nExtended version of [https://github.com/xiag-ag/typescript-to-json-schema](https://github.com/xiag-ag/typescript-to-json-schema).\n\nInspired by [`YousefED/typescript-json-schema`](https://github.com/YousefED/typescript-json-schema). Here's the differences list:\n\n-   this implementation avoids the use of `typeChecker.getTypeAtLocation()` (so probably it keeps correct type aliases)\n-   processing AST and formatting JSON schema have been split into two independent steps\n-   not exported types, interfaces, enums are not exposed in the `definitions` section in the JSON schema\n\n## Contributors\n\nThis project is made possible by a [community of contributors](https://github.com/vega/ts-json-schema-generator/graphs/contributors). We welcome contributions of any kind (issues, code, documentation, examples, tests,...). Please read our [code of conduct](https://vega.github.io/vega/about/code-of-conduct).\n\n## CLI Usage\n\nRun the schema generator with npx:\n\n```bash\nnpx ts-json-schema-generator --path 'my/project/**/*.ts' --type 'My.Type.Name'\n```\n\nOr install the package and then run it\n\n```bash\nnpm install --save ts-json-schema-generator\n./node_modules/.bin/ts-json-schema-generator --path 'my/project/**/*.ts' --type 'My.Type.Name'\n```\n\nNote that different platforms (e.g. Windows) may use different path separators so you may have to adjust the command above.\n\nAlso note that you need to quote paths with `*` as otherwise the shell will expand the paths and therefore only pass the first path to the generator.\n\n## Programmatic Usage\n\n```js\n// main.js\n\nconst tsj = require(\"ts-json-schema-generator\");\nconst fs = require(\"fs\");\n\n/** @type {import('ts-json-schema-generator/dist/src/Config').Config} */\nconst config = {\n    path: \"path/to/source/file\",\n    tsconfig: \"path/to/tsconfig.json\",\n    type: \"*\", // Or <type-name> if you want to generate schema for that one type only\n};\n\nconst output_path = \"path/to/output/file\";\n\nconst schema = tsj.createGenerator(config).createSchema(config.type);\nconst schemaString = JSON.stringify(schema, null, 2);\nfs.writeFile(output_path, schemaString, (err) => {\n    if (err) throw err;\n});\n```\n\nRun the schema generator via `node main.js`.\n\n### Custom formatting\n\nExtending the built-in formatting is possible by creating a custom formatter and adding it to the main formatter:\n\n1. First we create a formatter, in this case for formatting function types:\n\n```ts\n// my-function-formatter.ts\nimport { BaseType, Definition, FunctionType, SubTypeFormatter } from \"ts-json-schema-generator\";\nimport ts from \"typescript\";\n\nexport class MyFunctionTypeFormatter implements SubTypeFormatter {\n    // You can skip this line if you don't need childTypeFormatter\n    public constructor(private childTypeFormatter: TypeFormatter) {}\n\n    public supportsType(type: FunctionType): boolean {\n        return type instanceof FunctionType;\n    }\n\n    public getDefinition(type: FunctionType): Definition {\n        // Return a custom schema for the function property.\n        return {\n            type: \"object\",\n            properties: {\n                isFunction: {\n                    type: \"boolean\",\n                    const: true,\n                },\n            },\n        };\n    }\n\n    // If this type does NOT HAVE children, generally all you need is:\n    public getChildren(type: FunctionType): BaseType[] {\n        return [];\n    }\n\n    // However, if children ARE supported, you'll need something similar to\n    // this (see src/TypeFormatter/{Array,Definition,etc}.ts for some examples):\n    public getChildren(type: FunctionType): BaseType[] {\n        return this.childTypeFormatter.getChildren(type.getType());\n    }\n}\n```\n\n2. Then we add the formatter as a child to the core formatter using the augmentation callback:\n\n```ts\nimport { createProgram, createParser, SchemaGenerator, createFormatter } from \"ts-json-schema-generator\";\nimport { MyFunctionTypeFormatter } from \"./my-function-formatter.ts\";\nimport fs from \"fs\";\n\nconst config = {\n    path: \"path/to/source/file\",\n    tsconfig: \"path/to/tsconfig.json\",\n    type: \"*\", // Or <type-name> if you want to generate schema for that one type only\n};\n\n// We configure the formatter an add our custom formatter to it.\nconst formatter = createFormatter(config, (fmt, circularReferenceTypeFormatter) => {\n    // If your formatter DOES NOT support children, e.g. getChildren() { return [] }:\n    fmt.addTypeFormatter(new MyFunctionTypeFormatter());\n    // If your formatter DOES support children, you'll need this reference too:\n    fmt.addTypeFormatter(new MyFunctionTypeFormatter(circularReferenceTypeFormatter));\n});\n\nconst program = createProgram(config);\nconst parser = createParser(program, config);\nconst generator = new SchemaGenerator(program, parser, formatter, config);\nconst schema = generator.createSchema(config.type);\n\nconst schemaString = JSON.stringify(schema, null, 2);\nfs.writeFile(output_path, schemaString, (err) => {\n    if (err) throw err;\n});\n```\n\n### Custom parsing\n\nSimilar to custom formatting, extending the built-in parsing works practically the same way:\n\n1. First we create a parser, in this case for parsing construct types:\n\n```ts\n// my-constructor-parser.ts\nimport { Context, StringType, ReferenceType, BaseType, SubNodeParser } from \"ts-json-schema-generator\";\n// use typescript exported by TJS to avoid version conflict\nimport ts from \"ts-json-schema-generator\";\n\nexport class MyConstructorParser implements SubNodeParser {\n    supportsNode(node: ts.Node): boolean {\n        return node.kind === ts.SyntaxKind.ConstructorType;\n    }\n    createType(node: ts.Node, context: Context, reference?: ReferenceType): BaseType | undefined {\n        return new StringType(); // Treat constructors as strings in this example\n    }\n}\n```\n\n2. Then we add the parser as a child to the core parser using the augmentation callback:\n\n```ts\nimport { createProgram, createParser, SchemaGenerator, createFormatter } from \"ts-json-schema-generator\";\nimport { MyConstructorParser } from \"./my-constructor-parser.ts\";\nimport fs from \"fs\";\n\nconst config = {\n    path: \"path/to/source/file\",\n    tsconfig: \"path/to/tsconfig.json\",\n    type: \"*\", // Or <type-name> if you want to generate schema for that one type only\n};\n\nconst program = createProgram(config);\n\n// We configure the parser an add our custom parser to it.\nconst parser = createParser(program, config, (prs) => {\n    prs.addNodeParser(new MyConstructorParser());\n});\n\nconst formatter = createFormatter(config);\nconst generator = new SchemaGenerator(program, parser, formatter, config);\nconst schema = generator.createSchema(config.type);\n\nconst schemaString = JSON.stringify(schema, null, 2);\nfs.writeFile(output_path, schemaString, (err) => {\n    if (err) throw err;\n});\n```\n\n## Options\n\n```\n-p, --path 'index.ts'\n    The path to the TypeScript source file. If this is not provided, the type will be searched in the project specified in the `.tsconfig`.\n\n-t, --type 'My.Type.Name'\n    The type the generated schema will represent. If omitted, the generated schema will contain all\n    types found in the files matching path. The same is true if '*' is specified.\n\n-i, --id 'generatedSchemaId'\n    The `$id` of the generated schema. If omitted, there will be no `$id`.\n\n-e, --expose <all|none|export>\n    all: Create shared $ref definitions for all types.\n    none: Do not create shared $ref definitions.\n    export (default): Create shared $ref definitions only for exported types (not tagged as `@internal`).\n\n-f, --tsconfig 'my/project/tsconfig.json'\n    Use a custom tsconfig file for processing typescript (see https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) instead of the default:\n    {\n        \"compilerOptions\": {\n            \"noEmit\": true,\n            \"emitDecoratorMetadata\": true,\n            \"experimentalDecorators\": true,\n            \"target\": \"ES5\",\n            \"module\": \"CommonJS\",\n            \"strictNullChecks\": false,\n        }\n    }\n\n-j, --jsDoc <extended|none|basic>\n    none: Do not use JsDoc annotations.\n    basic: Read JsDoc annotations to provide schema properties.\n    extended (default): Also read @nullable, and @asType annotations.\n\n--unstable\n    Do not sort properties.\n\n--strict-tuples\n    Do not allow additional items on tuples.\n\n--no-top-ref\n    Do not create a top-level $ref definition.\n\n--no-type-check\n    Skip type checks for better performance.\n\n--no-ref-encode\n    Do not encode references. According to the standard, references must be valid URIs but some tools do not support encoded references.\n\n--validation-keywords\n    Provide additional validation keywords to include.\n\n-o, --out\n    Specify the output file path. Without this option, the generator logs the response in the console.\n\n--additional-properties <true|false>\n    Controls whether or not to allow additional properties for objects that have no index signature.\n\n    true: Additional properties are allowed\n    false (default): Additional properties are not allowed\n\n--minify\n    Minify generated schema (default: false)\n```\n\n## Current state\n\n-   `interface` types\n-   `enum` types\n-   `union`, `tuple`, `type[]` types\n-   `Date`, `RegExp`, `URL` types\n-   `string`, `boolean`, `number` types\n-   `\"value\"`, `123`, `true`, `false`, `null`, `undefined` literals\n-   type aliases\n-   generics\n-   `typeof`\n-   `keyof`\n-   conditional types\n\n## Run locally\n\n`yarn --silent run run --path 'test/valid-data/type-mapped-array/*.ts' --type 'MyObject'`\n\n## Debug\n\n`yarn --silent run debug --path 'test/valid-data/type-mapped-array/*.ts' --type 'MyObject'`\n\nAnd connect via the debugger protocol.\n\n[AST Explorer](https://astexplorer.net/) is amazing for developers of this tool!\n\n## Publish\n\nPublishing is handled by a 2-branch [pre-release process](https://intuit.github.io/auto/docs/generated/shipit#next-branch-default), configured in `publish-auto.yml`. All changes should be based off the default `next` branch, and are published automatically.\n\n-   PRs made into the default branch are auto-deployed to the `next` pre-release tag on NPM. The result can be installed with `npm install ts-json-schema-generator@next`\n    -   When merging into `next`, please use the `squash and merge` strategy.\n-   To release a new stable version, open a PR from `next` into `stable` using this [compare link](https://github.com/vega/ts-json-schema-generator/compare/stable...next).\n    -   When merging from `next` into `stable`, please use the `create a merge commit` strategy.\n","readmeFilename":"README.md"}