{"_id":"@6river/openapi-schema-to-json-schema","_rev":"1-c22d70d7c2fe7da060efe9c5d4862715","name":"@6river/openapi-schema-to-json-schema","dist-tags":{"latest":"0.1.0-allowArrayTypes.3"},"versions":{"0.1.0-allowArrayTypes.3":{"author":{"name":"OpenAPI Contrib"},"dependencies":{"fast-deep-equal":"^3.1.3"},"description":"Converts OpenAPI Schema Object to JSON Schema","devDependencies":{"eslint":"^6.8.0","eslint-config-standard":"^14.1.0","eslint-plugin-import":"^2.20.0","eslint-plugin-node":"^11.0.0","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.0.1","semantic-release":"^19.0.3","tap-spec":"^5.0.0","tape":"^4.13.2"},"license":"MIT","main":"index.js","name":"@6river/openapi-schema-to-json-schema","private":false,"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"repository":{"type":"git","url":"git+https://github.com/openapi-contrib/openapi-schema-to-json-schema.git"},"scripts":{"pretest":"npm run lint","test":"tape test/**/*.test.js | tap-spec","lint":"eslint .","lint.fix":"eslint . --fix"},"types":"index.d.ts","version":"0.1.0-allowArrayTypes.3","gitHead":"e3930d563e0bdff929d7d1943b7c3df45b89e203","bugs":{"url":"https://github.com/openapi-contrib/openapi-schema-to-json-schema/issues"},"homepage":"https://github.com/openapi-contrib/openapi-schema-to-json-schema#readme","_id":"@6river/openapi-schema-to-json-schema@0.1.0-allowArrayTypes.3","_nodeVersion":"14.17.6","_npmVersion":"6.14.15","dist":{"integrity":"sha512-5DIOFh03ip0oCPivWDOAUZC1YQKqkhweBw7m/3qN2LI5ZIseEu9Sybg+BcjJXi3I73Uo6YUA21zZnsE38t/2Cw==","shasum":"98accef5c46935bc8e42a322850964987005f6a4","tarball":"https://registry.npmjs.org/@6river/openapi-schema-to-json-schema/-/openapi-schema-to-json-schema-0.1.0-allowArrayTypes.3.tgz","fileCount":37,"unpackedSize":85518,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAdkaXXIs2R3KuQCVimZzDr/FQi3zBKGIvf5jctLHKnTAiEAzYemFKEzfi8y2XsMLQqf/3D741+GF1OGEXMFuOx838Y="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi8XAeACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmowFg//br9JX7uswV8fmJRmvAPZtJI6jr6T+SQxicytMwAvUYEsvv00\r\npmtC3WGiMwDumib7Zdzimdo7Tx5q2dBI+3UiXIPnrwjliSVlgZddZum1Rzlv\r\n2WsFmbYeUG2KLCN5Axcg0OSjskuZ2H7Lfa8Az35IWf5aN5kZbwOhAwKfR3Sb\r\n0DCAHUI7mecKyVxKXgYuSH/ONDurxqMUn/R6ct9TdI+mXYNRdSNpZlK4bFEl\r\nwtedvJqEmmVF1Lh2O/SjuVQEBaqPCDT38X7Gz+NrzvqKRbq3egw9NHWPBodX\r\nkfp7QFE8kf8J6Hw+oikSuV/4wlqXP1B3UIHCK1Vs5NwOhL5OWeViYSUtm4Un\r\nP3Jg/+VxMwC6tMgO2HZ2xVvN8mXgaSTyoCTxK/9iOZDA977Apndj6ox1lXbZ\r\nOA3HOOtVFGbf2ebHeibzaoiHnDn6nPAiiwV9mOwSQ9taNyYOymLG9S76KSD1\r\nZ5xbGpeej3QOFe5lBQ/7g3lKXHqSEGnOFnht1xEeweyMgg09QxqYFqq+3Ydv\r\ndi0kEqWTnMSoqd0cpPyUfpD4TJsaT1lE5Q9BaOWPe1KXBbt0SPf/0WlLygfs\r\nh/VD1me7T77Tln4LfpPX+Ld9ZtWcJsYkiXSFQ1FnfQybZR7KzoylGAB71TIt\r\n5w9mTGyARZxKhyhezW7HK6atKPLWku0yBOU=\r\n=tOLv\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"6river-machine","email":"swdev@6river.com"},"directories":{},"maintainers":[{"name":"6river-machine","email":"swdev@6river.com"},{"name":"kolach","email":"chikolad@gmail.com"},{"name":"jjhughes57","email":"jjhughes57@gmail.com"},{"name":"aaron.france","email":"afrance@6river.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/openapi-schema-to-json-schema_0.1.0-allowArrayTypes.3_1659990046298_0.4542536783167621"},"_hasShrinkwrap":false}},"time":{"created":"2022-08-08T20:20:46.237Z","0.1.0-allowArrayTypes.3":"2022-08-08T20:20:46.442Z","modified":"2023-01-05T16:58:30.550Z"},"maintainers":[{"email":"eng_sw_devops@6river.com","name":"6river-npm"},{"email":"swdev@6river.com","name":"6river-machine"},{"email":"chikolad@gmail.com","name":"kolach"},{"email":"jjhughes57@gmail.com","name":"jjhughes57"},{"email":"afrance@6river.com","name":"aaron.france"}],"description":"Converts OpenAPI Schema Object to JSON Schema","homepage":"https://github.com/openapi-contrib/openapi-schema-to-json-schema#readme","repository":{"type":"git","url":"git+https://github.com/openapi-contrib/openapi-schema-to-json-schema.git"},"author":{"name":"OpenAPI Contrib"},"bugs":{"url":"https://github.com/openapi-contrib/openapi-schema-to-json-schema/issues"},"license":"MIT","readme":"# OpenAPI Schema to JSON Schema\n\nA little NodeJS package to convert OpenAPI Schema Object or Parameter Object to JSON Schema.\n\nCurrently converts from [OpenAPI 3.0](https://spec.openapis.org/oas/v3.0.3.html) to [JSON Schema Draft 4](http://json-schema.org/specification-links.html#draft-4).\n\n[![Treeware](https://img.shields.io/badge/dynamic/json?color=brightgreen&label=Treeware&query=%24.total&url=https%3A%2F%2Fpublic.offset.earth%2Fusers%2Ftreeware%2Ftrees)](https://treeware.earth)\n\n## Why?\n\nOpenAPI is a specification for describing RESTful APIs. OpenAPI v3.0 allows us to describe the structures of request and response payloads in a detailed manner. This would, theoretically, mean that we should be able to automatically validate request and response payloads. However, as of writing there aren't many validators around.\n\nThe good news is that there are many validators for JSON Schema for different languages. The bad news is that OpenAPI v3.0 is [not entirely compatible with JSON Schema](https://stoplight.io/blog/openapi-json-schema/). The Schema Object of OpenAPI v3.0 is an extended subset of JSON Schema Specification Wright Draft 00 with some differences. This will be resolved in OpenAPI v3.1, but until then... this tool will fill that gap.\n\nThere is also a [CLI tool](https://github.com/mikunn/openapi2schema) for creating a JSON of schemas from the whole API specification.\n\nIf you need to do the conversion in reverse, checkout [json-schema-to-openapi-schema](https://github.com/openapi-contrib/json-schema-to-openapi-schema).\n\n## Features\n\n* converts OpenAPI v3.0 Schema Object to JSON Schema Draft 4\n* converts OpenAPI v3.0 Parameter Object to JSON Schema Draft 4\n* deletes `nullable` and adds `\"null\"` to `type` array if `nullable` is `true`\n* supports deep structures with nested `allOf`s etc.\n* removes [OpenAPI specific properties](https://spec.openapis.org/oas/v3.0.3.html#fixed-fields-20) such as `discriminator`, `deprecated` etc. unless specified otherwise\n* optionally supports `patternProperties` with `x-patternProperties` in the Schema Object\n\n**NOTE**: `$ref`s are not handled in any way, so please use a resolver such as [json-schema-ref-parser](https://github.com/APIDevTools/json-schema-ref-parser) or [swagger-cli bundle](https://www.npmjs.com/package/swagger-cli) prior to using this package.\n\n## Installation\n\n```\nnpm install --save @openapi-contrib/openapi-schema-to-json-schema\n```\n\n## Converting OpenAPI schema\n\nHere's a small example to get the idea:\n\n```js\n\nvar toJsonSchema = require('@openapi-contrib/openapi-schema-to-json-schema');\n\nvar schema = {\n  type: 'string',\n  format: 'date-time',\n  nullable: true\n};\n\nvar convertedSchema = toJsonSchema(schema);\n\nconsole.log(convertedSchema);\n```\n\nThe example prints out\n\n```js\n{\n  type: ['string', 'null'],\n  format: 'date-time',\n  '$schema': 'http://json-schema.org/draft-04/schema#'\n}\n```\n\nProvide the function the schema object with possible options.\n\n### Options\n\nThe function accepts `options` object as the second argument.\n\n#### `cloneSchema` (boolean)\n\nIf set to `false`, converts the provided schema in place. If `true`, clones the schema by converting it to JSON and back. The overhead of the cloning is usually negligible. Defaults to `true`.\n\n#### `dateToDateTime` (boolean)\n\nThis is `false` by default and leaves `date` format as is. If set to `true`, sets `format: 'date'` to `format: 'date-time'`.\n\nFor example\n\n```js\nvar schema = {\n  type: 'string',\n  format: 'date'\n};\n\nvar convertedSchema = toJsonSchema(schema, { dateToDateTime: true });\n\nconsole.log(convertedSchema);\n```\n\nprints\n\n```js\n{\n  type: 'string',\n  format: 'date-time',\n  '$schema': 'http://json-schema.org/draft-04/schema#'\n}\n```\n\n#### `keepNotSupported` (array)\n\nBy default, the following fields are removed from the result schema: `nullable`, `discriminator`, `readOnly`, `writeOnly`, `xml`, `externalDocs`, `example` and `deprecated` as they are not supported by JSON Schema Draft 4. Provide an array of the ones you want to keep (as strings) and they won't be removed.\n\n#### `removeReadOnly` (boolean)\n\nIf set to `true`, will remove properties set as `readOnly`. If the property is set as `required`, it will be removed from the `required` array as well. The property will be removed even if `readOnly` is set to be kept with `keepNotSupported`.\n\n#### `removeWriteOnly` (boolean)\n\nSimilar to `removeReadOnly`, but for `writeOnly` properties.\n\n#### `supportPatternProperties` (boolean)\n\nIf set to `true` and `x-patternProperties` property is present, change `x-patternProperties` to `patternProperties` and call `patternPropertiesHandler`. If `patternPropertiesHandler` is not defined, call the default handler. See `patternPropertiesHandler` for more information.\n\n#### `patternPropertiesHandler` (function)\n\nProvide a function to handle pattern properties and set `supportPatternProperties` to take effect. The function takes the schema where `x-patternProperties` is defined on the root level. At this point `x-patternProperties` is changed to `patternProperties`. It must return the modified schema.\n\nIf the handler is not provided, the default handler is used. If `additionalProperties` is set and is an object, the default handler sets it to false if the `additionalProperties` object has deep equality with a pattern object inside `patternProperties`. This is because we might want to define `additionalProperties` in OpenAPI spec file, but want to validate against a pattern. The pattern would turn out to be useless if `additionalProperties` of the same structure were allowed. Create you own handler to override this functionality.\n\nSee `test/pattern_properties.test.js` for examples how this works.\n\n## Converting OpenAPI parameters\n\nOpenAPI parameters can be converted:\n\n```js\nvar toJsonSchema = require('@openapi-contrib/openapi-schema-to-json-schema').fromParameter;\n\nvar param = {\n  name: 'parameter name',\n  in: 'query',\n  schema: {\n    type: 'string',\n    format: 'date'\n  }\n}\n\nvar convertedSchema = toJsonSchema(param);\n\nconsole.log(convertedSchema);\n```\n\nThe result is as follows:\n\n```js\n{\n  type: 'string',\n  format: 'date',\n  '$schema': 'http://json-schema.org/draft-04/schema#'\n}\n```\n\nWhen a parameter has several schemas (one per MIME type) a map is returned instead.\n\n```js\n{\n  name: 'parameter name',\n  in: 'query',\n  content: {\n    'application/javascript': {\n      schema: {\n        type: 'string'\n      }\n    },\n    'text/css': {\n      schema: {\n        type: 'string'\n      }\n    }\n  }\n}\n```\n\nwould be converted to:\n\n```js\n{\n  'application/javascript': {\n    type: 'string',\n    '$schema': 'http://json-schema.org/draft-04/schema#'\n  },\n  'text/css': {\n    type: 'string',\n    '$schema': 'http://json-schema.org/draft-04/schema#'\n  }\n}\n```\n\n## Treeware\n\nThis package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/{venfor}/{package}) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.\n\n## Thanks\n\n- [Stoplight][] for donating time and effort to this project, and many more.\n- [mikunn][] for originally creating this package.\n- [All Contributors][link-contributors]\n\n[Stoplight]: https://stoplight.io/\n[mikunn]: https://github.com/mikunn\n[link-contributors]: https://github.com/openapi-contrib/openapi-schema-to-json-schema/graphs/contributors\n\n## Copyright  \n\nCopyright 2021 the [OpenAPI Contrib organization](https://github.com/openapi-contrib). Code released under the [MIT License](https://github.com/openapi-contrib/openapi-schema-to-json-schema/blob/main/LICENSE).\n","readmeFilename":"README.md"}