oas 38.3.1 → 38.5.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 +38 -4
- package/dist/analyzer/index.cjs +16 -16
- package/dist/analyzer/index.js +2 -2
- package/dist/{chunk-3ZXZMZXT.cjs → chunk-2F2OPV5M.cjs} +89 -75
- package/dist/chunk-2F2OPV5M.cjs.map +1 -0
- package/dist/{chunk-ANZIKNVX.js → chunk-6D7GWVEH.js} +2 -2
- package/dist/chunk-6DVSNS26.cjs +709 -0
- package/dist/chunk-6DVSNS26.cjs.map +1 -0
- package/dist/{chunk-7WBPPWYI.cjs → chunk-6GTPCWO5.cjs} +3 -3
- package/dist/{chunk-7WBPPWYI.cjs.map → chunk-6GTPCWO5.cjs.map} +1 -1
- package/dist/{chunk-LZNTJ4ZR.js → chunk-DYHV2B4Z.js} +4 -1
- package/dist/chunk-DYHV2B4Z.js.map +1 -0
- package/dist/{chunk-6HXOZ5GY.cjs → chunk-EARDDQSB.cjs} +5 -2
- package/dist/chunk-EARDDQSB.cjs.map +1 -0
- package/dist/chunk-MR33ELUC.js +709 -0
- package/dist/chunk-MR33ELUC.js.map +1 -0
- package/dist/{chunk-XXX6U72S.js → chunk-TU6UPWO6.js} +19 -5
- package/dist/chunk-TU6UPWO6.js.map +1 -0
- package/dist/extensions.cjs +4 -2
- package/dist/extensions.cjs.map +1 -1
- package/dist/extensions.d.cts +1 -1
- package/dist/extensions.d.ts +1 -1
- package/dist/extensions.js +3 -1
- package/dist/index-Borb1VXh.d.cts +174 -0
- package/dist/index-Br-eJMCh.d.ts +174 -0
- package/dist/index.cjs +60 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +14 -7
- package/dist/index.js.map +1 -1
- package/dist/operation/index.cjs +4 -4
- package/dist/operation/index.js +3 -3
- package/dist/pruner/index.cjs +87 -0
- package/dist/pruner/index.cjs.map +1 -0
- package/dist/pruner/index.d.cts +72 -0
- package/dist/pruner/index.d.ts +72 -0
- package/dist/pruner/index.js +87 -0
- package/dist/pruner/index.js.map +1 -0
- package/dist/reducer/index.cjs +40 -521
- package/dist/reducer/index.cjs.map +1 -1
- package/dist/reducer/index.d.cts +22 -108
- package/dist/reducer/index.d.ts +22 -108
- package/dist/reducer/index.js +38 -519
- package/dist/reducer/index.js.map +1 -1
- package/dist/utils.cjs +3 -3
- package/dist/utils.js +2 -2
- package/package.json +6 -2
- package/dist/chunk-3ZXZMZXT.cjs.map +0 -1
- package/dist/chunk-6HXOZ5GY.cjs.map +0 -1
- package/dist/chunk-LZNTJ4ZR.js.map +0 -1
- package/dist/chunk-XXX6U72S.js.map +0 -1
- /package/dist/{chunk-ANZIKNVX.js.map → chunk-6D7GWVEH.js.map} +0 -0
package/README.md
CHANGED
|
@@ -310,12 +310,13 @@ console.log(await analyzer(petstore, ['polymorphism', 'xml]));
|
|
|
310
310
|
|
|
311
311
|
#### Reducer
|
|
312
312
|
|
|
313
|
-
|
|
314
|
-
> This API is still very experimental and should not be used in production environments!
|
|
313
|
+
The `OpenAPIReducer` utility, located in `oas/reducer`, can be used to reduce an OpenAPI definition down to only the information necessary to fulfill a specific set of tags, paths, operations, operation IDs, or webhooks.
|
|
315
314
|
|
|
316
|
-
|
|
315
|
+
OpenAPI reduction can be helpful not only to isolate and troubleshoot issues with large API definitions, but also to compress a large API definition down to a manageable size containing a specific set of items.
|
|
317
316
|
|
|
318
|
-
|
|
317
|
+
Tag and operation ID filters intersect with path, operation, and webhook filters. When they are combined, an operation is retained only when it matches every configured filter. Multiple operation IDs are alternatives within the operation ID filter.
|
|
318
|
+
|
|
319
|
+
Operation IDs are matched exactly. For operations without an authored `operationId`, use the generated value returned by `Operation.getOperationId()`.
|
|
319
320
|
|
|
320
321
|
```ts
|
|
321
322
|
import petstore from '@readme/oas-examples/3.0/json/petstore.json' with { type: 'json' };
|
|
@@ -328,12 +329,45 @@ console.log(OpenAPIReducer.init(petstore).byTag('Store').reduce());
|
|
|
328
329
|
// Reduces the `petstore` down to only the `POST /pet` operation.
|
|
329
330
|
console.log(OpenAPIReducer.init(petstore).byOperation('/pet', 'post').reduce());
|
|
330
331
|
|
|
332
|
+
// Reduces the `petstore` down to the operation with this exact operation ID.
|
|
333
|
+
console.log(OpenAPIReducer.init(petstore).byOperationId('addPet').reduce());
|
|
334
|
+
|
|
331
335
|
// You can also select all of the methods of a given path by using the `*`
|
|
332
336
|
// wildcard. The resulting reduced API definition here will contain `POST /pet`
|
|
333
337
|
// and `PUT /put`.
|
|
334
338
|
console.log(OpenAPIReducer.init(petstore).byPath('/pet').reduce());
|
|
335
339
|
```
|
|
336
340
|
|
|
341
|
+
#### Pruner
|
|
342
|
+
|
|
343
|
+
The `OpenAPIPruner` utility, located in `oas/pruner`, can be used to remove a specific set of tags, paths, operations, operation IDs, or webhooks from an OpenAPI definition. Components and tags that are no longer reachable from the remaining definition are also removed.
|
|
344
|
+
|
|
345
|
+
Unlike `oas/reducer`, which selects the content to retain, the pruner is useful when you know which content to remove.
|
|
346
|
+
|
|
347
|
+
Pruner filters are additive. Combining tag, operation ID, and location filters removes operations that match any filter.
|
|
348
|
+
|
|
349
|
+
Operation IDs are matched exactly. For operations without an authored `operationId`, use the generated value returned by `Operation.getOperationId()`.
|
|
350
|
+
|
|
351
|
+
```ts
|
|
352
|
+
import petstore from '@readme/oas-examples/3.0/json/petstore.json' with { type: 'json' };
|
|
353
|
+
import { OpenAPIPruner } from 'oas/pruner';
|
|
354
|
+
|
|
355
|
+
// Removes every operation in the `store` tag.
|
|
356
|
+
console.log(OpenAPIPruner.init(petstore).removeTag('store').prune());
|
|
357
|
+
|
|
358
|
+
// Removes only the `POST /pet` operation while retaining other operations on
|
|
359
|
+
// the same path.
|
|
360
|
+
console.log(OpenAPIPruner.init(petstore).removeOperation('/pet', 'post').prune());
|
|
361
|
+
|
|
362
|
+
// Removes the operation with this exact operation ID.
|
|
363
|
+
console.log(OpenAPIPruner.init(petstore).removeOperationId('addPet').prune());
|
|
364
|
+
|
|
365
|
+
// Removes an entire path and all of its operations.
|
|
366
|
+
console.log(OpenAPIPruner.init(petstore).removePath('/pet').prune());
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
Referenced Path Items in paths and webhooks are retained intact for operation-level removals because they cannot be partially transformed without rewriting their shared target. Removing an entire referenced path or webhook removes the Path Item and any components that are no longer reachable when it is not used elsewhere. The pruner rejects removals that would break a `$ref` from a surviving operation.
|
|
370
|
+
|
|
337
371
|
## FAQ
|
|
338
372
|
|
|
339
373
|
#### Can I create an OpenAPI definition with this?
|
package/dist/analyzer/index.cjs
CHANGED
|
@@ -7,8 +7,8 @@ var _chunkCOHEPMUPcjs = require('../chunk-COHEPMUP.cjs');
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
require('../chunk-
|
|
10
|
+
var _chunk6GTPCWO5cjs = require('../chunk-6GTPCWO5.cjs');
|
|
11
|
+
require('../chunk-EARDDQSB.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
var _chunk7PWF3F2Wcjs = require('../chunk-7PWF3F2W.cjs');
|
|
@@ -127,14 +127,14 @@ function accumulateReachableRefs(definition, seeds) {
|
|
|
127
127
|
reachable.add(ref);
|
|
128
128
|
let resolved;
|
|
129
129
|
try {
|
|
130
|
-
resolved = _jsonpointer2.default.get(definition,
|
|
130
|
+
resolved = _jsonpointer2.default.get(definition, _chunk6GTPCWO5cjs.toPointer.call(void 0, ref));
|
|
131
131
|
} catch (e) {
|
|
132
132
|
continue;
|
|
133
133
|
}
|
|
134
134
|
if (resolved === void 0) {
|
|
135
135
|
continue;
|
|
136
136
|
}
|
|
137
|
-
|
|
137
|
+
_chunk6GTPCWO5cjs.collectRefsInSchema.call(void 0, resolved).forEach((nestedRef) => {
|
|
138
138
|
if (!reachable.has(nestedRef)) {
|
|
139
139
|
queue.push(nestedRef);
|
|
140
140
|
}
|
|
@@ -144,7 +144,7 @@ function accumulateReachableRefs(definition, seeds) {
|
|
|
144
144
|
}
|
|
145
145
|
function buildAnchors(rootPointer, extraPointers, reachableRefs) {
|
|
146
146
|
const anchors = [rootPointer, ...extraPointers];
|
|
147
|
-
reachableRefs.forEach((ref) => anchors.push(
|
|
147
|
+
reachableRefs.forEach((ref) => anchors.push(_chunk6GTPCWO5cjs.toPointer.call(void 0, ref)));
|
|
148
148
|
return { anchors, anchorPrefixes: anchors.map((anchor) => `${anchor}/`) };
|
|
149
149
|
}
|
|
150
150
|
function collectSecuritySchemeRefs(security) {
|
|
@@ -168,16 +168,16 @@ function computeOperationScope(definition, path, method) {
|
|
|
168
168
|
}
|
|
169
169
|
const pathItem = definition.paths[pathKey] || {};
|
|
170
170
|
const methodKey = resolveKey(Object.keys(pathItem), method);
|
|
171
|
-
if (!methodKey || !
|
|
171
|
+
if (!methodKey || !_chunk6GTPCWO5cjs.supportedMethods.includes(methodKey.toLowerCase())) {
|
|
172
172
|
throw new Error(`Operation \`${method} ${path}\` not found.`);
|
|
173
173
|
}
|
|
174
174
|
const operation = pathItem[methodKey];
|
|
175
|
-
const rootPointer = `/paths/${
|
|
175
|
+
const rootPointer = `/paths/${_chunk6GTPCWO5cjs.encodePointer.call(void 0, pathKey)}/${methodKey}`;
|
|
176
176
|
const extraPointers = [];
|
|
177
|
-
const seeds = new Set(
|
|
177
|
+
const seeds = new Set(_chunk6GTPCWO5cjs.collectRefsInSchema.call(void 0, operation));
|
|
178
178
|
if (pathItem.parameters) {
|
|
179
|
-
extraPointers.push(`/paths/${
|
|
180
|
-
|
|
179
|
+
extraPointers.push(`/paths/${_chunk6GTPCWO5cjs.encodePointer.call(void 0, pathKey)}/parameters`);
|
|
180
|
+
_chunk6GTPCWO5cjs.collectRefsInSchema.call(void 0, pathItem.parameters).forEach((ref) => seeds.add(ref));
|
|
181
181
|
}
|
|
182
182
|
const security = "security" in operation ? operation.security : definition.security;
|
|
183
183
|
collectSecuritySchemeRefs(security).forEach((ref) => seeds.add(ref));
|
|
@@ -192,16 +192,16 @@ function computeWebhookScope(definition, webhookName, method) {
|
|
|
192
192
|
}
|
|
193
193
|
const webhook = webhooks2[webhookKey] || {};
|
|
194
194
|
const methodKey = resolveKey(Object.keys(webhook), method);
|
|
195
|
-
if (!methodKey || !
|
|
195
|
+
if (!methodKey || !_chunk6GTPCWO5cjs.supportedMethods.includes(methodKey.toLowerCase())) {
|
|
196
196
|
throw new Error(`Webhook operation \`${method} ${webhookName}\` not found.`);
|
|
197
197
|
}
|
|
198
198
|
const operation = webhook[methodKey];
|
|
199
|
-
const rootPointer = `/webhooks/${
|
|
199
|
+
const rootPointer = `/webhooks/${_chunk6GTPCWO5cjs.encodePointer.call(void 0, webhookKey)}/${methodKey}`;
|
|
200
200
|
const extraPointers = [];
|
|
201
|
-
const seeds = new Set(
|
|
201
|
+
const seeds = new Set(_chunk6GTPCWO5cjs.collectRefsInSchema.call(void 0, operation));
|
|
202
202
|
if (webhook.parameters) {
|
|
203
|
-
extraPointers.push(`/webhooks/${
|
|
204
|
-
|
|
203
|
+
extraPointers.push(`/webhooks/${_chunk6GTPCWO5cjs.encodePointer.call(void 0, webhookKey)}/parameters`);
|
|
204
|
+
_chunk6GTPCWO5cjs.collectRefsInSchema.call(void 0, webhook.parameters).forEach((ref) => seeds.add(ref));
|
|
205
205
|
}
|
|
206
206
|
const security = "security" in operation ? operation.security : definition.security;
|
|
207
207
|
collectSecuritySchemeRefs(security).forEach((ref) => seeds.add(ref));
|
|
@@ -392,7 +392,7 @@ async function buildAnalysis(definition, query2, scope) {
|
|
|
392
392
|
}
|
|
393
393
|
if (!query2 || query2.includes("circularRefs")) {
|
|
394
394
|
const { circularRefs: dereferencedCircularRefs } = await dereferenceOasShared(definition);
|
|
395
|
-
const circularRefs = (scope ? dereferencedCircularRefs.filter((ref) => isPointerInScope(
|
|
395
|
+
const circularRefs = (scope ? dereferencedCircularRefs.filter((ref) => isPointerInScope(_chunk6GTPCWO5cjs.toPointer.call(void 0, ref), scope)) : [...dereferencedCircularRefs]).toSorted();
|
|
396
396
|
analysis.circularRefs = {
|
|
397
397
|
present: !!circularRefs.length,
|
|
398
398
|
locations: circularRefs
|
package/dist/analyzer/index.js
CHANGED