{"_id":"@cappasityinc/json-schema-to-typescript","_rev":"19-4fd787874b4a52f2a17b55886bf0c4c1","name":"@cappasityinc/json-schema-to-typescript","dist-tags":{"latest":"8.0.0"},"versions":{"8.0.0":{"name":"@cappasityinc/json-schema-to-typescript","version":"8.0.0","keywords":["json","schema","typescript","compile","transpile","api","interface","typing","share"],"author":{"url":"http://performancejs.com/","name":"Boris Cherny","email":"boris@performancejs.com"},"license":"MIT","_id":"@cappasityinc/json-schema-to-typescript@8.0.0","maintainers":[{"name":"tokarov","email":"o.tokar@cappasity.com"},{"name":"avvs","email":"v@aminev.me"},{"name":"cappasity","email":"k.popov@cappasity.com"}],"homepage":"https://github.com/cappasityinc/json-schema-to-typescript#readme","bugs":{"url":"https://github.com/cappasityinc/json-schema-to-typescript/issues"},"ava":{"files":["./dist/test/test.js"],"vebose":true,"sources":["./dist/test/e2e/*.js","./dist/test/normalizer/*.json","./dist/src/*.js","./test/resources/*.json"],"snapshotDir":"./test/__snapshots__"},"bin":{"cjson2ts":"dist/src/cli.js"},"dist":{"shasum":"310ec20655bcd62eab7bcb3fc84d236e3637f30b","tarball":"https://registry.npmjs.org/@cappasityinc/json-schema-to-typescript/-/json-schema-to-typescript-8.0.0.tgz","fileCount":53,"integrity":"sha512-0gnDv4QDQr9yWh1tNWqzH1WafHVPD1nCggUsRF5Cn67bsapJAqJIL7ZFeeqUA2eXrkiGnmgSqyHd5bwMALtKSg==","signatures":[{"sig":"MEUCIQDxlAdQF1oJMyPZgAlkPDT+UeY2GSSCQUKjYOwP10MTEAIgL8kaHcvZvsYCRCTq4j4gOP9xzmApuoD21miF4rAN6P0=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":131053,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdljriCRA9TVsSAnZWagAA3REQAJ3PSal8GV0ggRc59L8y\n+SGlsN/ld23yM5egs9JWv73y9SZL8c7727XEVB2URZOmT2i6/ul7ObG5EGpJ\nuOxa+EW4hzNHSZtK5nQYqPlVm/zonKrbq3F29jw0IoWsFMWvMeFSej8dMjmM\nVgzqXTTSTep5oh9kI3vimuyd0f5tuKp7ikQV0kX35UuhRnprPPk/COOFk8b6\nkRchINUX/GEKUZXzmjEUmqV49PYa8Evu4AtKnRVknyb3QWSlXPrW9NFhN8gJ\nSC/NnKusrD71icmuq/bMW8GTMd1uU2jHei19GTInZcxscVOuepKkaYSGa8/+\nEjXM8VYdqJ9PHP+2nTYo2B2PySeLgaS1OdYZuxvsdza7luP7Fvwd1te+wuJw\nkTYIFxdiT1AlqYbbnDvQS4KQB7wtEPcyNJUu/yPAU8eVYA4z66TdkfWO/MmA\n56WoAHnUayiXqq8oHEXGNpLaXTaxPHPZYX3LytAiAgGrhq/X3BzZpN3AtHvn\npE6W5mv6Mi5ExNhZBPINfozjnvn0UyrMTk1Ovi3zyDtmBL4YjYqQ+eqmAsIT\nIxekxYXLyuw8I9TcE9NJpFEzwG7XBHad3WkbPbLjOFZ5kaj/+e4QR3Rj9XVh\nF14cbo4lirc/s3SWXQmyVKBU8k2EXCtbaQ23p5ofr5oOxBNj37lMkfdAtxlA\neR7U\r\n=ThPf\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/src/index.js","engines":{"node":">=10.15.0"},"scripts":{"tdd":"concurrently -r -p '' -k 'yarn watch' 'yarn watch:test'","lint":"tslint -c tslint.json src/*.ts","test":"ava --verbose","build":"yarn clean && mkdir dist && yarn build:server","clean":"rimraf dist","watch":"tsc -w","pretest":"yarn build","watch:test":"ava -w","build:server":"tsc -d","prepublishOnly":"npm test"},"typings":"dist/src/index.d.ts","_npmUser":{"name":"avvs","email":"v@aminev.me"},"browserify":{"transform":["browserify-shim"]},"repository":{"url":"git+https://github.com/cappasityinc/json-schema-to-typescript.git","type":"git"},"description":"compile json schema to typescript typings","directories":{},"dependencies":{"mz":"^2.7.0","glob":"^7.1.4","yargs":"^14.0.0","lodash":"^4.17.15","is-glob":"^4.0.1","prettier":"^1.18.2","cli-color":"^1.4.0","get-stdin":"^7.0.0","json-stringify-safe":"^5.0.1","@cappasityinc/json-schema-ref-parser":"^7.1.4"},"_hasShrinkwrap":false,"browserify-shim":{"prettier":"global:prettier"},"devDependencies":{"ava":"^2.4.0","shx":"^0.3.2","tsify":"^4.0.1","rimraf":"^3.0.0","tslint":"^5.20.0","@types/mz":"0.0.32","browserify":"^16.5.0","typescript":"^3.6.3","@types/glob":"^7.1.1","@types/node":">=12.7.10","@types/yargs":"^13.0.3","concurrently":"^4.1.2","@types/lodash":"^4.14.141","@types/is-glob":"^4.0.1","tsconfig-paths":"^3.9.0","@types/prettier":"^1.18.2","browserify-shim":"^3.8.14","@types/cli-color":"^0.3.29","@types/get-stdin":"^7.0.0","@types/json-schema":"^7.0.3","@types/json-stringify-safe":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/json-schema-to-typescript_8.0.0_1570126562038_0.8523563006831463","host":"s3://npm-registry-packages"}}},"time":{"created":"2019-10-03T18:16:01.805Z","modified":"2026-01-23T17:09:50.978Z","8.0.0":"2019-10-03T18:16:02.194Z"},"bugs":{"url":"https://github.com/cappasityinc/json-schema-to-typescript/issues"},"author":{"url":"http://performancejs.com/","name":"Boris Cherny","email":"boris@performancejs.com"},"license":"MIT","homepage":"https://github.com/cappasityinc/json-schema-to-typescript#readme","keywords":["json","schema","typescript","compile","transpile","api","interface","typing","share"],"repository":{"url":"git+https://github.com/cappasityinc/json-schema-to-typescript.git","type":"git"},"description":"compile json schema to typescript typings","maintainers":[{"email":"storis2012@yandex.ru","name":"v.latyshev"},{"email":"k.popov@cappasity.com","name":"cappasity"},{"email":"o.tokar@cappasity.com","name":"tokarov"},{"email":"sorokin.sh@gmail.com","name":"sorokinsh"}],"readme":"# json-schema-to-typescript [![Build Status][build]](https://circleci.com/gh/bcherny/json-schema-to-typescript) [![npm]](https://www.npmjs.com/package/json-schema-to-typescript) [![mit]](https://opensource.org/licenses/MIT)\n\n[build]: https://img.shields.io/circleci/project/github/bcherny/json-schema-to-typescript/master.svg?style=flat-square\n[npm]: https://img.shields.io/npm/v/json-schema-to-typescript.svg?style=flat-square\n[mit]: https://img.shields.io/npm/l/json-schema-to-typescript.svg?style=flat-square\n\n> Compile json schema to typescript typings\n\n## Example\n\nInput:\n```json\n{\n  \"title\": \"Example Schema\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"firstName\": {\n      \"type\": \"string\"\n    },\n    \"lastName\": {\n      \"type\": \"string\"\n    },\n    \"age\": {\n      \"description\": \"Age in years\",\n      \"type\": \"integer\",\n      \"minimum\": 0\n    },\n    \"hairColor\": {\n      \"enum\": [\"black\", \"brown\", \"blue\"],\n      \"type\": \"string\"\n    }\n  },\n  \"additionalProperties\": false,\n  \"required\": [\"firstName\", \"lastName\"]\n}\n```\n\nOutput:\n```ts\nexport interface ExampleSchema {\n  firstName: string;\n  lastName: string;\n  /**\n   * Age in years\n   */\n  age?: number;\n  hairColor?: \"black\" | \"brown\" | \"blue\";\n}\n```\n\n## Installation\n\n```sh\n# Using Yarn:\nyarn add json-schema-to-typescript\n\n# Or, using NPM:\nnpm install json-schema-to-typescript --save\n```\n\n## Usage\n\n```js\nimport { compile, compileFromFile } from 'json-schema-to-typescript'\n\n// compile from file\ncompileFromFile('foo.json')\n  .then(ts => fs.writeFileSync('foo.d.ts', ts))\n\n// or, compile a JS object\nlet mySchema = {\n  properties: [...]\n}\ncompile(mySchema, 'MySchema')\n  .then(ts => ...)\n```\n\nSee [server demo](example) and [browser demo](https://github.com/bcherny/json-schema-to-typescript-browser) for full examples.\n\n## Options\n\n`compileFromFile` and `compile` accept options as their last argument (all keys are optional):\n\n| key | type | default | description |\n|-|-|-|-|\n| bannerComment | string | `\"/* tslint:disable */\\n/**\\n* This file was automatically generated by json-schema-to-typescript.\\n* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,\\n* and run json-schema-to-typescript to regenerate this file.\\n*/\"` | Disclaimer comment prepended to the top of each generated file |\n| cwd | string | `process.cwd()` | Root directory for resolving [`$ref`](https://tools.ietf.org/id/draft-pbryan-zyp-json-ref-03.html)s |\n| declareExternallyReferenced | boolean | `true` | Declare external schemas referenced via `$ref`? |\n| enableConstEnums | boolean | `true` | Prepend enums with [`const`](https://www.typescriptlang.org/docs/handbook/enums.html#computed-and-constant-members)? |\n| style | object | `{ bracketSpacing: false,  printWidth: 120,  semi: true,  singleQuote: false,  tabWidth: 2,  trailingComma: 'none',  useTabs: false }` | A [Prettier](https://prettier.io/docs/en/options.html) configuration |\n| unreachableDefinitions | boolean | `false` | Generates code for `definitions` that aren't referenced by the schema. |\n| strictIndexSignatures | boolean | `false` | Append all index signatures with `| undefined` so that they are strictly typed. |\n| $refOptions | object | `{}` | [$RefParser](https://github.com/BigstickCarpet/json-schema-ref-parser) Options, used when resolving `$ref`s |\n## CLI\n\nA simple CLI utility is provided with this package.\n\n```sh\ncat foo.json | json2ts > foo.d.ts\n# or\njson2ts foo.json > foo.d.ts\n# or\njson2ts foo.json foo.d.ts\n# or\njson2ts foo.json --output foo.d.ts\n# or\njson2ts -i foo.json -o foo.d.ts\n```\n\nYou can pass any of the options described above (including style options) as CLI flags. Boolean values can be set to false using the `no-` prefix.\n\n```sh\n# generate code for definitions that aren't referenced\njson2ts -i foo.json -o foo.d.ts --unreachableDefinitions\n# use single quotes and disable trailing semicolons\njson2ts -i foo.json -o foo.d.ts --style.singleQuote --no-style.semi\n```\n\n## Tests\n\n`npm test`\n\n## Features\n\n- [x] `title` => `interface`\n- [x] Primitive types:\n  - [x] array\n  - [x] homogeneous array\n  - [x] boolean\n  - [x] integer\n  - [x] number\n  - [x] null\n  - [x] object\n  - [x] string\n  - [x] homogeneous enum\n  - [x] heterogeneous enum\n- [x] Non/extensible interfaces\n- [ ] Custom JSON-schema extensions\n- [x] Nested properties\n- [x] Schema definitions\n- [x] [Schema references](http://json-schema.org/latest/json-schema-core.html#rfc.section.7.2.2)\n- [x] Local (filesystem) schema references\n- [x] External (network) schema references\n- [x] Add support for running in browser\n- [x] default interface name\n- [x] infer unnamed interface name from filename\n- [x] `allOf` (\"intersection\")\n- [x] `anyOf` (\"union\")\n- [x] `oneOf` (treated like `anyOf`)\n- [x] `maxItems` ([eg](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L166))\n- [x] `minItems` ([eg](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L165))\n- [x] `additionalProperties` of type\n- [x] `patternProperties` (partial support)\n- [x] [`extends`](https://github.com/json-schema/json-schema/wiki/Extends)\n- [x] `required` properties on objects ([eg](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L130))\n- [ ] `validateRequired` ([eg](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L124))\n- [x] literal objects in enum ([eg](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L236))\n- [x] referencing schema by id ([eg](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L331))\n- [x] custom typescript types via `tsType`\n\n## Not expressible in TypeScript:\n\n- `dependencies` ([single](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L261), [multiple](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L282))\n- `divisibleBy` ([eg](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L185))\n- [`format`](https://github.com/json-schema/json-schema/wiki/Format) ([eg](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L209))\n- `multipleOf` ([eg](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L186))\n- `maximum` ([eg](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L183))\n- `minimum` ([eg](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L182))\n- `maxProperties` ([eg](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L113))\n- `minProperties` ([eg](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L112))\n- `not`/`disallow`\n- `oneOf` (\"xor\", use `anyOf` instead)\n- `pattern` ([string](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L203), [regex](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L207))\n- `uniqueItems` ([eg](https://github.com/tdegrunt/jsonschema/blob/67c0e27ce9542efde0bf43dc1b2a95dd87df43c3/examples/all.js#L172))\n\n## Further Reading\n\n- JSON-schema spec: https://tools.ietf.org/html/draft-zyp-json-schema-04\n- JSON-schema wiki: https://github.com/json-schema/json-schema/wiki\n- JSON-schema test suite: https://github.com/json-schema/JSON-Schema-Test-Suite/blob/node\n- TypeScript spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md\n\n## Projects That Use JSON-Schema-to-TypeScript\n\n- [RAML-to-TypeScript](https://github.com/ducin/raml-to-typescript)\n- See more: https://www.npmjs.com/browse/depended/json-schema-to-typescript\n","readmeFilename":"README.md"}