@hey-api/json-schema-ref-parser 1.2.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +9 -84
  2. package/dist/index.d.mts +629 -0
  3. package/dist/index.d.mts.map +1 -0
  4. package/dist/index.mjs +1887 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/package.json +42 -78
  7. package/src/__tests__/bundle.test.ts +59 -0
  8. package/src/__tests__/index.test.ts +43 -0
  9. package/src/__tests__/pointer.test.ts +34 -0
  10. package/src/__tests__/utils.ts +3 -0
  11. package/{lib → src}/bundle.ts +143 -229
  12. package/{lib → src}/dereference.ts +20 -43
  13. package/{lib → src}/index.ts +103 -125
  14. package/{lib → src}/options.ts +13 -9
  15. package/{lib → src}/parse.ts +19 -15
  16. package/src/parsers/binary.ts +13 -0
  17. package/{lib → src}/parsers/json.ts +5 -6
  18. package/src/parsers/text.ts +21 -0
  19. package/{lib → src}/parsers/yaml.ts +9 -9
  20. package/{lib → src}/pointer.ts +42 -23
  21. package/{lib → src}/ref.ts +25 -21
  22. package/{lib → src}/refs.ts +23 -26
  23. package/{lib → src}/resolve-external.ts +91 -60
  24. package/{lib → src}/resolvers/file.ts +7 -10
  25. package/{lib → src}/resolvers/url.ts +12 -8
  26. package/{lib → src}/types/index.ts +9 -2
  27. package/src/util/convert-path-to-posix.ts +8 -0
  28. package/{lib → src}/util/errors.ts +38 -36
  29. package/{lib → src}/util/is-windows.ts +1 -1
  30. package/{lib → src}/util/plugins.ts +7 -8
  31. package/{lib → src}/util/url.ts +41 -42
  32. package/dist/lib/__tests__/bundle.test.d.ts +0 -1
  33. package/dist/lib/__tests__/bundle.test.js +0 -50
  34. package/dist/lib/__tests__/index.test.d.ts +0 -1
  35. package/dist/lib/__tests__/index.test.js +0 -43
  36. package/dist/lib/__tests__/pointer.test.d.ts +0 -1
  37. package/dist/lib/__tests__/pointer.test.js +0 -27
  38. package/dist/lib/bundle.d.ts +0 -26
  39. package/dist/lib/bundle.js +0 -600
  40. package/dist/lib/dereference.d.ts +0 -11
  41. package/dist/lib/dereference.js +0 -226
  42. package/dist/lib/index.d.ts +0 -92
  43. package/dist/lib/index.js +0 -525
  44. package/dist/lib/options.d.ts +0 -61
  45. package/dist/lib/options.js +0 -45
  46. package/dist/lib/parse.d.ts +0 -13
  47. package/dist/lib/parse.js +0 -87
  48. package/dist/lib/parsers/binary.d.ts +0 -2
  49. package/dist/lib/parsers/binary.js +0 -12
  50. package/dist/lib/parsers/json.d.ts +0 -2
  51. package/dist/lib/parsers/json.js +0 -38
  52. package/dist/lib/parsers/text.d.ts +0 -2
  53. package/dist/lib/parsers/text.js +0 -18
  54. package/dist/lib/parsers/yaml.d.ts +0 -2
  55. package/dist/lib/parsers/yaml.js +0 -28
  56. package/dist/lib/pointer.d.ts +0 -88
  57. package/dist/lib/pointer.js +0 -297
  58. package/dist/lib/ref.d.ts +0 -180
  59. package/dist/lib/ref.js +0 -226
  60. package/dist/lib/refs.d.ts +0 -127
  61. package/dist/lib/refs.js +0 -232
  62. package/dist/lib/resolve-external.d.ts +0 -13
  63. package/dist/lib/resolve-external.js +0 -151
  64. package/dist/lib/resolvers/file.d.ts +0 -6
  65. package/dist/lib/resolvers/file.js +0 -61
  66. package/dist/lib/resolvers/url.d.ts +0 -17
  67. package/dist/lib/resolvers/url.js +0 -62
  68. package/dist/lib/types/index.d.ts +0 -43
  69. package/dist/lib/types/index.js +0 -2
  70. package/dist/lib/util/convert-path-to-posix.d.ts +0 -1
  71. package/dist/lib/util/convert-path-to-posix.js +0 -14
  72. package/dist/lib/util/errors.d.ts +0 -56
  73. package/dist/lib/util/errors.js +0 -112
  74. package/dist/lib/util/is-windows.d.ts +0 -1
  75. package/dist/lib/util/is-windows.js +0 -6
  76. package/dist/lib/util/plugins.d.ts +0 -16
  77. package/dist/lib/util/plugins.js +0 -45
  78. package/dist/lib/util/url.d.ts +0 -79
  79. package/dist/lib/util/url.js +0 -285
  80. package/dist/vite.config.d.ts +0 -2
  81. package/dist/vite.config.js +0 -19
  82. package/lib/__tests__/bundle.test.ts +0 -52
  83. package/lib/__tests__/index.test.ts +0 -45
  84. package/lib/__tests__/pointer.test.ts +0 -26
  85. package/lib/__tests__/spec/circular-ref-with-description.json +0 -11
  86. package/lib/__tests__/spec/multiple-refs.json +0 -34
  87. package/lib/__tests__/spec/openapi-paths-ref.json +0 -46
  88. package/lib/__tests__/spec/path-parameter.json +0 -16
  89. package/lib/parsers/binary.ts +0 -13
  90. package/lib/parsers/text.ts +0 -21
  91. package/lib/util/convert-path-to-posix.ts +0 -11
  92. /package/{LICENSE → LICENSE.md} +0 -0
