@scalar/openapi-parser 0.22.3 → 0.23.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/CHANGELOG.md +27 -0
- package/README.md +49 -17
- package/dist/configuration/index.d.ts +1399 -0
- package/dist/configuration/index.d.ts.map +1 -1
- package/dist/configuration/index.js +3 -1
- package/dist/configuration/index.js.map +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +2 -2
- package/dist/lib/Validator/Validator.d.ts +6 -16
- package/dist/lib/Validator/Validator.d.ts.map +1 -1
- package/dist/lib/Validator/Validator.js +8 -9
- package/dist/lib/Validator/Validator.js.map +2 -2
- package/dist/plugins/read-files/read-files.js +1 -1
- package/dist/plugins/read-files/read-files.js.map +2 -2
- package/dist/schemas/v3.2/schema.d.ts +1401 -0
- package/dist/schemas/v3.2/schema.d.ts.map +1 -0
- package/dist/schemas/v3.2/schema.js +1505 -0
- package/dist/schemas/v3.2/schema.js.map +7 -0
- package/dist/utils/dereference.d.ts +7 -2
- package/dist/utils/dereference.d.ts.map +1 -1
- package/dist/utils/dereference.js +1 -1
- package/dist/utils/dereference.js.map +2 -2
- package/dist/utils/normalize.js +1 -1
- package/dist/utils/normalize.js.map +2 -2
- package/dist/utils/openapi/utils/workThroughQueue.d.ts.map +1 -1
- package/dist/utils/openapi/utils/workThroughQueue.js +2 -3
- package/dist/utils/openapi/utils/workThroughQueue.js.map +2 -2
- package/dist/utils/resolve-references.d.ts.map +1 -1
- package/dist/utils/resolve-references.js.map +2 -2
- package/dist/utils/validate.d.ts.map +1 -1
- package/dist/utils/validate.js +13 -9
- package/dist/utils/validate.js.map +2 -2
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @scalar/openapi-parser
|
|
2
2
|
|
|
3
|
+
## 0.23.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#7121](https://github.com/scalar/scalar/pull/7121) [`9661e81`](https://github.com/scalar/scalar/commit/9661e81907d1a9b74ba30f270f2d6c8e49834cd5) Thanks [@marcalexiei](https://github.com/marcalexiei)! - feat(oas-utils): make `dereference` synchronous
|
|
8
|
+
|
|
9
|
+
- [#7092](https://github.com/scalar/scalar/pull/7092) [`134ff5f`](https://github.com/scalar/scalar/commit/134ff5f32aa6842696bf146c7e0817b1662905eb) Thanks [@baywet](https://github.com/baywet)! - feat - parser - adds support for OpenAPI 3.2.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#7116](https://github.com/scalar/scalar/pull/7116) [`2239843`](https://github.com/scalar/scalar/commit/2239843150ed16d1ca35b0b1f8e90cd3e35be7ce) Thanks [@baywet](https://github.com/baywet)! - docs adds a mention that OpenAPI 3.2.0 is now supported
|
|
14
|
+
|
|
15
|
+
- [#7092](https://github.com/scalar/scalar/pull/7092) [`134ff5f`](https://github.com/scalar/scalar/commit/134ff5f32aa6842696bf146c7e0817b1662905eb) Thanks [@baywet](https://github.com/baywet)! - feat: update OpenAPI 3.0 and 3.1 JSON schemas for validation
|
|
16
|
+
|
|
17
|
+
- [#7182](https://github.com/scalar/scalar/pull/7182) [`c84b7c5`](https://github.com/scalar/scalar/commit/c84b7c5e81be83dacbdfcbf9cb1e558dfdc3faa1) Thanks [@baywet](https://github.com/baywet)! - [fix] adds missing dereference options export in parser
|
|
18
|
+
|
|
19
|
+
- [#7094](https://github.com/scalar/scalar/pull/7094) [`eba18d0`](https://github.com/scalar/scalar/commit/eba18d06267a163a8f91396a66f817100ee59461) Thanks [@geoffgscott](https://github.com/geoffgscott)! - Migrate to workspace store as primary source of truth.
|
|
20
|
+
|
|
21
|
+
- [#7196](https://github.com/scalar/scalar/pull/7196) [`a821986`](https://github.com/scalar/scalar/commit/a821986332141e69d26885b2d2b32eb0c49f416c) Thanks [@marcalexiei](https://github.com/marcalexiei)! - fix(openapi-parser): remove internal unneeded async logic without changing the public API
|
|
22
|
+
|
|
23
|
+
- [#7149](https://github.com/scalar/scalar/pull/7149) [`e23229d`](https://github.com/scalar/scalar/commit/e23229dfbd9613b5047b28b57901f2fc5a6e33e6) Thanks [@baywet](https://github.com/baywet)! - [docs] updates readme to bundle method and adds migration from load guidance
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`11a6e64`](https://github.com/scalar/scalar/commit/11a6e6405d4f30f001a16d6afda4d2b759c0ed09), [`2239843`](https://github.com/scalar/scalar/commit/2239843150ed16d1ca35b0b1f8e90cd3e35be7ce), [`134ff5f`](https://github.com/scalar/scalar/commit/134ff5f32aa6842696bf146c7e0817b1662905eb), [`6ca835e`](https://github.com/scalar/scalar/commit/6ca835e5afd3e8c603e073e7c83f2cdd961a0f69), [`43bc5e8`](https://github.com/scalar/scalar/commit/43bc5e8b90dc0edf7176d0ddfc64bf3212494458)]:
|
|
26
|
+
- @scalar/openapi-upgrader@0.1.4
|
|
27
|
+
- @scalar/openapi-types@0.5.1
|
|
28
|
+
- @scalar/json-magic@0.7.0
|
|
29
|
+
|
|
3
30
|
## 0.22.3
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/@scalar/openapi-parser)
|
|
6
6
|
[](https://discord.gg/scalar)
|
|
7
7
|
|
|
8
|
-
Modern OpenAPI parser written in TypeScript with support for OpenAPI 3.1,
|
|
8
|
+
Modern OpenAPI parser written in TypeScript with support for OpenAPI 3.2, 3.1, 3.0 and Swagger 2.0.
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
@@ -180,12 +180,13 @@ const file: OpenAPI.Document = {
|
|
|
180
180
|
You can reference other files, too. To do that, the parser needs to know what files are available.
|
|
181
181
|
|
|
182
182
|
```ts
|
|
183
|
-
import {
|
|
184
|
-
import { fetchUrls } from
|
|
185
|
-
import { readFiles } from
|
|
183
|
+
import { bundle } from "@scalar/json-magic/bundle"
|
|
184
|
+
import { fetchUrls } from "@scalar/json-magic/bundle/plugins/browser"
|
|
185
|
+
import { readFiles } from "@scalar/json-magic/bundle/plugins/node"
|
|
186
|
+
import { dereference } from '@scalar/openapi-parser'
|
|
186
187
|
|
|
187
188
|
// Load a file and all referenced files
|
|
188
|
-
const
|
|
189
|
+
const data = await bundle('./openapi.yaml', {
|
|
189
190
|
plugins: [
|
|
190
191
|
readFiles(),
|
|
191
192
|
fetchUrls({
|
|
@@ -194,25 +195,27 @@ const { filesystem } = await load('./openapi.yaml', {
|
|
|
194
195
|
],
|
|
195
196
|
})
|
|
196
197
|
|
|
197
|
-
// Instead of just passing a single specification, pass the whole
|
|
198
|
-
const result = await dereference(
|
|
198
|
+
// Instead of just passing a single specification, pass the whole data object
|
|
199
|
+
const result = await dereference(data)
|
|
199
200
|
```
|
|
200
201
|
|
|
201
|
-
As you see, `
|
|
202
|
+
As you see, `bundle()` supports plugins. You can write your own plugin, if you'd like to fetch API definitions from another data source, for example your database. Look at the source code of the `readFiles` to learn how this could look like.
|
|
202
203
|
|
|
203
204
|
#### Directly load URLs
|
|
204
205
|
|
|
205
206
|
Once the `fetchUrls` plugin is loaded, you can also just pass an URL:
|
|
206
207
|
|
|
207
208
|
```ts
|
|
208
|
-
import {
|
|
209
|
-
import { fetchUrls } from
|
|
209
|
+
import { bundle } from "@scalar/json-magic/bundle"
|
|
210
|
+
import { fetchUrls, parseJson, parseYaml } from "@scalar/json-magic/bundle/plugins/browser"
|
|
211
|
+
import { readFiles } from "@scalar/json-magic/bundle/plugins/node"
|
|
212
|
+
import { dereference } from '@scalar/openapi-parser'
|
|
210
213
|
|
|
211
214
|
// Load a file and all referenced files
|
|
212
|
-
const
|
|
215
|
+
const data = await bundle(
|
|
213
216
|
'https://registry.scalar.com/@scalar/apis/galaxy/latest?format=yaml',
|
|
214
217
|
{
|
|
215
|
-
plugins: [fetchUrls()],
|
|
218
|
+
plugins: [readFiles(), fetchUrls(), parseYaml(), parseJson()],
|
|
216
219
|
},
|
|
217
220
|
)
|
|
218
221
|
```
|
|
@@ -222,11 +225,39 @@ const { filesystem } = await load(
|
|
|
222
225
|
If you're using the package in a browser environment, you may run into CORS issues when fetching from URLs. You can intercept the requests, for example to use a proxy, though:
|
|
223
226
|
|
|
224
227
|
```ts
|
|
225
|
-
import {
|
|
226
|
-
import { fetchUrls } from
|
|
228
|
+
import { bundle } from "@scalar/json-magic/bundle"
|
|
229
|
+
import { fetchUrls, parseJson, parseYaml } from "@scalar/json-magic/bundle/plugins/browser"
|
|
230
|
+
import { readFiles } from "@scalar/json-magic/bundle/plugins/node"
|
|
231
|
+
import { dereference } from '@scalar/openapi-parser'
|
|
232
|
+
|
|
233
|
+
// Load a file and all referenced files
|
|
234
|
+
const result = await bundle(
|
|
235
|
+
'https://registry.scalar.com/@scalar/apis/galaxy/latest?format=yaml',
|
|
236
|
+
{
|
|
237
|
+
plugins: [
|
|
238
|
+
fetchUrls({
|
|
239
|
+
fetch: (url) => fetch(url.replace('BANANA.net', 'jsdelivr.net')),
|
|
240
|
+
}).get('https://cdn.BANANA.net/npm/@scalar/galaxy/dist/latest.yaml'),
|
|
241
|
+
],
|
|
242
|
+
},
|
|
243
|
+
)
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
#### Migration from the load method
|
|
247
|
+
|
|
248
|
+
If you were previously using the `load()` method and want to migrate to the latest bundle method, the following diff illustrates the changes to apply.
|
|
249
|
+
|
|
250
|
+
```diff
|
|
251
|
+
-import { dereference, load } from '@scalar/openapi-parser'
|
|
252
|
+
-import { fetchUrls } from '@scalar/openapi-parser/plugins/fetch-urls'
|
|
253
|
+
+import { bundle } from "@scalar/json-magic/bundle"
|
|
254
|
+
+import { fetchUrls, parseJson, parseYaml } from "@scalar/json-magic/bundle/plugins/browser"
|
|
255
|
+
+import { readFiles } from "@scalar/json-magic/bundle/plugins/node"
|
|
256
|
+
+import { dereference } from '@scalar/openapi-parser'
|
|
227
257
|
|
|
228
258
|
// Load a file and all referenced files
|
|
229
|
-
const { filesystem } = await load(
|
|
259
|
+
-const { filesystem } = await load(
|
|
260
|
+
+const result = await bundle(
|
|
230
261
|
'https://registry.scalar.com/@scalar/apis/galaxy/latest?format=yaml',
|
|
231
262
|
{
|
|
232
263
|
plugins: [
|
|
@@ -242,14 +273,15 @@ const { filesystem } = await load(
|
|
|
242
273
|
|
|
243
274
|
We are API nerds. You too? Let's chat on Discord: <https://discord.gg/scalar>
|
|
244
275
|
|
|
245
|
-
## Thank you
|
|
276
|
+
## Thank you
|
|
246
277
|
|
|
247
278
|
Thanks a ton for all the help and inspiration:
|
|
248
279
|
|
|
249
280
|
- [@philsturgeon](https://github.com/philsturgeon) to make sure we build something we won't hate.
|
|
250
281
|
- We took a lot of inspiration from [@seriousme](https://github.com/seriousme) and his package [openapi-schema-validator](https://github.com/seriousme/openapi-schema-validator) early-on.
|
|
251
282
|
- You could consider this package the modern successor of [@apidevtools/swagger-parser](https://github.com/APIDevTools/swagger-parser), we even test against it to make sure we're getting the same results (where intended).
|
|
252
|
-
- We stole a lot of example
|
|
283
|
+
- We stole a lot of example documents from [@mermade](https://github.com/mermade) to test against.
|
|
284
|
+
- Thanks [@baywet](https://github.com/baywet) for adding OpenAPI 3.2 support.
|
|
253
285
|
|
|
254
286
|
## License
|
|
255
287
|
|