@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.
- package/README.md +9 -84
- package/dist/index.d.mts +629 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1887 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +42 -78
- package/src/__tests__/bundle.test.ts +59 -0
- package/src/__tests__/index.test.ts +43 -0
- package/src/__tests__/pointer.test.ts +34 -0
- package/src/__tests__/utils.ts +3 -0
- package/{lib → src}/bundle.ts +143 -229
- package/{lib → src}/dereference.ts +20 -43
- package/{lib → src}/index.ts +103 -125
- package/{lib → src}/options.ts +13 -9
- package/{lib → src}/parse.ts +19 -15
- package/src/parsers/binary.ts +13 -0
- package/{lib → src}/parsers/json.ts +5 -6
- package/src/parsers/text.ts +21 -0
- package/{lib → src}/parsers/yaml.ts +9 -9
- package/{lib → src}/pointer.ts +42 -23
- package/{lib → src}/ref.ts +25 -21
- package/{lib → src}/refs.ts +23 -26
- package/{lib → src}/resolve-external.ts +91 -60
- package/{lib → src}/resolvers/file.ts +7 -10
- package/{lib → src}/resolvers/url.ts +12 -8
- package/{lib → src}/types/index.ts +9 -2
- package/src/util/convert-path-to-posix.ts +8 -0
- package/{lib → src}/util/errors.ts +38 -36
- package/{lib → src}/util/is-windows.ts +1 -1
- package/{lib → src}/util/plugins.ts +7 -8
- package/{lib → src}/util/url.ts +41 -42
- package/dist/lib/__tests__/bundle.test.d.ts +0 -1
- package/dist/lib/__tests__/bundle.test.js +0 -50
- package/dist/lib/__tests__/index.test.d.ts +0 -1
- package/dist/lib/__tests__/index.test.js +0 -43
- package/dist/lib/__tests__/pointer.test.d.ts +0 -1
- package/dist/lib/__tests__/pointer.test.js +0 -27
- package/dist/lib/bundle.d.ts +0 -26
- package/dist/lib/bundle.js +0 -600
- package/dist/lib/dereference.d.ts +0 -11
- package/dist/lib/dereference.js +0 -226
- package/dist/lib/index.d.ts +0 -92
- package/dist/lib/index.js +0 -525
- package/dist/lib/options.d.ts +0 -61
- package/dist/lib/options.js +0 -45
- package/dist/lib/parse.d.ts +0 -13
- package/dist/lib/parse.js +0 -87
- package/dist/lib/parsers/binary.d.ts +0 -2
- package/dist/lib/parsers/binary.js +0 -12
- package/dist/lib/parsers/json.d.ts +0 -2
- package/dist/lib/parsers/json.js +0 -38
- package/dist/lib/parsers/text.d.ts +0 -2
- package/dist/lib/parsers/text.js +0 -18
- package/dist/lib/parsers/yaml.d.ts +0 -2
- package/dist/lib/parsers/yaml.js +0 -28
- package/dist/lib/pointer.d.ts +0 -88
- package/dist/lib/pointer.js +0 -297
- package/dist/lib/ref.d.ts +0 -180
- package/dist/lib/ref.js +0 -226
- package/dist/lib/refs.d.ts +0 -127
- package/dist/lib/refs.js +0 -232
- package/dist/lib/resolve-external.d.ts +0 -13
- package/dist/lib/resolve-external.js +0 -151
- package/dist/lib/resolvers/file.d.ts +0 -6
- package/dist/lib/resolvers/file.js +0 -61
- package/dist/lib/resolvers/url.d.ts +0 -17
- package/dist/lib/resolvers/url.js +0 -62
- package/dist/lib/types/index.d.ts +0 -43
- package/dist/lib/types/index.js +0 -2
- package/dist/lib/util/convert-path-to-posix.d.ts +0 -1
- package/dist/lib/util/convert-path-to-posix.js +0 -14
- package/dist/lib/util/errors.d.ts +0 -56
- package/dist/lib/util/errors.js +0 -112
- package/dist/lib/util/is-windows.d.ts +0 -1
- package/dist/lib/util/is-windows.js +0 -6
- package/dist/lib/util/plugins.d.ts +0 -16
- package/dist/lib/util/plugins.js +0 -45
- package/dist/lib/util/url.d.ts +0 -79
- package/dist/lib/util/url.js +0 -285
- package/dist/vite.config.d.ts +0 -2
- package/dist/vite.config.js +0 -19
- package/lib/__tests__/bundle.test.ts +0 -52
- package/lib/__tests__/index.test.ts +0 -45
- package/lib/__tests__/pointer.test.ts +0 -26
- package/lib/__tests__/spec/circular-ref-with-description.json +0 -11
- package/lib/__tests__/spec/multiple-refs.json +0 -34
- package/lib/__tests__/spec/openapi-paths-ref.json +0 -46
- package/lib/__tests__/spec/path-parameter.json +0 -16
- package/lib/parsers/binary.ts +0 -13
- package/lib/parsers/text.ts +0 -21
- package/lib/util/convert-path-to-posix.ts +0 -11
- /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
|
-
<!-- [](https://github.com/APIDevTools/json-schema-ref-parser/actions)
|
|
8
|
-
[](https://coveralls.io/github/APIDevTools/json-schema-ref-parser) -->
|
|
9
|
-
|
|
10
|
-
<!-- [](https://www.npmjs.com/package/@apidevtools/json-schema-ref-parser)
|
|
11
|
-
[](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
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
{ openapi:
|
|
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(
|
|
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:
|
|
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:
|
|
119
|
-
openapi:
|
|
96
|
+
$id: 'https://api.example.com/openapi.json',
|
|
97
|
+
openapi: '3.1.0',
|
|
120
98
|
paths: {
|
|
121
|
-
|
|
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`
|