package/README.md CHANGED
@@ -1,15 +1,7 @@
1
- > This is a modified fork to serve Hey API needs
2
-
3
1
  # JSON Schema $Ref Parser
4
2
 
5
3
  #### Parse, Resolve, and Dereference JSON Schema $ref pointers
6
4
 
7
- <!-- [![Build Status](https://github.com/APIDevTools/json-schema-ref-parser/workflows/CI-CD/badge.svg?branch=master)](https://github.com/APIDevTools/json-schema-ref-parser/actions)
8
- [![Coverage Status](https://coveralls.io/repos/github/APIDevTools/json-schema-ref-parser/badge.svg?branch=master)](https://coveralls.io/github/APIDevTools/json-schema-ref-parser) -->
9
-
10
- <!-- [![npm](https://img.shields.io/npm/v/@apidevtools/json-schema-ref-parser.svg)](https://www.npmjs.com/package/@apidevtools/json-schema-ref-parser)
11
- [![License](https://img.shields.io/npm/l/@apidevtools/json-schema-ref-parser.svg)](LICENSE) -->
12
-
13
5
  ## Installation
14
6
 
15
7
  Install using [npm](https://docs.npmjs.com/about-npm/):
@@ -66,33 +58,19 @@ JavaScript objects.
66
58
  instance
67
59
  - Compatible with Node LTS and beyond, and all major web browsers on Windows, Mac, and Linux
68
60
 
69
- ## Example
70
-
71
- ```javascript
72
- import { $RefParser } from "@hey-api/json-schema-ref-parser";
73
-
74
- try {
75
- const parser = new $RefParser();
76
- await parser.dereference({ pathOrUrlOrSchema: mySchema });
77
- console.log(parser.schema.definitions.person.properties.firstName);
78
- } catch (err) {
79
- console.error(err);
80
- }
81
- ```
82
-
83
61
  ### New in this fork (@hey-api)
84
62
 
85
63
  - **Multiple inputs with `bundleMany`**: Merge and bundle several OpenAPI/JSON Schema inputs (files, URLs, or raw objects) into a single schema. Components are prefixed to avoid name collisions, paths are namespaced on conflict, and `$ref`s are rewritten accordingly.
86
64
 
87
65
  ```javascript
88
- import { $RefParser } from "@hey-api/json-schema-ref-parser";
66
+ import { $RefParser } from '@hey-api/json-schema-ref-parser';
89
67
 
90
68
  const parser = new $RefParser();
91
69
  const merged = await parser.bundleMany({
92
70
  pathOrUrlOrSchemas: [
93
- "./specs/a.yaml",
94
- "https://example.com/b.yaml",
95
- { openapi: "3.1.0", info: { title: "Inline" }, paths: {} },
71
+ './specs/a.yaml',
72
+ 'https://example.com/b.yaml',
73
+ { openapi: '3.1.0', info: { title: 'Inline' }, paths: {} },
96
74
  ],
97
75
  });
98
76
 
@@ -103,11 +81,11 @@ const merged = await parser.bundleMany({
103
81
 
104
82
  ```javascript
105
83
  const parser = new $RefParser();
106
- parser.options.dereference.excludedPathMatcher = (p) => p.includes("/example/");
84
+ parser.options.dereference.excludedPathMatcher = (p) => p.includes('/example/');
107
85
  parser.options.dereference.onDereference = (p, v) => {
108
86
  // inspect p / v as needed
109
87
  };
110
- await parser.dereference({ pathOrUrlOrSchema: "./openapi.yaml" });
88
+ await parser.dereference({ pathOrUrlOrSchema: './openapi.yaml' });
111
89
  ```
112
90
 
113
91
  - **Smart input resolution**: You can pass a file path, URL, or raw schema object. If a raw schema includes `$id`, it is used as the base URL for resolving relative `$ref`s.
@@ -115,64 +93,11 @@ await parser.dereference({ pathOrUrlOrSchema: "./openapi.yaml" });
115
93
  ```javascript
116
94
  await new $RefParser().bundle({
117
95
  pathOrUrlOrSchema: {
118
- $id: "https://api.example.com/openapi.json",
119
- openapi: "3.1.0",
96
+ $id: 'https://api.example.com/openapi.json',
97
+ openapi: '3.1.0',
120
98
  paths: {
121
- "/ping": { get: { responses: { 200: { description: "ok" } } } },
99
+ '/ping': { get: { responses: { 200: { description: 'ok' } } } },
122
100
  },
123
101
  },
124
102
  });
125
103
  ```
126
-
127
- ## Polyfills
128
-
129
- If you are using Node.js < 18, you'll need a polyfill for `fetch`,
130
- like [node-fetch](https://github.com/node-fetch/node-fetch):
131
-
132
- ```javascript
133
- import fetch from "node-fetch";
134
-
135
- globalThis.fetch = fetch;
136
- ```
137
-
138
- ## Browser support
139
-
140
- JSON Schema $Ref Parser supports recent versions of every major web browser. Older browsers may
141
- require [Babel](https://babeljs.io/) and/or [polyfills](https://babeljs.io/docs/en/next/babel-polyfill).
142
-
143
- To use JSON Schema $Ref Parser in a browser, you'll need to use a bundling tool such
144
- as [Webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org/), [Parcel](https://parceljs.org/),
145
- or [Browserify](http://browserify.org/). Some bundlers may require a bit of configuration, such as
146
- setting `browser: true` in [rollup-plugin-resolve](https://github.com/rollup/rollup-plugin-node-resolve).
147
-
148
- #### Webpack 5
149
-
150
- Webpack 5 has dropped the default export of node core modules in favour of polyfills, you'll need to set them up
151
- yourself ( after npm-installing them )
152
- Edit your `webpack.config.js` :
153
-
154
- ```js
155
- config.resolve.fallback = {
156
- path: require.resolve("path-browserify"),
157
- fs: require.resolve("browserify-fs"),
158
- };
159
-
160
- config.plugins.push(
161
- new webpack.ProvidePlugin({
162
- Buffer: ["buffer", "Buffer"],
163
- }),
164
- );
165
- ```
166
-
167
- #### Building/Testing
168
-
169
- To build/test the project locally on your computer:
170
-
171
- 1. **Clone this repo**<br>
172
- `git clone https://github.com/APIDevTools/json-schema-ref-parser.git`
173
-
174
- 2. **Install dependencies**<br>
175
- `yarn install`
176
-
177
- 3. **Run the tests**<br>
178
- `yarn test`