{"_id":"@amir.best/ts-json-schema-generator","name":"@amir.best/ts-json-schema-generator","dist-tags":{"latest":"1.0.1-alpha.1"},"versions":{"1.0.1-alpha.1":{"name":"@amir.best/ts-json-schema-generator","version":"1.0.1-alpha.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":"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.9","commander":"^9.0.0","glob":"^8.0.1","json5":"^2.2.0","normalize-path":"^3.0.0","safe-stable-stringify":"^2.3.1"},"devDependencies":{"@auto-it/conventional-commits":"^10.32.5","@auto-it/first-time-contributor":"^10.32.5","@babel/core":"^7.16.7","@babel/preset-env":"^7.16.8","@babel/preset-typescript":"^7.16.7","@types/glob":"^7.2.0","@types/jest":"^28.1.1","@types/node":"^18.0.0","@types/normalize-path":"^3.0.0","@typescript-eslint/eslint-plugin":"^5.9.1","@typescript-eslint/parser":"^5.9.1","ajv":"^8.8.2","ajv-formats":"^2.1.1","auto":"^10.32.5","chai":"^4.3.4","cross-env":"^7.0.3","eslint":"^8.6.0","eslint-config-prettier":"^8.3.0","eslint-plugin-prettier":"^4.0.0","jest":"^28.0.3","jest-junit":"^14.0.0","prettier":"^2.5.1","ts-node":"^10.4.0","typescript":"~4.7.2","vega":"^5.21.0","vega-lite":"^5.2.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"},"peerDependencies":{"typescript":"4"},"licenseText":"The MIT License\n\nCopyright (c) 2019, TypeScript JSON Schema Generator\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","_id":"@amir.best/ts-json-schema-generator@1.0.1-alpha.1","dist":{"shasum":"a43edc148c137386a805019da32e15f3fb543c41","integrity":"sha512-r2/eTNx5WVe1FkETQtLo67034cni5XRB1SMsze3KC3ZKLjekZcXqZsFnt2b2iVyGRYC+pt3PS+A5NVq/Y57vaQ==","tarball":"https://registry.npmjs.org/@amir.best/ts-json-schema-generator/-/ts-json-schema-generator-1.0.1-alpha.1.tgz","fileCount":709,"unpackedSize":814779,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCpg98FJsjIb2pEv6BixWnrDzg8V3sxrniiGTDNyqnS4QIhAKfBm8g4Efv4gi2vZ+Dfn9UoYE4lm731z+sRjjRir9vG"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiu3piACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmrkmg/9Eq7ex5PKElEiVyviW2ex5M72t9HlWhGGwpBMeiU7K+MhDLpM\r\nqV+ZnKEfnE5I6tQoS866us9dcjAQQRxwDdJaOzfNLAXoj14VIjvdJxDFWQ0r\r\n3b9U8J8bmnMS0mKbFYsSf81JbFI4hTuDyyQvjAiwYXzSeQ3adl6jmdVwwyy3\r\nxc/N8CydoGYvzWnlp3iEiyPEDbbtqTINDCAGqwD7BjMH9hqwWGb1Qony5fHt\r\nRkKs8owq9Rv9bQWBjeh+WigH0+2I/YlHRmjApp+cGsRqrWdmFMx6yfM8C4gT\r\na0+tTBsGBHjcO3EqK+JY56P6IoBi+JLKpzEXwtte1V8UvnQ1AT3hnm3co8nC\r\nTXz1E4QduVCTHrJvwfX2Y40kftOLdUCy/4GQARj2+JTJVYVPPuZH4pjhe2R6\r\nEXo+sZAZ01Ylw9N+NDomgYoLH9t+XiieCo9vYrARfiI99Idfc4zkdv1TSB7Y\r\nI7YvLdcmUp9wjxqrqJxJBAV2zBngasG05DhnHa2ulB5QVp3uBm34mTqaSdsw\r\nwbDAwvS60GxddAAW8HVIiBNL9ed/GmYZkYp9MbejlU7jY4VbQGGyY5Ilm2Zv\r\nCZkK5kOdHMiAiQN5leuZporUu49jVElkForvSNf5vyfwinI5hyTJz1x12Ups\r\n8s5hEHkRvV1BN9i/pLYBGpGQADinjCJTC+w=\r\n=rNTe\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"amir.al.omari","email":"me@amir.best"},"directories":{},"maintainers":[{"name":"amir.al.omari","email":"me@amir.best"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ts-json-schema-generator_1.0.1-alpha.1_1656453730455_0.8628615392262162"},"_hasShrinkwrap":false}},"time":{"created":"2022-06-28T22:02:10.394Z","1.0.1-alpha.1":"2022-06-28T22:02:10.703Z","modified":"2022-06-28T22:02:10.862Z"},"maintainers":[{"name":"amir.al.omari","email":"me@amir.best"}],"description":"Generate JSON schema from your Typescript sources","keywords":["ts","typescript","json","schema","jsonschema"],"repository":{"type":"git","url":"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"},"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\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\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\";\nimport ts from \"typescript\";\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` 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"}