{"_id":"@afmhenry/json-ref-resolver","_rev":"2-3c2c9716466e517f90a4cbd64948aa4f","name":"@afmhenry/json-ref-resolver","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@afmhenry/json-ref-resolver","version":"1.0.0","description":"Recursively resolve JSON pointers and remote authorities. With larger stack size check.","keywords":["json-parser","json","jsonschema","json-schema","json-pointer","$ref","resolver","openapi","swagger","dereference","resolve"],"main":"src/index.ts","sideEffects":false,"homepage":"https://github.com/stoplightio/json-ref-resolver","bugs":{"url":"https://github.com/stoplightio/json-ref-resolver/issues"},"author":{"name":"Afmhenry"},"repository":{"type":"git","url":"git+https://github.com/afmhenry/json-ref-resolver.git"},"license":"Apache-2.0","engines":{"node":">=8.3.0"},"scripts":{"build":"sl-scripts build","commit":"git-cz","lint":"tslint -p .","lint.fix":"yarn lint --fix","release":"sl-scripts release","release.dryRun":"sl-scripts release --dry-run --debug","test":"jest","test.prod":"yarn lint && yarn test --coverage --no-cache","test.update":"yarn test --updateSnapshot","test.watch":"yarn test --watch"},"dependencies":{"@stoplight/json":"^3.21.0","@stoplight/path":"^1.3.2","@stoplight/types":"^12.3.0 || ^13.0.0","@types/urijs":"^1.19.19","dependency-graph":"~0.11.0","fast-memoize":"^2.5.2","immer":"^9.0.6","lodash":"^4.17.21","tslib":"^2.6.0","urijs":"^1.19.11"},"devDependencies":{"@stoplight/scripts":"^5","@types/jest":"^24.9.0","@types/lodash":"^4.14.178","benchmark":"^2.1","jest":"^29.6.1","ts-jest":"^29.1.1","tslint":"^5.20","tslint-config-stoplight":"~1.4","typescript":"~4.9.5"},"lint-staged":{"*.{ts,tsx}$":["tslint -p tsconfig.json --fix","git add"]},"release":{"extends":"@stoplight/scripts/release"},"prettier":{"printWidth":120,"trailingComma":"es5","singleQuote":true},"_id":"@afmhenry/json-ref-resolver@1.0.0","gitHead":"dd6e8e542ebacecf18f664a545180b4e24590ac6","_nodeVersion":"18.17.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-/TYLug519BmiJNoffsfxSkJu5MBJUC1qh6FnlMMJDaECUNu40yyqx4DF4ldSA/mbF6WRxsRWXZQ9XUt8/qVCmA==","shasum":"237481a2a040960a39893aa963312a79ddaba0ad","tarball":"https://registry.npmjs.org/@afmhenry/json-ref-resolver/-/json-ref-resolver-1.0.0.tgz","fileCount":117,"unpackedSize":428689,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHwk+L991PAlGzVmoa2t1uJsMTnB/iuJnYlAslGl9VoDAiARnvymv/qsC2+yAyIuhRMTRJmeiDU753EVO6pnT0XpXQ=="}]},"_npmUser":{"name":"afmhenry","email":"alex@henrycalifornia.com"},"directories":{},"maintainers":[{"name":"afmhenry","email":"alex@henrycalifornia.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/json-ref-resolver_1.0.0_1703237195821_0.8945333693296871"},"_hasShrinkwrap":false},"1.0.1":{"name":"@afmhenry/json-ref-resolver","version":"1.0.1","description":"Recursively resolve JSON pointers and remote authorities. With larger stack size check.","keywords":["json-parser","json","jsonschema","json-schema","json-pointer","$ref","resolver","openapi","swagger","dereference","resolve"],"main":"dist/index.ts","sideEffects":false,"homepage":"https://github.com/stoplightio/json-ref-resolver","bugs":{"url":"https://github.com/stoplightio/json-ref-resolver/issues"},"author":{"name":"Afmhenry"},"repository":{"type":"git","url":"git+https://github.com/afmhenry/json-ref-resolver.git"},"license":"Apache-2.0","engines":{"node":">=8.3.0"},"scripts":{"build":"sl-scripts build","commit":"git-cz","lint":"tslint -p .","lint.fix":"yarn lint --fix","release":"sl-scripts release","release.dryRun":"sl-scripts release --dry-run --debug","test":"jest","test.prod":"yarn lint && yarn test --coverage --no-cache","test.update":"yarn test --updateSnapshot","test.watch":"yarn test --watch"},"dependencies":{"@stoplight/json":"^3.21.0","@stoplight/path":"^1.3.2","@stoplight/types":"^12.3.0 || ^13.0.0","@types/urijs":"^1.19.19","dependency-graph":"~0.11.0","fast-memoize":"^2.5.2","immer":"^9.0.6","lodash":"^4.17.21","tslib":"^2.6.0","urijs":"^1.19.11"},"devDependencies":{"@stoplight/scripts":"^5","@types/jest":"^24.9.0","@types/lodash":"^4.14.178","benchmark":"^2.1","jest":"^29.6.1","ts-jest":"^29.1.1","tslint":"^5.20","tslint-config-stoplight":"~1.4","typescript":"~4.9.5"},"lint-staged":{"*.{ts,tsx}$":["tslint -p tsconfig.json --fix","git add"]},"release":{"extends":"@stoplight/scripts/release"},"prettier":{"printWidth":120,"trailingComma":"es5","singleQuote":true},"_id":"@afmhenry/json-ref-resolver@1.0.1","gitHead":"dd6e8e542ebacecf18f664a545180b4e24590ac6","types":"./dist/index.d.ts","_nodeVersion":"18.17.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-aFGZatM4bDxAznnbTE9CW16E6Xv+0VQgov0Bse4fh6JimmOn8FoKctMs7+z9zOUeJUHd5rszZg7zNuRwzLf4JQ==","shasum":"2ecf088f081ba3ddf93de64e138c02265758bd0e","tarball":"https://registry.npmjs.org/@afmhenry/json-ref-resolver/-/json-ref-resolver-1.0.1.tgz","fileCount":117,"unpackedSize":428690,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDU6VxygPPcuyIIGWbJDxzUAP9Bv9Y4IFhsMCVFq/C64wIgKQCy7og9fRAhvElgIqjsdhQHLot5bhs7uWlTyugzbd8="}]},"_npmUser":{"name":"afmhenry","email":"alex@henrycalifornia.com"},"directories":{},"maintainers":[{"name":"afmhenry","email":"alex@henrycalifornia.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/json-ref-resolver_1.0.1_1703237430157_0.015609662270709812"},"_hasShrinkwrap":false},"1.0.2":{"name":"@afmhenry/json-ref-resolver","version":"1.0.2","description":"Recursively resolve JSON pointers and remote authorities. With larger stack size check.","keywords":["json-parser","json","jsonschema","json-schema","json-pointer","$ref","resolver","openapi","swagger","dereference","resolve"],"main":"dist/index.js","sideEffects":false,"homepage":"https://github.com/stoplightio/json-ref-resolver","bugs":{"url":"https://github.com/stoplightio/json-ref-resolver/issues"},"author":{"name":"Afmhenry"},"repository":{"type":"git","url":"git+https://github.com/afmhenry/json-ref-resolver.git"},"license":"Apache-2.0","engines":{"node":">=8.3.0"},"scripts":{"build":"sl-scripts build","commit":"git-cz","lint":"tslint -p .","lint.fix":"yarn lint --fix","release":"sl-scripts release","release.dryRun":"sl-scripts release --dry-run --debug","test":"jest","test.prod":"yarn lint && yarn test --coverage --no-cache","test.update":"yarn test --updateSnapshot","test.watch":"yarn test --watch"},"dependencies":{"@stoplight/json":"^3.21.0","@stoplight/path":"^1.3.2","@stoplight/types":"^12.3.0 || ^13.0.0","@types/urijs":"^1.19.19","dependency-graph":"~0.11.0","fast-memoize":"^2.5.2","immer":"^9.0.6","lodash":"^4.17.21","tslib":"^2.6.0","urijs":"^1.19.11"},"devDependencies":{"@stoplight/scripts":"^5","@types/jest":"^24.9.0","@types/lodash":"^4.14.178","benchmark":"^2.1","jest":"^29.6.1","ts-jest":"^29.1.1","tslint":"^5.20","tslint-config-stoplight":"~1.4","typescript":"~4.9.5"},"lint-staged":{"*.{ts,tsx}$":["tslint -p tsconfig.json --fix","git add"]},"release":{"extends":"@stoplight/scripts/release"},"prettier":{"printWidth":120,"trailingComma":"es5","singleQuote":true},"_id":"@afmhenry/json-ref-resolver@1.0.2","gitHead":"dd6e8e542ebacecf18f664a545180b4e24590ac6","types":"./dist/index.d.ts","_nodeVersion":"18.17.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-u0VNJaVJriwfG3xPRvNrPMRAi48XDS924MxiuVXih1w5fjmUzhiu+TVgfpYsFkvKEal7OdpRD8VXaveXgcA9ng==","shasum":"f216eb9de7f9db6165e4e145b469f72c76bf4706","tarball":"https://registry.npmjs.org/@afmhenry/json-ref-resolver/-/json-ref-resolver-1.0.2.tgz","fileCount":117,"unpackedSize":428690,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAplJ/6JrgslZ8IPAs+IROZ9tGelk6LzXPlnY25wHdTRAiEAuzgnQoveQGJTsIWPBXDjFydW5RTDBWfNvYmWPS+kz1g="}]},"_npmUser":{"name":"afmhenry","email":"alex@henrycalifornia.com"},"directories":{},"maintainers":[{"name":"afmhenry","email":"alex@henrycalifornia.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/json-ref-resolver_1.0.2_1703237492451_0.5044288442304599"},"_hasShrinkwrap":false}},"time":{"created":"2023-12-22T09:26:35.736Z","1.0.0":"2023-12-22T09:26:36.178Z","modified":"2023-12-22T09:31:32.986Z","1.0.1":"2023-12-22T09:30:30.363Z","1.0.2":"2023-12-22T09:31:32.811Z"},"maintainers":[{"name":"afmhenry","email":"alex@henrycalifornia.com"}],"description":"Recursively resolve JSON pointers and remote authorities. With larger stack size check.","homepage":"https://github.com/stoplightio/json-ref-resolver","keywords":["json-parser","json","jsonschema","json-schema","json-pointer","$ref","resolver","openapi","swagger","dereference","resolve"],"repository":{"type":"git","url":"git+https://github.com/afmhenry/json-ref-resolver.git"},"author":{"name":"Afmhenry"},"bugs":{"url":"https://github.com/stoplightio/json-ref-resolver/issues"},"license":"Apache-2.0","readme":"# JSON Ref Resolver \n\n[![Buy us a tree](https://img.shields.io/badge/Buy%20us%20a%20tree-%F0%9F%8C%B3-lightgreen)](https://offset.earth/stoplightinc)\n[![CircleCI](https://circleci.com/gh/stoplightio/json-ref-resolver.svg?style=svg)](https://circleci.com/gh/stoplightio/json-ref-resolver)\n\nFollow `$ref` values in JSON Schema, OpenAPI (formerly known as Swagger), and any other objects with `$ref` values inside of them.\n\n- View the changelog: [Releases](https://github.com/stoplightio/json-ref-resolver/releases)\n\n## Features\n\n- **Performant**: Hot paths are memoized, remote URIs are resolved concurrently, and the minimum surface area is crawled and resolved.\n- **Caching**: Results from remote URIs are cached.\n- **Immutable**: The original object is not changed, and structural sharing is used to only change relevant bits. [example test](src/__tests__/resolver.spec.ts#L182)\n- **Reference equality:** $refs to the same location will resolve to the same object in memory. [example test](src/__tests__/resolver.spec.ts#L329)\n- **Flexible:** Bring your own readers for `http://`, `file://`, `mongo://`, `custom://`... etc, or use [one of ours][json-ref-readers].\n- **Cross Platform:** Supports POSIX and Windows style file paths.\n- **Reliable:** Well tested to handle all sorts of circular reference edge cases.\n\n## Installation\n\nSupported in modern browsers and node.\n\n```bash\nyarn add @stoplight/json-ref-resolver\n```\n\n## Usage\n\nAll relevant types and options can be found in [src/types.ts](./src/types.ts).\n\n```ts\n// Import the Resolver class.\nimport { Resolver } from \"@stoplight/json-ref-resolver\";\n\n/**\n * Create a Resolver instance. Resolve can be called on this instance multiple times to take advantage of caching.\n *\n * @param globalOpts {IResolverOpts} [{}]\n *\n * These options are used on every resolve call for this resolver instance.\n *\n * See `IResolverOpts` interface defined in [src/types.ts](src/types.ts) for available options.\n *\n * @return IResolver\n */\nconst resolver = new Resolver(globalOpts);\n\n/**\n * Resolve the passed in object, replacing all references.\n\n * @param resolveOpts {any} - The object to resolve.\n\n * @param resolveOpts {IResolveOpts} [{}]\n *\n * These options override any globalOpts specified on the resolver instance, and only apply during this resolve call.\n *\n * See `IResolveOpts` interface defined in [src/types.ts](src/types.ts) for available options.\n *\n * @return IResolveResult - see [src/types.ts](src/types.ts) for interface definition.\n */\nconst resolved = await resolver.resolve(sourceObj, resolveOpts);\n```\n\n### Example: Basic Inline Dereferencing\n\nBy default, only inline references will be dereferenced.\n\n```ts\nimport { Resolver } from \"@stoplight/json-ref-resolver\";\n\nconst resolver = new Resolver();\nconst resolved = await resolver.resolve({\n  user: {\n    $ref: \"#/models/user\"\n  },\n  models: {\n    user: {\n      name: \"john\"\n    }\n  }\n});\n\n// ==> result is the original object, with local refs resolved and replaced\nexpect(resolved.result).toEqual({\n  user: {\n    name: \"john\"\n  },\n  models: {\n    user: {\n      name: \"john\"\n    }\n  }\n});\n```\n\n### Example: Dereference a Subset of the Source\n\nThis will dereference the minimal number of references needed for the given target, and return the target.\n\nIn the example below, the address reference (`https://slow-website.com/definitions#/address`) will NOT be dereferenced, since\nit is not needed to resolve the `#/user` jsonPointer target we have specified. However, `#/models/user/card` IS dereferenced since\nit is needed in order to full dereference the `#/user` property.\n\n```ts\nimport { Resolver } from \"@stoplight/json-ref-resolver\";\n\nconst resolver = new Resolver();\nconst resolved = await resolver.resolve(\n  {\n    user: {\n      $ref: \"#/models/user\"\n    },\n    address: {\n      $ref: \"https://slow-website.com/definitions#/address\"\n    },\n    models: {\n      user: {\n        name: \"john\",\n        card: {\n          $ref: \"#/models/card\"\n        }\n      },\n      card: {\n        type: \"visa\"\n      }\n    }\n  },\n  {\n    jsonPointer: \"#/user\"\n  }\n);\n\n// ==> result is the target object, with refs resolved and replaced\nexpect(resolved.result).toEqual({\n  name: \"john\",\n  card: {\n    type: \"visa\"\n  }\n});\n```\n\n### Example: Dereferencing Remote References with Resolvers\n\nBy default only inline references (those that point to values inside of the original object) are dereferenced.\n\nIn order to dereference remote URIs (file, http, etc) you must provide resolvers for each URI scheme.\n\nResolvers are keyed by scheme, receive the URI to fetch, and must return the fetched data.\n\n```ts\nimport { Resolver } from \"@stoplight/json-ref-resolver\";\n\n// some example http library\nimport * as axios from \"axios\";\n\n// if we're in node, we create a file resolver with fs\nimport * as fs from \"fs\";\n\n// create our resolver instance\nconst resolver = new Resolver({\n  // resolvers can do anything, so long as they define an async read function that resolves to a value\n  resolvers: {\n    // this resolver will be invoked for refs with the https protocol\n    https: {\n      async resolve(ref: uri.URI) {\n        return axios({\n          method: \"get\",\n          url: String(ref)\n        });\n      }\n    },\n\n    // this resolver will be invoked for refs with the file protocol\n    file: {\n      async resolve(ref: uri.URI) {\n        return fs.read(String(ref));\n      }\n    }\n  }\n});\n\nconst resolved = await resolver.resolve({\n  definitions: {\n    someOASFile: {\n      $ref: \"./main.oas2.yml#/definitions/user\"\n    },\n    someMarkdownFile: {\n      $ref: \"https://foo.com/intro.md\"\n    }\n  }\n});\n\n// ==> result is the original object, with refs resolved and replaced\nexpect(resolved.result).toEqual({\n  definitions: {\n    someOASFile: {\n      // ... the data located in the relative file `./main.oas2.yml` and inner json path `#/definitions/user`\n    },\n    someMarkdownFile: {\n      // ... the data located at the url `https://foo.com/intro.md`\n    }\n  }\n});\n```\n\n### Example: Dereferencing Relative Remote References with the baseUri Option\n\nIf there are relative remote references (for example, a relative file path `../model.json`), then the location of the source\ndata must be specified via the `baseUri` option. Relative references will be dereferenced against this baseUri.\n\n```ts\nimport { Resolver } from \"@stoplight/json-ref-resolver\";\nimport * as fs from \"fs\";\nimport * as URI from \"urijs\";\n\nconst resolver = new Resolver({\n  readers: {\n    file: {\n      async read(ref: uri.URI) {\n        return fs.read(String(ref));\n      }\n    }\n  }\n});\n\nconst sourcePath = \"/specs/api.json\";\nconst sourceData = fs.readSync(sourcePath);\n// sourceData === {\n//   user: {\n//     $ref: \"../models/user.json\"\n//   }\n// }\n\nconst resolved = await resolver.resolve(sourceData, {\n  // Indicate where the `sourceData` being resolved lives, so that relative remote references can be fetched and resolved.\n  baseUri: new URI(sourcePath)\n});\n\nexpect(resolved.result).toEqual({\n  user: {\n    // ... the user object defined in `../models/user.json`\n  }\n});\n```\n\nIn the above example, the user `$ref` will resolve to `/models/user.json`, because `../models/user.json` is resolved against the `baseUri` of the current document (which was indicated at `/specs/api.json`). Relative references will not work if the source document has no baseUri set.\n\nThis is a simplistic example of a reader. You can create your own, but we have built some [readers][json-ref-readers] which you might find useful.\n\n## Contributing\n\nIf you are interested in contributing to Spectral itself, check out our [contributing docs](CONTRIBUTING.md) to get started.\n\n[json-ref-readers]: https://github.com/stoplightio/json-ref-readers/\n","readmeFilename":"README.md"}