@scalar/openapi-parser 0.13.0 → 0.15.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 +19 -0
- package/README.md +157 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +2 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/bundle/bundle.d.ts +279 -0
- package/dist/utils/bundle/bundle.d.ts.map +1 -0
- package/dist/utils/bundle/bundle.js +215 -0
- package/dist/utils/bundle/bundle.js.map +7 -0
- package/dist/utils/bundle/create-limiter.d.ts +21 -0
- package/dist/utils/bundle/create-limiter.d.ts.map +1 -0
- package/dist/utils/bundle/create-limiter.js +31 -0
- package/dist/utils/bundle/create-limiter.js.map +7 -0
- package/dist/utils/bundle/index.d.ts +4 -0
- package/dist/utils/bundle/index.d.ts.map +1 -0
- package/dist/utils/bundle/index.js +9 -0
- package/dist/utils/bundle/index.js.map +7 -0
- package/dist/utils/bundle/plugins/fetch-urls/index.d.ts +39 -0
- package/dist/utils/bundle/plugins/fetch-urls/index.d.ts.map +1 -0
- package/dist/utils/bundle/plugins/fetch-urls/index.js +41 -0
- package/dist/utils/bundle/plugins/fetch-urls/index.js.map +7 -0
- package/dist/utils/bundle/plugins/read-files/index.d.ts +29 -0
- package/dist/utils/bundle/plugins/read-files/index.d.ts.map +1 -0
- package/dist/utils/bundle/plugins/read-files/index.js +30 -0
- package/dist/utils/bundle/plugins/read-files/index.js.map +7 -0
- package/dist/utils/normalize.js +2 -2
- package/dist/utils/normalize.js.map +2 -2
- package/dist/utils/openapi/actions/details.d.ts +7 -0
- package/dist/utils/openapi/actions/details.d.ts.map +1 -0
- package/dist/utils/openapi/actions/details.js +11 -0
- package/dist/utils/openapi/actions/details.js.map +7 -0
- package/dist/utils/openapi/actions/files.d.ts +6 -0
- package/dist/utils/openapi/actions/files.d.ts.map +1 -0
- package/dist/utils/openapi/actions/files.js +9 -0
- package/dist/utils/openapi/actions/files.js.map +7 -0
- package/dist/utils/openapi/actions/get.d.ts +6 -0
- package/dist/utils/openapi/actions/get.d.ts.map +1 -0
- package/dist/utils/openapi/actions/get.js +11 -0
- package/dist/utils/openapi/actions/get.js.map +7 -0
- package/dist/utils/openapi/actions/toJson.d.ts +6 -0
- package/dist/utils/openapi/actions/toJson.d.ts.map +1 -0
- package/dist/utils/openapi/actions/toJson.js +11 -0
- package/dist/utils/openapi/actions/toJson.js.map +7 -0
- package/dist/utils/openapi/actions/toYaml.d.ts +6 -0
- package/dist/utils/openapi/actions/toYaml.d.ts.map +1 -0
- package/dist/utils/openapi/actions/toYaml.js +11 -0
- package/dist/utils/openapi/actions/toYaml.js.map +7 -0
- package/dist/utils/openapi/commands/dereferenceCommand.d.ts +27 -0
- package/dist/utils/openapi/commands/dereferenceCommand.d.ts.map +1 -0
- package/dist/utils/openapi/commands/dereferenceCommand.js +27 -0
- package/dist/utils/openapi/commands/dereferenceCommand.js.map +7 -0
- package/dist/utils/openapi/commands/filterCommand.d.ts +41 -0
- package/dist/utils/openapi/commands/filterCommand.d.ts.map +1 -0
- package/dist/utils/openapi/commands/filterCommand.js +26 -0
- package/dist/utils/openapi/commands/filterCommand.js.map +7 -0
- package/dist/utils/openapi/commands/loadCommand.d.ts +8321 -0
- package/dist/utils/openapi/commands/loadCommand.d.ts.map +1 -0
- package/dist/utils/openapi/commands/loadCommand.js +42 -0
- package/dist/utils/openapi/commands/loadCommand.js.map +7 -0
- package/dist/utils/openapi/commands/upgradeCommand.d.ts +3406 -0
- package/dist/utils/openapi/commands/upgradeCommand.d.ts.map +1 -0
- package/dist/utils/openapi/commands/upgradeCommand.js +29 -0
- package/dist/utils/openapi/commands/upgradeCommand.js.map +7 -0
- package/dist/utils/openapi/commands/validateCommand.d.ts +3451 -0
- package/dist/utils/openapi/commands/validateCommand.d.ts.map +1 -0
- package/dist/utils/openapi/commands/validateCommand.js +33 -0
- package/dist/utils/openapi/commands/validateCommand.js.map +7 -0
- package/dist/utils/openapi/openapi.d.ts +1272 -0
- package/dist/utils/openapi/openapi.d.ts.map +1 -0
- package/dist/utils/openapi/openapi.js +15 -0
- package/dist/utils/openapi/openapi.js.map +7 -0
- package/dist/utils/openapi/openapi.test-d.d.ts +2 -0
- package/dist/utils/openapi/openapi.test-d.d.ts.map +1 -0
- package/dist/utils/openapi/openapi.test-d.js +14 -0
- package/dist/utils/openapi/openapi.test-d.js.map +7 -0
- package/dist/utils/openapi/utils/queueTask.d.ts +6 -0
- package/dist/utils/openapi/utils/queueTask.d.ts.map +1 -0
- package/dist/utils/openapi/utils/queueTask.js +10 -0
- package/dist/utils/openapi/utils/queueTask.js.map +7 -0
- package/dist/utils/openapi/utils/workThroughQueue.d.ts +6 -0
- package/dist/utils/openapi/utils/workThroughQueue.d.ts.map +1 -0
- package/dist/utils/openapi/utils/workThroughQueue.js +52 -0
- package/dist/utils/openapi/utils/workThroughQueue.js.map +7 -0
- package/dist/utils/upgrade-from-two-to-three.js +45 -1
- package/dist/utils/upgrade-from-two-to-three.js.map +2 -2
- package/package.json +16 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @scalar/openapi-parser
|
|
2
2
|
|
|
3
|
+
## 0.15.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b9dacba: fix(openapi-parser): multi entry build for bundler plugins
|
|
8
|
+
- a73e9be: chore(openapi-parser): bring back pipeline syntax
|
|
9
|
+
- f4332eb: feat: external reference resolution and partial bundle of the openapi document
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 17bc0d8: fix: collectionFormat is not migrated to new style and explode keywords
|
|
14
|
+
- 49c04cf: fix(openapi-parser): use dynamic imports inside the plugin
|
|
15
|
+
|
|
16
|
+
## 0.14.0
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- ee3eb77: feat(openapi-parser): bundle openapi documents
|
|
21
|
+
|
|
3
22
|
## 0.13.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -55,6 +55,163 @@ const specification = `{
|
|
|
55
55
|
const { schema, errors } = await dereference(specification)
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
+
### Bundle external references
|
|
59
|
+
|
|
60
|
+
The OpenAPI specification allows to point to external files (URLs or files). But sometimes, you just want to combine all files into one.
|
|
61
|
+
|
|
62
|
+
#### Plugins
|
|
63
|
+
|
|
64
|
+
##### fetchUrls
|
|
65
|
+
This plugins handles all external urls. It works for both node.js and browser environment
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { bundle } from '@scalar/openapi-parser'
|
|
69
|
+
import { fetchUrls } from '@scalar/openapi-parser/utils/bundle/plugins/fetch-urls'
|
|
70
|
+
|
|
71
|
+
const document = {
|
|
72
|
+
openapi: '3.1.0',
|
|
73
|
+
info: { title: 'Bundled API', version: '1.0.0' },
|
|
74
|
+
paths: {},
|
|
75
|
+
components: {
|
|
76
|
+
schemas: {
|
|
77
|
+
User: { $ref: 'https://example.com/user-schema.json#' }
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// This will bundle all external documents and turn all references from external into internal
|
|
83
|
+
await bundle(document, {
|
|
84
|
+
plugins: [fetchUrls()],
|
|
85
|
+
treeShake: true // <------ This flag will try to remove any unused part of the external document
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
console.log(document)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
###### Limiting the number of concurrent requests
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
await bundle(document, {
|
|
95
|
+
plugins: [
|
|
96
|
+
fetchUrls({
|
|
97
|
+
limit: 10, // it should run at most 10 requests at the same time
|
|
98
|
+
}),
|
|
99
|
+
],
|
|
100
|
+
treeShake: false
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
###### Custom headers
|
|
106
|
+
To pass custom headers to requests for specific domains you can configure the fetch plugin like the example
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
await bundle(
|
|
110
|
+
document,
|
|
111
|
+
{
|
|
112
|
+
plugins: [
|
|
113
|
+
fetchUrls({
|
|
114
|
+
// Pass custom headers
|
|
115
|
+
// The header will only be attached to the list of domains
|
|
116
|
+
headers: [
|
|
117
|
+
{
|
|
118
|
+
domains: ['example.com'],
|
|
119
|
+
headers: {
|
|
120
|
+
'Authorization': 'Bearer <TOKEN>'
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
}),
|
|
125
|
+
readFiles(),
|
|
126
|
+
],
|
|
127
|
+
treeShake: false
|
|
128
|
+
},
|
|
129
|
+
)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
###### Custom fetch function
|
|
133
|
+
For advanced use cases like proxying requests or implementing custom network logic, you can provide your own fetch implementation. This allows you to handle things like CORS restrictions, custom authentication flows, or request/response transformations.
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
await bundle(
|
|
137
|
+
document,
|
|
138
|
+
{
|
|
139
|
+
plugins: [
|
|
140
|
+
fetchUrls({
|
|
141
|
+
// Custom fetcher function
|
|
142
|
+
fetch: async (input, init) => {
|
|
143
|
+
console.log('Custom fetch logic')
|
|
144
|
+
return fetch(input, init)
|
|
145
|
+
},
|
|
146
|
+
})
|
|
147
|
+
readFiles(),
|
|
148
|
+
],
|
|
149
|
+
treeShake: false
|
|
150
|
+
},
|
|
151
|
+
)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
###### Bundle from remote url
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
const result = await bundle(
|
|
158
|
+
'https://example.com/openapi.json',
|
|
159
|
+
{
|
|
160
|
+
plugins: [
|
|
161
|
+
fetchUrls(),
|
|
162
|
+
],
|
|
163
|
+
treeShake: false
|
|
164
|
+
},
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
// Bundled document
|
|
168
|
+
console.log(result)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
##### readFiles
|
|
172
|
+
This plugins handles local files. Only works on node.js environment
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
import { bundle, readFiles } from '@scalar/openapi-parser'
|
|
176
|
+
|
|
177
|
+
const document = {
|
|
178
|
+
openapi: '3.1.0',
|
|
179
|
+
info: { title: 'Bundled API', version: '1.0.0' },
|
|
180
|
+
paths: {},
|
|
181
|
+
components: {
|
|
182
|
+
schemas: {
|
|
183
|
+
User: { $ref: './user-schema.json#' }
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// This will bundle all external documents and turn all references from external into internal
|
|
189
|
+
await bundle(document, {
|
|
190
|
+
plugins: [readFiles()],
|
|
191
|
+
treeShake: false
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
console.log(document)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
###### Bundle from local file
|
|
198
|
+
You can pass the file path directly but make sure to have the correct plugins to handle reading from the local files
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
const result = await bundle(
|
|
202
|
+
'./input.json',
|
|
203
|
+
{
|
|
204
|
+
plugins: [
|
|
205
|
+
readFiles(),
|
|
206
|
+
],
|
|
207
|
+
treeShake: false
|
|
208
|
+
},
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
// Bundled document
|
|
212
|
+
console.log(result)
|
|
213
|
+
```
|
|
214
|
+
|
|
58
215
|
### Track references
|
|
59
216
|
|
|
60
217
|
The `dereference` function accepts an `onDereference` callback option that gets called whenever a reference is resolved. This can be useful for tracking which schemas are being dereferenced:
|
package/dist/index.d.ts
CHANGED
|
@@ -14,5 +14,7 @@ export { upgrade } from './utils/upgrade.js';
|
|
|
14
14
|
export { upgradeFromThreeToThreeOne } from './utils/upgrade-from-three-to-three-one.js';
|
|
15
15
|
export { upgradeFromTwoToThree } from './utils/upgrade-from-two-to-three.js';
|
|
16
16
|
export { validate } from './utils/validate.js';
|
|
17
|
+
export { bundle } from './utils/bundle/index.js';
|
|
17
18
|
export type { LoadResult, Filesystem, AnyObject, ErrorObject } from './types/index.js';
|
|
19
|
+
export { openapi } from './utils/openapi/openapi.js';
|
|
18
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAA;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,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./utils/upgrade.js";
|
|
|
14
14
|
import { upgradeFromThreeToThreeOne } from "./utils/upgrade-from-three-to-three-one.js";
|
|
15
15
|
import { upgradeFromTwoToThree } from "./utils/upgrade-from-two-to-three.js";
|
|
16
16
|
import { validate } from "./utils/validate.js";
|
|
17
|
+
import { bundle } from "./utils/bundle/index.js";
|
|
18
|
+
import { openapi } from "./utils/openapi/openapi.js";
|
|
17
19
|
export {
|
|
20
|
+
bundle,
|
|
18
21
|
dereference,
|
|
19
22
|
escapeJsonPointer,
|
|
20
23
|
filter,
|
|
@@ -22,6 +25,7 @@ export {
|
|
|
22
25
|
isYaml,
|
|
23
26
|
load,
|
|
24
27
|
normalize,
|
|
28
|
+
openapi,
|
|
25
29
|
sanitize,
|
|
26
30
|
toJson,
|
|
27
31
|
toYaml,
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { dereference } from './utils/dereference'\nexport { escapeJsonPointer } from './utils/escape-json-pointer'\nexport { filter } from './utils/filter'\nexport { isJson } from './utils/is-json'\nexport { isYaml } from './utils/is-yaml'\nexport { load } from './utils/load'\nexport { normalize } from './utils/normalize'\nexport { sanitize } from './utils/transform/sanitize'\nexport { toJson } from './utils/to-json'\nexport { toYaml } from './utils/to-yaml'\nexport { traverse } from './utils/traverse'\nexport { unescapeJsonPointer } from './utils/unescape-json-pointer'\nexport { upgrade } from './utils/upgrade'\nexport { upgradeFromThreeToThreeOne } from './utils/upgrade-from-three-to-three-one'\nexport { upgradeFromTwoToThree } from './utils/upgrade-from-two-to-three'\nexport { validate } from './utils/validate'\nexport type { LoadResult, Filesystem, AnyObject, ErrorObject } from './types'\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,gBAAgB;AACzB,SAAS,2BAA2B;AACpC,SAAS,eAAe;AACxB,SAAS,kCAAkC;AAC3C,SAAS,6BAA6B;AACtC,SAAS,gBAAgB;",
|
|
4
|
+
"sourcesContent": ["export { dereference } from './utils/dereference'\nexport { escapeJsonPointer } from './utils/escape-json-pointer'\nexport { filter } from './utils/filter'\nexport { isJson } from './utils/is-json'\nexport { isYaml } from './utils/is-yaml'\nexport { load } from './utils/load'\nexport { normalize } from './utils/normalize'\nexport { sanitize } from './utils/transform/sanitize'\nexport { toJson } from './utils/to-json'\nexport { toYaml } from './utils/to-yaml'\nexport { traverse } from './utils/traverse'\nexport { unescapeJsonPointer } from './utils/unescape-json-pointer'\nexport { upgrade } from './utils/upgrade'\nexport { upgradeFromThreeToThreeOne } from './utils/upgrade-from-three-to-three-one'\nexport { upgradeFromTwoToThree } from './utils/upgrade-from-two-to-three'\nexport { validate } from './utils/validate'\nexport { bundle } from './utils/bundle'\nexport type { LoadResult, Filesystem, AnyObject, ErrorObject } from './types'\nexport { openapi } from './utils/openapi/openapi'\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,gBAAgB;AACzB,SAAS,2BAA2B;AACpC,SAAS,eAAe;AACxB,SAAS,kCAAkC;AAC3C,SAAS,6BAA6B;AACtC,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAEvB,SAAS,eAAe;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { ERRORS, OpenApiVersion } from '../configuration/index.js';
|
|
|
5
5
|
*/
|
|
6
6
|
export type Merge<A, B> = A & Omit<B, keyof A>;
|
|
7
7
|
export type AnyObject = Record<string, any>;
|
|
8
|
+
export type UnknownObject = Record<string, unknown>;
|
|
8
9
|
/**
|
|
9
10
|
* JSON, YAML or object representation of an OpenAPI API definition
|
|
10
11
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAG7D;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;AAE9C,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAE3C;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,SAAS,CAAA;AAEvD,MAAM,MAAM,UAAU,GAAG;IACvB,UAAU,EAAE,UAAU,CAAA;IACtB,aAAa,EAAE,SAAS,CAAA;IACxB,MAAM,CAAC,EAAE,WAAW,EAAE,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,OAAO,CAAA;IACd,aAAa,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAA;IAChC,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,MAAM,CAAC,EAAE,WAAW,EAAE,CAAA;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAA;CAC1B,CAAA;AAED,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI;IACzE,aAAa,EAAE,CAAC,CAAA;I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,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GAC/E,KAAK,SAAS,IAAI,GAChB,IAAI,SAAS,IAAI,EAAE,GACjB,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC,GAC5D,KAAK,GACP,KAAK,GACP,uBAAuB,CAAA"}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import type { UnknownObject } from '../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a string is a remote URL (starts with http:// or https://)
|
|
4
|
+
* @param value - The URL string to check
|
|
5
|
+
* @returns true if the string is a remote URL, false otherwise
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* isRemoteUrl('https://example.com/schema.json') // true
|
|
9
|
+
* isRemoteUrl('http://api.example.com/schemas/user.json') // true
|
|
10
|
+
* isRemoteUrl('#/components/schemas/User') // false
|
|
11
|
+
* isRemoteUrl('./local-schema.json') // false
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function isRemoteUrl(value: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Checks if a string is a local reference (starts with #)
|
|
17
|
+
* @param value - The reference string to check
|
|
18
|
+
* @returns true if the string is a local reference, false otherwise
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* isLocalRef('#/components/schemas/User') // true
|
|
22
|
+
* isLocalRef('https://example.com/schema.json') // false
|
|
23
|
+
* isLocalRef('./local-schema.json') // false
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function isLocalRef(value: string): boolean;
|
|
27
|
+
export type ResolveResult = {
|
|
28
|
+
ok: true;
|
|
29
|
+
data: unknown;
|
|
30
|
+
} | {
|
|
31
|
+
ok: false;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves a nested value from an object using an array of property segments.
|
|
35
|
+
* @param target - The target object to traverse
|
|
36
|
+
* @param segments - Array of property names representing the path to the desired value
|
|
37
|
+
* @returns The value at the specified path, or undefined if the path doesn't exist
|
|
38
|
+
* @example
|
|
39
|
+
* const obj = { foo: { bar: { baz: 42 } } };
|
|
40
|
+
* getNestedValue(obj, ['foo', 'bar', 'baz']); // returns 42
|
|
41
|
+
*/
|
|
42
|
+
export declare function getNestedValue(target: Record<string, any>, segments: string[]): any;
|
|
43
|
+
/**
|
|
44
|
+
* Sets a value at a specified path in an object, creating intermediate objects/arrays as needed.
|
|
45
|
+
* This function traverses the object structure and creates any missing intermediate objects
|
|
46
|
+
* or arrays based on the path segments. If the next segment is a numeric string, it creates
|
|
47
|
+
* an array instead of an object.
|
|
48
|
+
*
|
|
49
|
+
* ⚠️ Warning: Be careful with object keys that look like numbers (e.g. "123") as this function
|
|
50
|
+
* will interpret them as array indices and create arrays instead of objects. If you need to
|
|
51
|
+
* use numeric-looking keys, consider prefixing them with a non-numeric character.
|
|
52
|
+
*
|
|
53
|
+
* @param obj - The target object to set the value in
|
|
54
|
+
* @param path - The JSON pointer path where the value should be set
|
|
55
|
+
* @param value - The value to set at the specified path
|
|
56
|
+
* @throws {Error} If attempting to set a value at the root path ('')
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const obj = {}
|
|
60
|
+
* setValueAtPath(obj, '/foo/bar/0', 'value')
|
|
61
|
+
* // Result:
|
|
62
|
+
* // {
|
|
63
|
+
* // foo: {
|
|
64
|
+
* // bar: ['value']
|
|
65
|
+
* // }
|
|
66
|
+
* // }
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const obj = { existing: { path: 'old' } }
|
|
70
|
+
* setValueAtPath(obj, '/existing/path', 'new')
|
|
71
|
+
* // Result:
|
|
72
|
+
* // {
|
|
73
|
+
* // existing: {
|
|
74
|
+
* // path: 'new'
|
|
75
|
+
* // }
|
|
76
|
+
* // }
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* // ⚠️ Warning: This will create an array instead of an object with key "123"
|
|
80
|
+
* setValueAtPath(obj, '/foo/123/bar', 'value')
|
|
81
|
+
* // Result:
|
|
82
|
+
* // {
|
|
83
|
+
* // foo: [
|
|
84
|
+
* // undefined,
|
|
85
|
+
* // undefined,
|
|
86
|
+
* // undefined,
|
|
87
|
+
* // { bar: 'value' }
|
|
88
|
+
* // ]
|
|
89
|
+
* // }
|
|
90
|
+
*/
|
|
91
|
+
export declare function setValueAtPath(obj: any, path: string, value: any): void;
|
|
92
|
+
/**
|
|
93
|
+
* Prefixes an internal JSON reference with a given path prefix.
|
|
94
|
+
* Takes a local reference (starting with #) and prepends the provided prefix segments.
|
|
95
|
+
*
|
|
96
|
+
* @param input - The internal reference string to prefix (must start with #)
|
|
97
|
+
* @param prefix - Array of path segments to prepend to the reference
|
|
98
|
+
* @returns The prefixed reference string
|
|
99
|
+
* @throws Error if input is not a local reference
|
|
100
|
+
* @example
|
|
101
|
+
* prefixInternalRef('#/components/schemas/User', ['definitions'])
|
|
102
|
+
* // Returns: '#/definitions/components/schemas/User'
|
|
103
|
+
*/
|
|
104
|
+
export declare function prefixInternalRef(input: string, prefix: string[]): string;
|
|
105
|
+
/**
|
|
106
|
+
* Updates internal references in an object by adding a prefix to their paths.
|
|
107
|
+
* Recursively traverses the input object and modifies any local $ref references
|
|
108
|
+
* by prepending the given prefix to their paths. This is used when embedding external
|
|
109
|
+
* documents to maintain correct reference paths relative to the main document.
|
|
110
|
+
*
|
|
111
|
+
* @param input - The object to update references in
|
|
112
|
+
* @param prefix - Array of path segments to prepend to internal reference paths
|
|
113
|
+
* @returns void
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* const input = {
|
|
117
|
+
* foo: {
|
|
118
|
+
* $ref: '#/components/schemas/User'
|
|
119
|
+
* }
|
|
120
|
+
* }
|
|
121
|
+
* prefixInternalRefRecursive(input, ['definitions'])
|
|
122
|
+
* // Result:
|
|
123
|
+
* // {
|
|
124
|
+
* // foo: {
|
|
125
|
+
* // $ref: '#/definitions/components/schemas/User'
|
|
126
|
+
* // }
|
|
127
|
+
* // }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export declare function prefixInternalRefRecursive(input: unknown, prefix: string[]): string;
|
|
131
|
+
/**
|
|
132
|
+
* Generates a short SHA-1 hash from a string value.
|
|
133
|
+
* This function is used to create unique identifiers for external references
|
|
134
|
+
* while keeping the hash length manageable. It uses the Web Crypto API to
|
|
135
|
+
* generate a SHA-1 hash and returns the first 7 characters of the hex string.
|
|
136
|
+
* If the hash would be all numbers, it ensures at least one letter is included.
|
|
137
|
+
*
|
|
138
|
+
* @param value - The string to hash
|
|
139
|
+
* @returns A 7-character hexadecimal hash with at least one letter
|
|
140
|
+
* @example
|
|
141
|
+
* // Returns "2ae91d7"
|
|
142
|
+
* await getHash("https://example.com/schema.json")
|
|
143
|
+
*/
|
|
144
|
+
export declare function getHash(value: string): Promise<string>;
|
|
145
|
+
/**
|
|
146
|
+
* Represents a plugin that handles resolving references from external sources.
|
|
147
|
+
* Plugins are responsible for fetching and processing data from different sources
|
|
148
|
+
* like URLs or the filesystem. Each plugin must implement validation to determine
|
|
149
|
+
* if it can handle a specific reference, and an execution function to perform
|
|
150
|
+
* the actual resolution.
|
|
151
|
+
*
|
|
152
|
+
* @property validate - Determines if this plugin can handle the given reference
|
|
153
|
+
* @property exec - Fetches and processes the reference, returning the resolved data
|
|
154
|
+
*/
|
|
155
|
+
export type Plugin = {
|
|
156
|
+
validate: (value: string) => boolean;
|
|
157
|
+
exec: (value: string) => Promise<ResolveResult>;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Configuration options for the bundler.
|
|
161
|
+
* Controls how external references are resolved and processed during bundling.
|
|
162
|
+
*/
|
|
163
|
+
type Config = {
|
|
164
|
+
/**
|
|
165
|
+
* Array of plugins that handle resolving references from different sources.
|
|
166
|
+
* Each plugin is responsible for fetching and processing data from specific sources
|
|
167
|
+
* like URLs or the filesystem.
|
|
168
|
+
*/
|
|
169
|
+
plugins: Plugin[];
|
|
170
|
+
/**
|
|
171
|
+
* Optional root object that serves as the base document when bundling a subpart.
|
|
172
|
+
* This allows resolving references relative to the root document's location,
|
|
173
|
+
* ensuring proper path resolution for nested references.
|
|
174
|
+
*/
|
|
175
|
+
root?: UnknownObject;
|
|
176
|
+
/**
|
|
177
|
+
* Optional cache to store promises of resolved references.
|
|
178
|
+
* Helps avoid duplicate fetches/reads of the same resource by storing
|
|
179
|
+
* the resolution promises for reuse.
|
|
180
|
+
*/
|
|
181
|
+
cache?: Map<string, Promise<ResolveResult>>;
|
|
182
|
+
/**
|
|
183
|
+
* Cache of visited nodes during partial bundling.
|
|
184
|
+
* Used to prevent re-bundling the same tree multiple times when doing partial bundling,
|
|
185
|
+
* improving performance by avoiding redundant processing of already bundled sections.
|
|
186
|
+
*/
|
|
187
|
+
visitedNodes?: Set<unknown>;
|
|
188
|
+
/**
|
|
189
|
+
* Enable tree shaking to optimize the bundle size.
|
|
190
|
+
* When enabled, only the parts of external documents that are actually referenced
|
|
191
|
+
* will be included in the final bundle.
|
|
192
|
+
*/
|
|
193
|
+
treeShake: boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Optional flag to generate a URL map.
|
|
196
|
+
* When enabled, tracks the original source URLs of bundled references
|
|
197
|
+
* in an x-ext-urls section for reference mapping.
|
|
198
|
+
*/
|
|
199
|
+
urlMap?: boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Optional hooks to monitor the bundler's lifecycle.
|
|
202
|
+
* Allows tracking the progress and status of reference resolution.
|
|
203
|
+
*/
|
|
204
|
+
hooks?: Partial<{
|
|
205
|
+
/** Called when starting to resolve a reference */
|
|
206
|
+
onResolveStart: (node: Record<string, unknown> & Record<'$ref', unknown>) => void;
|
|
207
|
+
/** Called when a reference resolution fails */
|
|
208
|
+
onResolveError: (node: Record<string, unknown> & Record<'$ref', unknown>) => void;
|
|
209
|
+
/** Called when a reference is successfully resolved */
|
|
210
|
+
onResolveSuccess: (node: Record<string, unknown> & Record<'$ref', unknown>) => void;
|
|
211
|
+
}>;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Bundles an OpenAPI specification by resolving all external references.
|
|
215
|
+
* This function traverses the input object recursively and embeds external $ref
|
|
216
|
+
* references into an x-ext section. External references can be URLs or local files.
|
|
217
|
+
* The original $refs are updated to point to their embedded content in the x-ext section.
|
|
218
|
+
* If the input is an object, it will be modified in place by adding an x-ext
|
|
219
|
+
* property to store resolved external references.
|
|
220
|
+
*
|
|
221
|
+
* @param input - The OpenAPI specification object or string to bundle. If a string is provided,
|
|
222
|
+
* it should be a URL or file path that points to an OpenAPI specification.
|
|
223
|
+
* The string will be resolved using the provided plugins before bundling.
|
|
224
|
+
* @param config - Configuration object containing plugins and options for bundling OpenAPI specifications
|
|
225
|
+
* @returns A promise that resolves to the bundled specification with all references embedded
|
|
226
|
+
* @example
|
|
227
|
+
* // Example with object input
|
|
228
|
+
* const spec = {
|
|
229
|
+
* paths: {
|
|
230
|
+
* '/users': {
|
|
231
|
+
* $ref: 'https://example.com/schemas/users.yaml'
|
|
232
|
+
* }
|
|
233
|
+
* }
|
|
234
|
+
* }
|
|
235
|
+
*
|
|
236
|
+
* const bundled = await bundle(spec, {
|
|
237
|
+
* plugins: [fetchUrls()],
|
|
238
|
+
* treeShake: true,
|
|
239
|
+
* urlMap: true,
|
|
240
|
+
* hooks: {
|
|
241
|
+
* onResolveStart: (ref) => console.log('Resolving:', ref.$ref),
|
|
242
|
+
* onResolveSuccess: (ref) => console.log('Resolved:', ref.$ref),
|
|
243
|
+
* onResolveError: (ref) => console.log('Failed to resolve:', ref.$ref)
|
|
244
|
+
* }
|
|
245
|
+
* })
|
|
246
|
+
* // Result:
|
|
247
|
+
* // {
|
|
248
|
+
* // paths: {
|
|
249
|
+
* // '/users': {
|
|
250
|
+
* // $ref: '#/x-ext/abc123'
|
|
251
|
+
* // }
|
|
252
|
+
* // },
|
|
253
|
+
* // 'x-ext': {
|
|
254
|
+
* // 'abc123': {
|
|
255
|
+
* // // Resolved content from users.yaml
|
|
256
|
+
* // }
|
|
257
|
+
* // },
|
|
258
|
+
* // 'x-ext-urls': {
|
|
259
|
+
* // 'https://example.com/schemas/users.yaml': 'abc123'
|
|
260
|
+
* // }
|
|
261
|
+
* // }
|
|
262
|
+
*
|
|
263
|
+
* // Example with URL input
|
|
264
|
+
* const bundledFromUrl = await bundle('https://example.com/openapi.yaml', {
|
|
265
|
+
* plugins: [fetchUrls()],
|
|
266
|
+
* treeShake: true,
|
|
267
|
+
* urlMap: true,
|
|
268
|
+
* hooks: {
|
|
269
|
+
* onResolveStart: (ref) => console.log('Resolving:', ref.$ref),
|
|
270
|
+
* onResolveSuccess: (ref) => console.log('Resolved:', ref.$ref),
|
|
271
|
+
* onResolveError: (ref) => console.log('Failed to resolve:', ref.$ref)
|
|
272
|
+
* }
|
|
273
|
+
* })
|
|
274
|
+
* // The function will first fetch the OpenAPI spec from the URL,
|
|
275
|
+
* // then bundle all its external references into the x-ext section
|
|
276
|
+
*/
|
|
277
|
+
export declare function bundle(input: UnknownObject | string, config: Config): Promise<unknown>;
|
|
278
|
+
export {};
|
|
279
|
+
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../../src/utils/bundle/bundle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAM5C;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED,MAAM,MAAM,aAAa,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,K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