@scalar/openapi-parser 0.22.3 → 0.23.1

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 (42) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +51 -19
  3. package/dist/configuration/index.d.ts +1399 -0
  4. package/dist/configuration/index.d.ts.map +1 -1
  5. package/dist/configuration/index.js +3 -1
  6. package/dist/configuration/index.js.map +2 -2
  7. package/dist/index.d.ts +2 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js.map +2 -2
  10. package/dist/lib/Validator/Validator.d.ts +6 -16
  11. package/dist/lib/Validator/Validator.d.ts.map +1 -1
  12. package/dist/lib/Validator/Validator.js +8 -9
  13. package/dist/lib/Validator/Validator.js.map +2 -2
  14. package/dist/plugins/read-files/read-files.js +2 -2
  15. package/dist/plugins/read-files/read-files.js.map +2 -2
  16. package/dist/schemas/v3.2/schema.d.ts +1401 -0
  17. package/dist/schemas/v3.2/schema.d.ts.map +1 -0
  18. package/dist/schemas/v3.2/schema.js +1505 -0
  19. package/dist/schemas/v3.2/schema.js.map +7 -0
  20. package/dist/utils/dereference.d.ts +7 -2
  21. package/dist/utils/dereference.d.ts.map +1 -1
  22. package/dist/utils/dereference.js +1 -1
  23. package/dist/utils/dereference.js.map +2 -2
  24. package/dist/utils/normalize.js +1 -1
  25. package/dist/utils/normalize.js.map +2 -2
  26. package/dist/utils/openapi/utils/workThroughQueue.d.ts.map +1 -1
  27. package/dist/utils/openapi/utils/workThroughQueue.js +2 -3
  28. package/dist/utils/openapi/utils/workThroughQueue.js.map +2 -2
  29. package/dist/utils/resolve-references.d.ts.map +1 -1
  30. package/dist/utils/resolve-references.js.map +2 -2
  31. package/dist/utils/validate.d.ts.map +1 -1
  32. package/dist/utils/validate.js +13 -9
  33. package/dist/utils/validate.js.map +2 -2
  34. package/package.json +7 -7
  35. package/dist/polyfills/index.d.ts +0 -2
  36. package/dist/polyfills/index.d.ts.map +0 -1
  37. package/dist/polyfills/index.js +0 -25
  38. package/dist/polyfills/index.js.map +0 -7
  39. package/dist/polyfills/path.d.ts +0 -24
  40. package/dist/polyfills/path.d.ts.map +0 -1
  41. package/dist/polyfills/path.js +0 -174
  42. package/dist/polyfills/path.js.map +0 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # @scalar/openapi-parser
2
2
 
3
+ ## 0.23.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#7235](https://github.com/scalar/scalar/pull/7235) [`c1ecd0c`](https://github.com/scalar/scalar/commit/c1ecd0c6096f3fbe2e3d8ad3794ea718bb6bce66) Thanks [@marcalexiei](https://github.com/marcalexiei)! - fix(openapi-parser): use `node:path` instead of polyfill
8
+
9
+ - [#7241](https://github.com/scalar/scalar/pull/7241) [`2377b76`](https://github.com/scalar/scalar/commit/2377b76d050f8de70037b17a32d0dd1181d3311d) Thanks [@hanspagel](https://github.com/hanspagel)! - chore: use "current" not "latest" scalar registry url
10
+
11
+ - Updated dependencies [[`c1ecd0c`](https://github.com/scalar/scalar/commit/c1ecd0c6096f3fbe2e3d8ad3794ea718bb6bce66), [`fddf294`](https://github.com/scalar/scalar/commit/fddf294b00dd8c9eb5c713c338f2ec6e3f62523d)]:
12
+ - @scalar/json-magic@0.8.0
13
+
14
+ ## 0.23.0
15
+
16
+ ### Minor Changes
17
+
18
+ - [#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
19
+
20
+ - [#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
21
+
22
+ ### Patch Changes
23
+
24
+ - [#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
25
+
26
+ - [#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
27
+
28
+ - [#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
29
+
30
+ - [#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.
31
+
32
+ - [#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
33
+
34
+ - [#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
35
+
36
+ - 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)]:
37
+ - @scalar/openapi-upgrader@0.1.4
38
+ - @scalar/openapi-types@0.5.1
39
+ - @scalar/json-magic@0.7.0
40
+
3
41
  ## 0.22.3
4
42
 
5
43
  ### Patch Changes
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![License](https://img.shields.io/npm/l/%40scalar%2Fopenapi-parser)](https://www.npmjs.com/package/@scalar/openapi-parser)
6
6
  [![Discord](https://img.shields.io/discord/1135330207960678410?style=flat&color=5865F2)](https://discord.gg/scalar)
7
7
 
8
- Modern OpenAPI parser written in TypeScript with support for OpenAPI 3.1, OpenAPI 3.0 and Swagger 2.0.
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 { dereference, load } from '@scalar/openapi-parser'
184
- import { fetchUrls } from '@scalar/openapi-parser/plugins/fetch-urls'
185
- import { readFiles } from '@scalar/openapi-parser/plugins/read-files'
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 { filesystem } = await load('./openapi.yaml', {
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 “filesystem”
198
- const result = await dereference(filesystem)
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, `load()` supports plugins. You can write your own plugin, if you'd like to fetch API defintions from another data source, for example your database. Look at the source code of the `readFiles` to learn how this could look like.
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 { dereference, load } from '@scalar/openapi-parser'
209
- import { fetchUrls } from '@scalar/openapi-parser/plugins/fetch-urls'
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 { filesystem } = await load(
213
- 'https://registry.scalar.com/@scalar/apis/galaxy/latest?format=yaml',
215
+ const data = await bundle(
216
+ 'https://registry.scalar.com/@scalar/apis/galaxy?format=yaml',
214
217
  {
215
- plugins: [fetchUrls()],
218
+ plugins: [readFiles(), fetchUrls(), parseYaml(), parseJson()],
216
219
  },
217
220
  )
218
221
  ```
@@ -222,12 +225,40 @@ 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 { dereference, load } from '@scalar/openapi-parser'
226
- import { fetchUrls } from '@scalar/openapi-parser/plugins/fetch-urls'
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?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(
230
- 'https://registry.scalar.com/@scalar/apis/galaxy/latest?format=yaml',
259
+ -const { filesystem } = await load(
260
+ +const result = await bundle(
261
+ 'https://registry.scalar.com/@scalar/apis/galaxy?format=yaml',
231
262
  {
232
263
  plugins: [
233
264
  fetchUrls({
@@ -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 specification from [@mermade](https://github.com/mermade) to test against.
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