oas 36.0.2 → 37.0.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 +0 -5
- package/dist/analyzer/index.cjs +83 -28
- package/dist/analyzer/index.cjs.map +1 -1
- package/dist/analyzer/index.d.cts +3 -10
- package/dist/analyzer/index.d.ts +3 -10
- package/dist/analyzer/index.js +81 -26
- package/dist/analyzer/index.js.map +1 -1
- package/dist/analyzer/types.d.cts +0 -1
- package/dist/analyzer/types.d.ts +0 -1
- package/dist/{chunk-UDN4U5TL.cjs → chunk-GS43VKJH.cjs} +320 -274
- package/dist/chunk-GS43VKJH.cjs.map +1 -0
- package/dist/{chunk-6MDVLJ3A.js → chunk-IEN4GZPF.js} +9 -23
- package/dist/chunk-IEN4GZPF.js.map +1 -0
- package/dist/{chunk-SCWW2SNX.cjs → chunk-UKD63LKG.cjs} +10 -24
- package/dist/chunk-UKD63LKG.cjs.map +1 -0
- package/dist/{chunk-35LEYZEY.js → chunk-WIVQX3DA.js} +199 -153
- package/dist/chunk-WIVQX3DA.js.map +1 -0
- package/dist/index.cjs +634 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -135
- package/dist/index.d.ts +38 -135
- package/dist/index.js +633 -6
- package/dist/index.js.map +1 -1
- package/dist/operation/index.cjs +3 -3
- package/dist/operation/index.js +2 -2
- package/dist/reducer/index.cjs +7 -7
- package/dist/reducer/index.js +1 -1
- package/dist/utils.cjs +2 -2
- package/dist/utils.js +1 -1
- package/package.json +1 -4
- package/dist/chunk-35LEYZEY.js.map +0 -1
- package/dist/chunk-6MDVLJ3A.js.map +0 -1
- package/dist/chunk-IXQKQM3K.js +0 -866
- package/dist/chunk-IXQKQM3K.js.map +0 -1
- package/dist/chunk-SCWW2SNX.cjs.map +0 -1
- package/dist/chunk-UDN4U5TL.cjs.map +0 -1
- package/dist/chunk-YKV73CBG.cjs +0 -866
- package/dist/chunk-YKV73CBG.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -76,8 +76,6 @@ Because this library has full TypeScript types and docblocks this README is not
|
|
|
76
76
|
<!-- prettier-ignore-start -->
|
|
77
77
|
| Method | Description |
|
|
78
78
|
| :--- | :--- |
|
|
79
|
-
| `.dereference()` | Dereference the current OpenAPI definition. Note that this will ignore circular references. |
|
|
80
|
-
| `.getCircularReferences()` | Retrieve an array of any circular `$ref` pointer that may exist wthin the OpenAPI definition. Note that this requires `.dereference()` to be called first. |
|
|
81
79
|
| `.getDefinition()` | Retrieve the OpenAPI definition that was fed into the `Oas` constructor. |
|
|
82
80
|
| `.getTags()` | Retrieve an array of all tags that exist within the API definition and are set on operations. |
|
|
83
81
|
| `.getPaths()` | Retrieve every operation that exists within the API definition. This returns an array of instances of the `Operation` class. |
|
|
@@ -85,7 +83,6 @@ Because this library has full TypeScript types and docblocks this README is not
|
|
|
85
83
|
| `.getVersion()` | Retrieve the OpenAPI version that this API definition is targeted for. |
|
|
86
84
|
| `.getWebhooks()` | Retrieve every webhook operation that exists within the API definition. This returns an array of instances of the `Webhook` class. |
|
|
87
85
|
| `.hasSecurityScheme()` | Determine if a security scheme exists within the API definition. |
|
|
88
|
-
| `.isDereferenced()` | Determine if the current API definition has been dereferenced or not. |
|
|
89
86
|
| `#init()` | An alternative for `new Oas()` that you can use if the typing on the `Oas` constructor gives you trouble. Typing OpenAPI definitions is hard! |
|
|
90
87
|
<!-- prettier-ignore-end -->
|
|
91
88
|
|
|
@@ -155,12 +152,10 @@ const operation = petstore.operation('/pet', 'post');
|
|
|
155
152
|
<!-- prettier-ignore-start -->
|
|
156
153
|
| Method | Description |
|
|
157
154
|
| :--- | :--- |
|
|
158
|
-
| `.dereference()` | Dereference the current operation. Note that this will ignore circular references. |
|
|
159
155
|
| `.getContentType()` | Retrieve the primary request body content type. If multiple are present, prefer whichever is JSON-compliant. |
|
|
160
156
|
| `.getDescription()` | Retrieve the `description` that's set on this operation. This supports common descriptions that may be set at the [path item level](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#path-item-object). |
|
|
161
157
|
| `.getOperationId()` | Retrieve the `operationId` that's present on the operation, and if one is not present one will be created based off the method + path and returned instead. |
|
|
162
158
|
| `.hasOperationId()` | Determine if the operation has an `operationId` present. |
|
|
163
|
-
| `.isDereferenced()` | Determine if the current operation schema has been dereferenced or not. |
|
|
164
159
|
| `.isDeprecated()` | Determine if this operation is marked as deprecated. |
|
|
165
160
|
| `.isFormUrlEncoded()` | Determine if this operation requires its payload to be delivered as `application/x-www-form-urlencoded`. |
|
|
166
161
|
| `.isJson()` | Determine if this operation requires its payload to be delivered as JSON. |
|
package/dist/analyzer/index.cjs
CHANGED
|
@@ -1,14 +1,79 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
var _chunkYKV73CBGcjs = require('../chunk-YKV73CBG.cjs');
|
|
4
|
-
require('../chunk-UDN4U5TL.cjs');
|
|
5
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
6
2
|
|
|
7
3
|
|
|
8
4
|
var _chunkW6GBV2JTcjs = require('../chunk-W6GBV2JT.cjs');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
require('
|
|
5
|
+
|
|
6
|
+
// src/analyzer/dereference.ts
|
|
7
|
+
var _openapiparser = require('@readme/openapi-parser');
|
|
8
|
+
function getDereferencingOptions(circularRefs2) {
|
|
9
|
+
return {
|
|
10
|
+
resolve: {
|
|
11
|
+
// We shouldn't be resolving external pointers at this point so just ignore them.
|
|
12
|
+
external: false
|
|
13
|
+
},
|
|
14
|
+
dereference: {
|
|
15
|
+
// If circular `$refs` are ignored they'll remain in the schema as `$ref: String`, otherwise
|
|
16
|
+
// `$ref` just won't exist. This, in tandem with `onCircular`, allows us to do easy and
|
|
17
|
+
// accumulate a list of circular references.
|
|
18
|
+
circular: "ignore",
|
|
19
|
+
onCircular: (path) => {
|
|
20
|
+
circularRefs2.add(`#${path.split("#")[1]}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
var dereferenceStates = /* @__PURE__ */ new WeakMap();
|
|
26
|
+
function getDereferenceState(definition) {
|
|
27
|
+
let state = dereferenceStates.get(definition);
|
|
28
|
+
if (!state) {
|
|
29
|
+
state = {
|
|
30
|
+
processing: false,
|
|
31
|
+
complete: false,
|
|
32
|
+
circularRefs: [],
|
|
33
|
+
promises: []
|
|
34
|
+
};
|
|
35
|
+
dereferenceStates.set(definition, state);
|
|
36
|
+
}
|
|
37
|
+
return state;
|
|
38
|
+
}
|
|
39
|
+
async function dereferenceOas(definition, opts) {
|
|
40
|
+
const state = getDereferenceState(definition);
|
|
41
|
+
if (state.complete && state.result) {
|
|
42
|
+
return state.result;
|
|
43
|
+
}
|
|
44
|
+
if (state.processing) {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
state.promises.push({ resolve, reject });
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
state.processing = true;
|
|
50
|
+
const circularRefs2 = /* @__PURE__ */ new Set();
|
|
51
|
+
const dereferencingOptions = getDereferencingOptions(circularRefs2);
|
|
52
|
+
const { promises } = state;
|
|
53
|
+
return _openapiparser.dereference.call(void 0, definition, dereferencingOptions).then((dereferenced) => {
|
|
54
|
+
const result = {
|
|
55
|
+
api: dereferenced,
|
|
56
|
+
circularRefs: [...circularRefs2]
|
|
57
|
+
};
|
|
58
|
+
state.result = result;
|
|
59
|
+
state.circularRefs = result.circularRefs;
|
|
60
|
+
state.processing = false;
|
|
61
|
+
state.complete = true;
|
|
62
|
+
if (_optionalChain([opts, 'optionalAccess', _ => _.cb])) {
|
|
63
|
+
opts.cb();
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}).then((result) => {
|
|
67
|
+
promises.forEach((deferred) => deferred.resolve(result));
|
|
68
|
+
state.promises = [];
|
|
69
|
+
return result;
|
|
70
|
+
}).catch((err) => {
|
|
71
|
+
state.processing = false;
|
|
72
|
+
promises.forEach((deferred) => deferred.reject(err));
|
|
73
|
+
state.promises = [];
|
|
74
|
+
throw err;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
12
77
|
|
|
13
78
|
// src/analyzer/queries/openapi.ts
|
|
14
79
|
function additionalProperties(definition) {
|
|
@@ -20,9 +85,8 @@ function callbacks(definition) {
|
|
|
20
85
|
);
|
|
21
86
|
}
|
|
22
87
|
async function circularRefs(definition) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const results = oas.getCircularReferences();
|
|
88
|
+
const { circularRefs: refs } = await dereferenceOas(structuredClone(definition));
|
|
89
|
+
const results = [...refs];
|
|
26
90
|
results.sort();
|
|
27
91
|
return results;
|
|
28
92
|
}
|
|
@@ -32,14 +96,12 @@ function commonParameters(definition) {
|
|
|
32
96
|
function discriminators(definition) {
|
|
33
97
|
return _chunkW6GBV2JTcjs.query.call(void 0, ["$..discriminator"], definition).map((res) => _chunkW6GBV2JTcjs.refizePointer.call(void 0, res.pointer));
|
|
34
98
|
}
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
const originalSizeInBytes = Buffer.from(JSON.stringify(oas.api)).length;
|
|
99
|
+
function fileSize(definition, definitionDereferenced) {
|
|
100
|
+
const originalSizeInBytes = Buffer.from(JSON.stringify(definition)).length;
|
|
38
101
|
const raw = Number((originalSizeInBytes / (1024 * 1024)).toFixed(2));
|
|
39
|
-
await oas.dereference();
|
|
40
102
|
let dereferenced;
|
|
41
103
|
try {
|
|
42
|
-
const dereferencedSizeInBytes = Buffer.from(JSON.stringify(
|
|
104
|
+
const dereferencedSizeInBytes = Buffer.from(JSON.stringify(definitionDereferenced)).length;
|
|
43
105
|
dereferenced = Number((dereferencedSizeInBytes / (1024 * 1024)).toFixed(2));
|
|
44
106
|
} catch (err) {
|
|
45
107
|
if (err instanceof RangeError) {
|
|
@@ -77,9 +139,6 @@ function polymorphism(definition) {
|
|
|
77
139
|
function references(definition) {
|
|
78
140
|
return _chunkW6GBV2JTcjs.query.call(void 0, ["$..$ref^"], definition).map((res) => _chunkW6GBV2JTcjs.refizePointer.call(void 0, res.pointer));
|
|
79
141
|
}
|
|
80
|
-
function refNames(definition) {
|
|
81
|
-
return _chunkW6GBV2JTcjs.query.call(void 0, ["$..['x-readme-ref-name']"], definition).map((res) => _chunkW6GBV2JTcjs.refizePointer.call(void 0, res.pointer));
|
|
82
|
-
}
|
|
83
142
|
function securityTypes(definition) {
|
|
84
143
|
return Array.from(new Set(_chunkW6GBV2JTcjs.query.call(void 0, ["$.components.securitySchemes..type"], definition).map((res) => res.value)));
|
|
85
144
|
}
|
|
@@ -126,17 +185,18 @@ function xmlSchemas(definition) {
|
|
|
126
185
|
|
|
127
186
|
// src/analyzer/index.ts
|
|
128
187
|
async function analyzer(definition) {
|
|
188
|
+
const clonedDefinition = structuredClone(definition);
|
|
189
|
+
const { api: dereferencedApi, circularRefs: dereferencedCircularRefs } = await dereferenceOas(clonedDefinition);
|
|
129
190
|
const additionalProperties2 = additionalProperties(definition);
|
|
130
191
|
const callbacks2 = callbacks(definition);
|
|
131
|
-
const circularRefs2 =
|
|
192
|
+
const circularRefs2 = [...dereferencedCircularRefs].toSorted();
|
|
132
193
|
const commonParameters2 = commonParameters(definition);
|
|
133
194
|
const discriminators2 = discriminators(definition);
|
|
134
|
-
const { raw: rawFileSize, dereferenced: dereferencedFileSize } =
|
|
195
|
+
const { raw: rawFileSize, dereferenced: dereferencedFileSize } = fileSize(definition, dereferencedApi);
|
|
135
196
|
const links2 = links(definition);
|
|
136
197
|
const parameterSerialization2 = parameterSerialization(definition);
|
|
137
198
|
const polymorphism2 = polymorphism(definition);
|
|
138
199
|
const references2 = references(definition);
|
|
139
|
-
const refNames2 = refNames(definition);
|
|
140
200
|
const serverVariables2 = serverVariables(definition);
|
|
141
201
|
const xmlSchemas2 = xmlSchemas(definition);
|
|
142
202
|
const xmlRequests2 = xmlRequests(definition);
|
|
@@ -202,10 +262,6 @@ async function analyzer(definition) {
|
|
|
202
262
|
present: !!references2.length,
|
|
203
263
|
locations: references2
|
|
204
264
|
},
|
|
205
|
-
refNames: {
|
|
206
|
-
present: !!refNames2.length,
|
|
207
|
-
locations: refNames2
|
|
208
|
-
},
|
|
209
265
|
serverVariables: {
|
|
210
266
|
present: !!serverVariables2.length,
|
|
211
267
|
locations: serverVariables2
|
|
@@ -250,6 +306,5 @@ async function analyzer(definition) {
|
|
|
250
306
|
|
|
251
307
|
|
|
252
308
|
|
|
253
|
-
|
|
254
|
-
exports.analyzeAdditionalProperties = additionalProperties; exports.analyzeCallbacks = callbacks; exports.analyzeCircularRefs = circularRefs; exports.analyzeCommonParameters = commonParameters; exports.analyzeDiscriminators = discriminators; exports.analyzeFileSize = fileSize; exports.analyzeLinks = links; exports.analyzeMediaTypes = mediaTypes; exports.analyzeParameterSerialization = parameterSerialization; exports.analyzePolymorphism = polymorphism; exports.analyzeRefNames = refNames; exports.analyzeReferences = references; exports.analyzeSecurityTypes = securityTypes; exports.analyzeServerVariables = serverVariables; exports.analyzeTotalOperations = totalOperations; exports.analyzeWebhooks = webhooks; exports.analyzeXMLRequests = xmlRequests; exports.analyzeXMLResponses = xmlResponses; exports.analyzeXMLSchemas = xmlSchemas; exports.analyzer = analyzer;
|
|
309
|
+
exports.analyzeAdditionalProperties = additionalProperties; exports.analyzeCallbacks = callbacks; exports.analyzeCircularRefs = circularRefs; exports.analyzeCommonParameters = commonParameters; exports.analyzeDiscriminators = discriminators; exports.analyzeFileSize = fileSize; exports.analyzeLinks = links; exports.analyzeMediaTypes = mediaTypes; exports.analyzeParameterSerialization = parameterSerialization; exports.analyzePolymorphism = polymorphism; exports.analyzeReferences = references; exports.analyzeSecurityTypes = securityTypes; exports.analyzeServerVariables = serverVariables; exports.analyzeTotalOperations = totalOperations; exports.analyzeWebhooks = webhooks; exports.analyzeXMLRequests = xmlRequests; exports.analyzeXMLResponses = xmlResponses; exports.analyzeXMLSchemas = xmlSchemas; exports.analyzer = analyzer;
|
|
255
310
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/analyzer/index.cjs","../../src/analyzer/queries/openapi.ts","../../src/analyzer/index.ts"],"names":["additionalProperties","callbacks","circularRefs","commonParameters","discriminators","links","parameterSerialization","polymorphism","references","refNames","serverVariables","xmlSchemas","xmlRequests","xmlResponses","webhooks"],"mappings":"AAAA;AACE;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B;AACA;ACDO,SAAS,oBAAA,CAAqB,UAAA,EAAmC;AACtE,EAAA,OAAO,qCAAA,CAAO,yBAAyB,CAAA,EAAG,UAAU,CAAA,CAAE,GAAA,CAAI,CAAA,GAAA,EAAA,GAAO,6CAAA,GAAc,CAAI,OAAO,CAAC,CAAA;AAC7F;AAQO,SAAS,SAAA,CAAU,UAAA,EAAmC;AAC3D,EAAA,OAAO,qCAAA,CAAO,wBAAA,EAA0B,qCAAqC,CAAA,EAAG,UAAU,CAAA,CAAE,GAAA;AAAA,IAAI,CAAA,GAAA,EAAA,GAC9F,6CAAA,GAAc,CAAI,OAAO;AAAA,EAC3B,CAAA;AACF;AAQA,MAAA,SAAsB,YAAA,CAAa,UAAA,EAA4C;AAG7E,EAAA,MAAM,IAAA,EAAM,IAAI,0BAAA,CAAI,eAAA,CAAgB,UAAU,CAAC,CAAA;AAC/C,EAAA,MAAM,G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,CAAC,CAACC,WAAAA,CAAW,MAAA;AAAA,QACtB,SAAA,EAAWA;AAAA,MACb,CAAA;AAAA,MACA,QAAA,EAAU;AAAA,QACR,OAAA,EAAS,CAAC,CAACC,SAAAA,CAAS,MAAA;AAAA,QACpB,SAAA,EAAWA;AAAA,MACb,CAAA;AAAA,MACA,eAAA,EAAiB;AAAA,QACf,OAAA,EAAS,CAAC,CAACC,gBAAAA,CAAgB,MAAA;AAAA,QAC3B,SAAA,EAAWA;AAAA,MACb,CAAA;AAAA,MACA,WAAA,EAAa;AAAA,QACX,OAAA,EAAS,CAAC,CAACE,YAAAA,CAAY,MAAA;AAAA,QACvB,SAAA,EAAWA;AAAA,MACb,CAAA;AAAA,MACA,YAAA,EAAc;AAAA,QACZ,OAAA,EAAS,CAAC,CAACC,aAAAA,CAAa,MAAA;AAAA,QACxB,SAAA,EAAWA;AAAA,MACb,CAAA;AAAA,MACA,UAAA,EAAY;AAAA,QACV,OAAA,EAAS,CAAC,CAACF,WAAAA,CAAW,MAAA;AAAA,QACtB,SAAA,EAAWA;AAAA,MACb,CAAA;AAAA,MACA,QAAA,EAAU;AAAA,QACR,OAAA,EAAS,CAAC,CAACG,SAAAA,CAAS,MAAA;AAAA,QACpB,SAAA,EAAWA;AAAA,MACb;AAAA,IACF;AAAA,EACF,CAAA;AAEA,EAAA,OAAO,QAAA;AACT;AF0EA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,o2BAAC","file":"/Users/erunion/code/readme/oas/packages/oas/dist/analyzer/index.cjs","sourcesContent":[null,"import type { OASDocument } from '../../types.js';\n\nimport Oas from '../../index.js';\nimport { query, refizePointer } from '../util.js';\n\n/**\n * Determine if a given API definition uses the `additionalProperties` schema property.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport function additionalProperties(definition: OASDocument): string[] {\n return query(['$..additionalProperties'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilizes `callbacks`.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object}\n */\nexport function callbacks(definition: OASDocument): string[] {\n return query(['$.components.callbacks', '$.paths.*[?(@.callbacks)].callbacks'], definition).map(res =>\n refizePointer(res.pointer),\n );\n}\n\n/**\n * Determine if a given API definition has circular refs.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport async function circularRefs(definition: OASDocument): Promise<string[]> {\n // Dereferencing will update the passed in variable, which we don't want to do, so we\n // instantiated `Oas` with a clone.\n const oas = new Oas(structuredClone(definition));\n await oas.dereference();\n\n const results = oas.getCircularReferences();\n\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition utilizes common parameters.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#path-item-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#path-item-object}\n */\nexport function commonParameters(definition: OASDocument): string[] {\n return query(['$..paths[*].parameters'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilizes discriminators.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminator-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#discriminator-object}\n */\nexport function discriminators(definition: OASDocument): string[] {\n return query(['$..discriminator'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Calculate the size of the raw and dereferenced OpenAPI file in MB.\n *\n * If a dereferenced API definition is too large to be stringified the file size will be returned\n * as NaN.\n *\n */\nexport async function fileSize(definition: OASDocument): Promise<{ raw: number; dereferenced: number | typeof NaN }> {\n const oas = new Oas(structuredClone(definition));\n\n const originalSizeInBytes = Buffer.from(JSON.stringify(oas.api)).length;\n const raw = Number((originalSizeInBytes / (1024 * 1024)).toFixed(2));\n\n await oas.dereference();\n\n let dereferenced: number;\n try {\n const dereferencedSizeInBytes = Buffer.from(JSON.stringify(oas.api)).length;\n dereferenced = Number((dereferencedSizeInBytes / (1024 * 1024)).toFixed(2));\n } catch (err) {\n // If the dereferenced API definition is too large to be stringified then we don't have a safer\n // way to estimate its size that wouldn't sacrifice accuracy so we'll just return NaN.\n if (err instanceof RangeError) {\n dereferenced = NaN;\n } else {\n throw err;\n }\n }\n\n return { raw, dereferenced };\n}\n\n/**\n * Determine if a given API definition utilizes `links`.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#link-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#link-object}\n */\nexport function links(definition: OASDocument): string[] {\n return query(['$.components.links', '$.paths..responses.*.links'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine all of the available media types used within an API definition.\n *\n * @todo This query currently picks up false positives if there is an object named `content`.\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#request-body-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#request-body-object}\n */\nexport function mediaTypes(definition: OASDocument): string[] {\n const results = Array.from(\n new Set(\n query(['$..paths..content'], definition).flatMap(res => {\n // This'll transform `results`, which looks like `[['application/json'], ['text/xml']]`\n // into `['application/json', 'text/xml']`.\n return Object.keys(res.value);\n }),\n ),\n );\n\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition uses parameter serialization.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object}\n */\nexport function parameterSerialization(definition: OASDocument): string[] {\n return query(['$..parameters[*].style^'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilizes schema polymorphism and/of interitance.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport function polymorphism(definition: OASDocument): string[] {\n const results = Array.from(\n new Set(query(['$..allOf^', '$..anyOf^', '$..oneOf^'], definition).map(res => refizePointer(res.pointer))),\n );\n\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition utilizes `$ref` pointers.\n *\n */\nexport function references(definition: OASDocument): string[] {\n return query(['$..$ref^'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition previously had references by checking if we added the\n * `x-readme-ref-name` extension after dereferencing. This extension is added only during the\n * dereferencing process.\n *\n */\nexport function refNames(definition: OASDocument): string[] {\n return query([\"$..['x-readme-ref-name']\"], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine every kind of security type that a given API definition has documented.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-scheme-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-scheme-object}\n */\nexport function securityTypes(definition: OASDocument): string[] {\n return Array.from(new Set(query(['$.components.securitySchemes..type'], definition).map(res => res.value as string)));\n}\n\n/**\n * Determine if a given API definition utilizes server variables.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#server-variable-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#server-variable-object}\n */\nexport function serverVariables(definition: OASDocument): string[] {\n return query(['$.servers..variables^'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine how many operations are defined in a given API definition.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operation-object}\n */\nexport function totalOperations(definition: OASDocument): number {\n return query(['$..paths[*]'], definition).flatMap(res => Object.keys(res.value)).length;\n}\n\n/**\n * Determine if a given API definition utilizes `webhooks` support in OpenAPI 3.1.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oasWebhooks}\n */\nexport function webhooks(definition: OASDocument): string[] {\n return query(['$.webhooks[*]'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition uses XML in a request body payload.\n *\n * @todo detect `+xml` media types\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\nexport function xmlRequests(definition: OASDocument): string[] {\n return query(\n [\n \"$..requestBody..['application/xml']\",\n \"$..requestBody..['application/xml-external-parsed-entity']\",\n \"$..requestBody..['application/xml-dtd']\",\n \"$..requestBody..['text/xml']\",\n \"$..requestBody..['text/xml-external-parsed-entity']\",\n '$..requestBody.content[?(@property.match(/\\\\+xml$/i))]',\n ],\n definition,\n ).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition uses XML in a response body.\n *\n * @todo detect `+xml` media types\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\nexport function xmlResponses(definition: OASDocument): string[] {\n return query(\n [\n \"$..responses..['application/xml']\",\n \"$..responses..['application/xml-external-parsed-entity']\",\n \"$..responses..['application/xml-dtd']\",\n \"$..responses..['text/xml']\",\n \"$..responses..['text/xml-external-parsed-entity']\",\n '$..responses[*].content[?(@property.match(/\\\\+xml$/i))]',\n ],\n definition,\n ).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilises the XML object for defining XML schemas.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#xml-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#xml-object}\n */\nexport function xmlSchemas(definition: OASDocument): string[] {\n return query(['$.components.schemas..xml^', '$..parameters..xml^', '$..requestBody..xml^'], definition).map(res =>\n refizePointer(res.pointer),\n );\n}\n","import type { OASDocument } from '../types.js';\nimport type { OASAnalysis } from './types.js';\n\nimport {\n additionalProperties as analyzeAdditionalProperties,\n callbacks as analyzeCallbacks,\n circularRefs as analyzeCircularRefs,\n commonParameters as analyzeCommonParameters,\n discriminators as analyzeDiscriminators,\n fileSize as analyzeFileSize,\n links as analyzeLinks,\n mediaTypes as analyzeMediaTypes,\n parameterSerialization as analyzeParameterSerialization,\n polymorphism as analyzePolymorphism,\n references as analyzeReferences,\n refNames as analyzeRefNames,\n securityTypes as analyzeSecurityTypes,\n serverVariables as analyzeServerVariables,\n totalOperations as analyzeTotalOperations,\n webhooks as analyzeWebhooks,\n xmlRequests as analyzeXMLRequests,\n xmlResponses as analyzeXMLResponses,\n xmlSchemas as analyzeXMLSchemas,\n} from './queries/openapi.js';\n\nexport {\n analyzeAdditionalProperties,\n analyzeCallbacks,\n analyzeCircularRefs,\n analyzeCommonParameters,\n analyzeDiscriminators,\n analyzeFileSize,\n analyzeLinks,\n analyzeMediaTypes,\n analyzeParameterSerialization,\n analyzePolymorphism,\n analyzeReferences,\n analyzeRefNames,\n analyzeSecurityTypes,\n analyzeServerVariables,\n analyzeTotalOperations,\n analyzeWebhooks,\n analyzeXMLRequests,\n analyzeXMLResponses,\n analyzeXMLSchemas,\n};\n\n/**\n * Analyze a given OpenAPI or Swagger definition for any OpenAPI or JSON Schema feature uses it\n * may contain or utilize.\n *\n */\nexport async function analyzer(definition: OASDocument): Promise<OASAnalysis> {\n const additionalProperties = analyzeAdditionalProperties(definition);\n const callbacks = analyzeCallbacks(definition);\n const circularRefs = await analyzeCircularRefs(definition);\n const commonParameters = analyzeCommonParameters(definition);\n const discriminators = analyzeDiscriminators(definition);\n const { raw: rawFileSize, dereferenced: dereferencedFileSize } = await analyzeFileSize(definition);\n const links = analyzeLinks(definition);\n const parameterSerialization = analyzeParameterSerialization(definition);\n const polymorphism = analyzePolymorphism(definition);\n const references = analyzeReferences(definition);\n const refNames = analyzeRefNames(definition);\n const serverVariables = analyzeServerVariables(definition);\n const xmlSchemas = analyzeXMLSchemas(definition);\n const xmlRequests = analyzeXMLRequests(definition);\n const xmlResponses = analyzeXMLResponses(definition);\n const webhooks = analyzeWebhooks(definition);\n\n const analysis: OASAnalysis = {\n general: {\n dereferencedFileSize: {\n name: 'Dereferenced File Size',\n found: dereferencedFileSize,\n },\n mediaTypes: {\n name: 'Media Type',\n found: analyzeMediaTypes(definition),\n },\n operationTotal: {\n name: 'Operation',\n found: analyzeTotalOperations(definition),\n },\n rawFileSize: {\n name: 'Raw File Size',\n found: rawFileSize,\n },\n securityTypes: {\n name: 'Security Type',\n found: analyzeSecurityTypes(definition),\n },\n },\n openapi: {\n additionalProperties: {\n present: !!additionalProperties.length,\n locations: additionalProperties,\n },\n callbacks: {\n present: !!callbacks.length,\n locations: callbacks,\n },\n circularRefs: {\n present: !!circularRefs.length,\n locations: circularRefs,\n },\n commonParameters: {\n present: !!commonParameters.length,\n locations: commonParameters,\n },\n discriminators: {\n present: !!discriminators.length,\n locations: discriminators,\n },\n links: {\n present: !!links.length,\n locations: links,\n },\n style: {\n present: !!parameterSerialization.length,\n locations: parameterSerialization,\n },\n polymorphism: {\n present: !!polymorphism.length,\n locations: polymorphism,\n },\n references: {\n present: !!references.length,\n locations: references,\n },\n refNames: {\n present: !!refNames.length,\n locations: refNames,\n },\n serverVariables: {\n present: !!serverVariables.length,\n locations: serverVariables,\n },\n xmlRequests: {\n present: !!xmlRequests.length,\n locations: xmlRequests,\n },\n xmlResponses: {\n present: !!xmlResponses.length,\n locations: xmlResponses,\n },\n xmlSchemas: {\n present: !!xmlSchemas.length,\n locations: xmlSchemas,\n },\n webhooks: {\n present: !!webhooks.length,\n locations: webhooks,\n },\n },\n };\n\n return analysis;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/analyzer/index.cjs","../../src/analyzer/dereference.ts","../../src/analyzer/queries/openapi.ts","../../src/analyzer/index.ts"],"names":["circularRefs","additionalProperties","callbacks","commonParameters","discriminators","links","parameterSerialization","polymorphism","references","serverVariables","xmlRequests","xmlResponses","xmlSchemas","webhooks"],"mappings":"AAAA;AACE;AACA;AACF,yDAA8B;AAC9B;AACA;ACFA,uDAA4B;AAM5B,SAAS,uBAAA,CAAwBA,aAAAA,EAA2E;AAC1G,EAAA,OAAO;AAAA,IACL,OAAA,EAAS;AAAA;AAAA,MAEP,QAAA,EAAU;AAAA,IACZ,CAAA;AAAA,IACA,WAAA,EAAa;AAAA;AAAA;AAAA;AAAA,MAIX,QAAA,EAAU,QAAA;AAAA,MAEV,UAAA,EAAY,CAAC,IAAA,EAAA,GAAiB;AAK5B,QAAAA,aAAAA,CAAa,GAAA,CAAI,CAAA,CAAA,EAAI,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAC,CAAA,CAAA;AACzC,MAAA;AACF,IAAA;AACF,EAAA;AACF;AAkB8B;AAE6C;AAC7B,EAAA;AAChC,EAAA;AACF,IAAA;AACM,MAAA;AACF,MAAA;AACK,MAAA;AACJ,MAAA;AACb,IAAA;AACuC,IAAA;AACzC,EAAA;AAEO,EAAA;AACT;AAkBiC;AACa,EAAA;AAER,EAAA;AACrB,IAAA;AACf,EAAA;AAEsB,EAAA;AACoB,IAAA;AACC,MAAA;AACxC,IAAA;AACH,EAAA;AAEmB,EAAA;AAEuB,EAAA;AACb,EAAA;AACR,EAAA;AAEuB,EAAA;AAEH,IAAA;AAC9B,MAAA;AAC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,EAAA;AAEO,EAAA;AACT;AHqIiD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/erunion/code/readme/oas/packages/oas/dist/analyzer/index.cjs","sourcesContent":[null,"import type { OASDocument } from '../types.js';\nimport type { ParserOptions } from '@readme/openapi-parser';\n\nimport { dereference } from '@readme/openapi-parser';\n\n/**\n * Retrive our dereferencing configuration for `@readme/openapi-parser`.\n *\n */\nfunction getDereferencingOptions(circularRefs: Set<string>): Pick<ParserOptions, 'resolve' | 'dereference'> {\n return {\n resolve: {\n // We shouldn't be resolving external pointers at this point so just ignore them.\n external: false,\n },\n dereference: {\n // If circular `$refs` are ignored they'll remain in the schema as `$ref: String`, otherwise\n // `$ref` just won't exist. This, in tandem with `onCircular`, allows us to do easy and\n // accumulate a list of circular references.\n circular: 'ignore',\n\n onCircular: (path: string) => {\n // The circular references that are coming out of `json-schema-ref-parser` are prefixed\n // with the schema path (file path, URL, whatever) that the schema exists in. Because we\n // don't care about this information for this reporting mechanism, and only the `$ref`\n // pointer, we're removing it.\n circularRefs.add(`#${path.split('#')[1]}`);\n },\n },\n };\n}\n\ninterface DereferenceOasResult {\n api: OASDocument;\n circularRefs: string[];\n}\n\ninterface DereferenceOasState {\n circularRefs: string[];\n complete: boolean;\n processing: boolean;\n promises: {\n reject: (err: unknown) => void;\n resolve: (result: DereferenceOasResult) => void;\n }[];\n result?: DereferenceOasResult;\n}\n\nconst dereferenceStates = new WeakMap<OASDocument, DereferenceOasState>();\n\nfunction getDereferenceState(definition: OASDocument): DereferenceOasState {\n let state = dereferenceStates.get(definition);\n if (!state) {\n state = {\n processing: false,\n complete: false,\n circularRefs: [],\n promises: [],\n };\n dereferenceStates.set(definition, state);\n }\n\n return state;\n}\n\n/**\n * Dereference a given OpenAPI definition so it can be parsed free from the hassle of resolving\n * `$ref` schemas and circular structures.\n *\n */\nexport async function dereferenceOas(\n definition: OASDocument,\n opts?: {\n /**\n * A callback method can be supplied to be called when dereferencing is complete. Used for\n * debugging that the multi-promise handling within this method works.\n *\n * @private\n */\n cb?: () => void;\n },\n): Promise<DereferenceOasResult> {\n const state = getDereferenceState(definition);\n\n if (state.complete && state.result) {\n return state.result;\n }\n\n if (state.processing) {\n return new Promise((resolve, reject) => {\n state.promises.push({ resolve, reject });\n });\n }\n\n state.processing = true;\n\n const circularRefs: Set<string> = new Set();\n const dereferencingOptions = getDereferencingOptions(circularRefs);\n const { promises } = state;\n\n return dereference<OASDocument>(definition, dereferencingOptions)\n .then((dereferenced: OASDocument) => {\n const result: DereferenceOasResult = {\n api: dereferenced,\n circularRefs: [...circularRefs],\n };\n\n state.result = result;\n state.circularRefs = result.circularRefs;\n state.processing = false;\n state.complete = true;\n\n // Used for debugging that dereferencing promise awaiting works.\n if (opts?.cb) {\n opts.cb();\n }\n\n return result;\n })\n .then(result => {\n promises.forEach(deferred => deferred.resolve(result));\n state.promises = [];\n return result;\n })\n .catch(err => {\n state.processing = false;\n promises.forEach(deferred => deferred.reject(err));\n state.promises = [];\n throw err;\n });\n}\n","import type { OASDocument } from '../../types.js';\n\nimport { dereferenceOas } from '../dereference.js';\nimport { query, refizePointer } from '../util.js';\n\n/**\n * Determine if a given API definition uses the `additionalProperties` schema property.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport function additionalProperties(definition: OASDocument): string[] {\n return query(['$..additionalProperties'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilizes `callbacks`.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object}\n */\nexport function callbacks(definition: OASDocument): string[] {\n return query(['$.components.callbacks', '$.paths.*[?(@.callbacks)].callbacks'], definition).map(res =>\n refizePointer(res.pointer),\n );\n}\n\n/**\n * Determine if a given API definition has circular refs.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport async function circularRefs(definition: OASDocument): Promise<string[]> {\n // Dereferencing will update the passed in variable, which we don't want to do, so we\n // instantiated `Oas` with a clone.\n const { circularRefs: refs } = await dereferenceOas(structuredClone(definition));\n\n const results = [...refs];\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition utilizes common parameters.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#path-item-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#path-item-object}\n */\nexport function commonParameters(definition: OASDocument): string[] {\n return query(['$..paths[*].parameters'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilizes discriminators.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminator-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#discriminator-object}\n */\nexport function discriminators(definition: OASDocument): string[] {\n return query(['$..discriminator'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Calculate the size of the raw and dereferenced OpenAPI file in MB.\n *\n * If a dereferenced API definition is too large to be stringified the file size will be returned\n * as NaN.\n *\n */\nexport function fileSize(\n definition: OASDocument,\n definitionDereferenced: OASDocument,\n): { raw: number; dereferenced: number | typeof NaN } {\n const originalSizeInBytes = Buffer.from(JSON.stringify(definition)).length;\n const raw = Number((originalSizeInBytes / (1024 * 1024)).toFixed(2));\n\n let dereferenced: number;\n try {\n const dereferencedSizeInBytes = Buffer.from(JSON.stringify(definitionDereferenced)).length;\n dereferenced = Number((dereferencedSizeInBytes / (1024 * 1024)).toFixed(2));\n } catch (err) {\n // If the dereferenced API definition is too large to be stringified then we don't have a safer\n // way to estimate its size that wouldn't sacrifice accuracy so we'll just return NaN.\n if (err instanceof RangeError) {\n dereferenced = NaN;\n } else {\n throw err;\n }\n }\n\n return { raw, dereferenced };\n}\n\n/**\n * Determine if a given API definition utilizes `links`.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#link-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#link-object}\n */\nexport function links(definition: OASDocument): string[] {\n return query(['$.components.links', '$.paths..responses.*.links'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine all of the available media types used within an API definition.\n *\n * @todo This query currently picks up false positives if there is an object named `content`.\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#request-body-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#request-body-object}\n */\nexport function mediaTypes(definition: OASDocument): string[] {\n const results = Array.from(\n new Set(\n query(['$..paths..content'], definition).flatMap(res => {\n // This'll transform `results`, which looks like `[['application/json'], ['text/xml']]`\n // into `['application/json', 'text/xml']`.\n return Object.keys(res.value);\n }),\n ),\n );\n\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition uses parameter serialization.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object}\n */\nexport function parameterSerialization(definition: OASDocument): string[] {\n return query(['$..parameters[*].style^'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilizes schema polymorphism and/of interitance.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport function polymorphism(definition: OASDocument): string[] {\n const results = Array.from(\n new Set(query(['$..allOf^', '$..anyOf^', '$..oneOf^'], definition).map(res => refizePointer(res.pointer))),\n );\n\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition utilizes `$ref` pointers.\n *\n */\nexport function references(definition: OASDocument): string[] {\n return query(['$..$ref^'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine every kind of security type that a given API definition has documented.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-scheme-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-scheme-object}\n */\nexport function securityTypes(definition: OASDocument): string[] {\n return Array.from(new Set(query(['$.components.securitySchemes..type'], definition).map(res => res.value as string)));\n}\n\n/**\n * Determine if a given API definition utilizes server variables.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#server-variable-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#server-variable-object}\n */\nexport function serverVariables(definition: OASDocument): string[] {\n return query(['$.servers..variables^'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine how many operations are defined in a given API definition.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operation-object}\n */\nexport function totalOperations(definition: OASDocument): number {\n return query(['$..paths[*]'], definition).flatMap(res => Object.keys(res.value)).length;\n}\n\n/**\n * Determine if a given API definition utilizes `webhooks` support in OpenAPI 3.1.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oasWebhooks}\n */\nexport function webhooks(definition: OASDocument): string[] {\n return query(['$.webhooks[*]'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition uses XML in a request body payload.\n *\n * @todo detect `+xml` media types\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\nexport function xmlRequests(definition: OASDocument): string[] {\n return query(\n [\n \"$..requestBody..['application/xml']\",\n \"$..requestBody..['application/xml-external-parsed-entity']\",\n \"$..requestBody..['application/xml-dtd']\",\n \"$..requestBody..['text/xml']\",\n \"$..requestBody..['text/xml-external-parsed-entity']\",\n '$..requestBody.content[?(@property.match(/\\\\+xml$/i))]',\n ],\n definition,\n ).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition uses XML in a response body.\n *\n * @todo detect `+xml` media types\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\nexport function xmlResponses(definition: OASDocument): string[] {\n return query(\n [\n \"$..responses..['application/xml']\",\n \"$..responses..['application/xml-external-parsed-entity']\",\n \"$..responses..['application/xml-dtd']\",\n \"$..responses..['text/xml']\",\n \"$..responses..['text/xml-external-parsed-entity']\",\n '$..responses[*].content[?(@property.match(/\\\\+xml$/i))]',\n ],\n definition,\n ).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilises the XML object for defining XML schemas.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#xml-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#xml-object}\n */\nexport function xmlSchemas(definition: OASDocument): string[] {\n return query(['$.components.schemas..xml^', '$..parameters..xml^', '$..requestBody..xml^'], definition).map(res =>\n refizePointer(res.pointer),\n );\n}\n","import type { OASDocument } from '../types.js';\nimport type { OASAnalysis } from './types.js';\n\nimport { dereferenceOas } from './dereference.js';\nimport {\n additionalProperties as analyzeAdditionalProperties,\n callbacks as analyzeCallbacks,\n circularRefs as analyzeCircularRefs,\n commonParameters as analyzeCommonParameters,\n discriminators as analyzeDiscriminators,\n fileSize as analyzeFileSize,\n links as analyzeLinks,\n mediaTypes as analyzeMediaTypes,\n parameterSerialization as analyzeParameterSerialization,\n polymorphism as analyzePolymorphism,\n references as analyzeReferences,\n securityTypes as analyzeSecurityTypes,\n serverVariables as analyzeServerVariables,\n totalOperations as analyzeTotalOperations,\n webhooks as analyzeWebhooks,\n xmlRequests as analyzeXMLRequests,\n xmlResponses as analyzeXMLResponses,\n xmlSchemas as analyzeXMLSchemas,\n} from './queries/openapi.js';\n\nexport {\n analyzeAdditionalProperties,\n analyzeCallbacks,\n analyzeCircularRefs,\n analyzeCommonParameters,\n analyzeDiscriminators,\n analyzeFileSize,\n analyzeLinks,\n analyzeMediaTypes,\n analyzeParameterSerialization,\n analyzePolymorphism,\n analyzeReferences,\n analyzeSecurityTypes,\n analyzeServerVariables,\n analyzeTotalOperations,\n analyzeWebhooks,\n analyzeXMLRequests,\n analyzeXMLResponses,\n analyzeXMLSchemas,\n};\n\n/**\n * Analyze a given OpenAPI or Swagger definition for any OpenAPI or JSON Schema feature uses it\n * may contain or utilize.\n *\n */\nexport async function analyzer(definition: OASDocument): Promise<OASAnalysis> {\n const clonedDefinition = structuredClone(definition);\n const { api: dereferencedApi, circularRefs: dereferencedCircularRefs } = await dereferenceOas(clonedDefinition);\n\n const additionalProperties = analyzeAdditionalProperties(definition);\n const callbacks = analyzeCallbacks(definition);\n const circularRefs = [...dereferencedCircularRefs].toSorted();\n const commonParameters = analyzeCommonParameters(definition);\n const discriminators = analyzeDiscriminators(definition);\n const { raw: rawFileSize, dereferenced: dereferencedFileSize } = analyzeFileSize(definition, dereferencedApi);\n const links = analyzeLinks(definition);\n const parameterSerialization = analyzeParameterSerialization(definition);\n const polymorphism = analyzePolymorphism(definition);\n const references = analyzeReferences(definition);\n const serverVariables = analyzeServerVariables(definition);\n const xmlSchemas = analyzeXMLSchemas(definition);\n const xmlRequests = analyzeXMLRequests(definition);\n const xmlResponses = analyzeXMLResponses(definition);\n const webhooks = analyzeWebhooks(definition);\n\n const analysis: OASAnalysis = {\n general: {\n dereferencedFileSize: {\n name: 'Dereferenced File Size',\n found: dereferencedFileSize,\n },\n mediaTypes: {\n name: 'Media Type',\n found: analyzeMediaTypes(definition),\n },\n operationTotal: {\n name: 'Operation',\n found: analyzeTotalOperations(definition),\n },\n rawFileSize: {\n name: 'Raw File Size',\n found: rawFileSize,\n },\n securityTypes: {\n name: 'Security Type',\n found: analyzeSecurityTypes(definition),\n },\n },\n openapi: {\n additionalProperties: {\n present: !!additionalProperties.length,\n locations: additionalProperties,\n },\n callbacks: {\n present: !!callbacks.length,\n locations: callbacks,\n },\n circularRefs: {\n present: !!circularRefs.length,\n locations: circularRefs,\n },\n commonParameters: {\n present: !!commonParameters.length,\n locations: commonParameters,\n },\n discriminators: {\n present: !!discriminators.length,\n locations: discriminators,\n },\n links: {\n present: !!links.length,\n locations: links,\n },\n style: {\n present: !!parameterSerialization.length,\n locations: parameterSerialization,\n },\n polymorphism: {\n present: !!polymorphism.length,\n locations: polymorphism,\n },\n references: {\n present: !!references.length,\n locations: references,\n },\n serverVariables: {\n present: !!serverVariables.length,\n locations: serverVariables,\n },\n xmlRequests: {\n present: !!xmlRequests.length,\n locations: xmlRequests,\n },\n xmlResponses: {\n present: !!xmlResponses.length,\n locations: xmlResponses,\n },\n xmlSchemas: {\n present: !!xmlSchemas.length,\n locations: xmlSchemas,\n },\n webhooks: {\n present: !!webhooks.length,\n locations: webhooks,\n },\n },\n };\n\n return analysis;\n}\n"]}
|
|
@@ -45,10 +45,10 @@ declare function discriminators(definition: OASDocument): string[];
|
|
|
45
45
|
* as NaN.
|
|
46
46
|
*
|
|
47
47
|
*/
|
|
48
|
-
declare function fileSize(definition: OASDocument):
|
|
48
|
+
declare function fileSize(definition: OASDocument, definitionDereferenced: OASDocument): {
|
|
49
49
|
raw: number;
|
|
50
50
|
dereferenced: number | typeof NaN;
|
|
51
|
-
}
|
|
51
|
+
};
|
|
52
52
|
/**
|
|
53
53
|
* Determine if a given API definition utilizes `links`.
|
|
54
54
|
*
|
|
@@ -83,13 +83,6 @@ declare function polymorphism(definition: OASDocument): string[];
|
|
|
83
83
|
*
|
|
84
84
|
*/
|
|
85
85
|
declare function references(definition: OASDocument): string[];
|
|
86
|
-
/**
|
|
87
|
-
* Determine if a given API definition previously had references by checking if we added the
|
|
88
|
-
* `x-readme-ref-name` extension after dereferencing. This extension is added only during the
|
|
89
|
-
* dereferencing process.
|
|
90
|
-
*
|
|
91
|
-
*/
|
|
92
|
-
declare function refNames(definition: OASDocument): string[];
|
|
93
86
|
/**
|
|
94
87
|
* Determine every kind of security type that a given API definition has documented.
|
|
95
88
|
*
|
|
@@ -148,4 +141,4 @@ declare function xmlSchemas(definition: OASDocument): string[];
|
|
|
148
141
|
*/
|
|
149
142
|
declare function analyzer(definition: OASDocument): Promise<OASAnalysis>;
|
|
150
143
|
|
|
151
|
-
export { additionalProperties as analyzeAdditionalProperties, callbacks as analyzeCallbacks, circularRefs as analyzeCircularRefs, commonParameters as analyzeCommonParameters, discriminators as analyzeDiscriminators, fileSize as analyzeFileSize, links as analyzeLinks, mediaTypes as analyzeMediaTypes, parameterSerialization as analyzeParameterSerialization, polymorphism as analyzePolymorphism,
|
|
144
|
+
export { additionalProperties as analyzeAdditionalProperties, callbacks as analyzeCallbacks, circularRefs as analyzeCircularRefs, commonParameters as analyzeCommonParameters, discriminators as analyzeDiscriminators, fileSize as analyzeFileSize, links as analyzeLinks, mediaTypes as analyzeMediaTypes, parameterSerialization as analyzeParameterSerialization, polymorphism as analyzePolymorphism, references as analyzeReferences, securityTypes as analyzeSecurityTypes, serverVariables as analyzeServerVariables, totalOperations as analyzeTotalOperations, webhooks as analyzeWebhooks, xmlRequests as analyzeXMLRequests, xmlResponses as analyzeXMLResponses, xmlSchemas as analyzeXMLSchemas, analyzer };
|
package/dist/analyzer/index.d.ts
CHANGED
|
@@ -45,10 +45,10 @@ declare function discriminators(definition: OASDocument): string[];
|
|
|
45
45
|
* as NaN.
|
|
46
46
|
*
|
|
47
47
|
*/
|
|
48
|
-
declare function fileSize(definition: OASDocument):
|
|
48
|
+
declare function fileSize(definition: OASDocument, definitionDereferenced: OASDocument): {
|
|
49
49
|
raw: number;
|
|
50
50
|
dereferenced: number | typeof NaN;
|
|
51
|
-
}
|
|
51
|
+
};
|
|
52
52
|
/**
|
|
53
53
|
* Determine if a given API definition utilizes `links`.
|
|
54
54
|
*
|
|
@@ -83,13 +83,6 @@ declare function polymorphism(definition: OASDocument): string[];
|
|
|
83
83
|
*
|
|
84
84
|
*/
|
|
85
85
|
declare function references(definition: OASDocument): string[];
|
|
86
|
-
/**
|
|
87
|
-
* Determine if a given API definition previously had references by checking if we added the
|
|
88
|
-
* `x-readme-ref-name` extension after dereferencing. This extension is added only during the
|
|
89
|
-
* dereferencing process.
|
|
90
|
-
*
|
|
91
|
-
*/
|
|
92
|
-
declare function refNames(definition: OASDocument): string[];
|
|
93
86
|
/**
|
|
94
87
|
* Determine every kind of security type that a given API definition has documented.
|
|
95
88
|
*
|
|
@@ -148,4 +141,4 @@ declare function xmlSchemas(definition: OASDocument): string[];
|
|
|
148
141
|
*/
|
|
149
142
|
declare function analyzer(definition: OASDocument): Promise<OASAnalysis>;
|
|
150
143
|
|
|
151
|
-
export { additionalProperties as analyzeAdditionalProperties, callbacks as analyzeCallbacks, circularRefs as analyzeCircularRefs, commonParameters as analyzeCommonParameters, discriminators as analyzeDiscriminators, fileSize as analyzeFileSize, links as analyzeLinks, mediaTypes as analyzeMediaTypes, parameterSerialization as analyzeParameterSerialization, polymorphism as analyzePolymorphism,
|
|
144
|
+
export { additionalProperties as analyzeAdditionalProperties, callbacks as analyzeCallbacks, circularRefs as analyzeCircularRefs, commonParameters as analyzeCommonParameters, discriminators as analyzeDiscriminators, fileSize as analyzeFileSize, links as analyzeLinks, mediaTypes as analyzeMediaTypes, parameterSerialization as analyzeParameterSerialization, polymorphism as analyzePolymorphism, references as analyzeReferences, securityTypes as analyzeSecurityTypes, serverVariables as analyzeServerVariables, totalOperations as analyzeTotalOperations, webhooks as analyzeWebhooks, xmlRequests as analyzeXMLRequests, xmlResponses as analyzeXMLResponses, xmlSchemas as analyzeXMLSchemas, analyzer };
|
package/dist/analyzer/index.js
CHANGED
|
@@ -1,14 +1,79 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Oas
|
|
3
|
-
} from "../chunk-IXQKQM3K.js";
|
|
4
|
-
import "../chunk-35LEYZEY.js";
|
|
5
1
|
import {
|
|
6
2
|
query,
|
|
7
3
|
refizePointer
|
|
8
4
|
} from "../chunk-CKC36IL7.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import "
|
|
5
|
+
|
|
6
|
+
// src/analyzer/dereference.ts
|
|
7
|
+
import { dereference } from "@readme/openapi-parser";
|
|
8
|
+
function getDereferencingOptions(circularRefs2) {
|
|
9
|
+
return {
|
|
10
|
+
resolve: {
|
|
11
|
+
// We shouldn't be resolving external pointers at this point so just ignore them.
|
|
12
|
+
external: false
|
|
13
|
+
},
|
|
14
|
+
dereference: {
|
|
15
|
+
// If circular `$refs` are ignored they'll remain in the schema as `$ref: String`, otherwise
|
|
16
|
+
// `$ref` just won't exist. This, in tandem with `onCircular`, allows us to do easy and
|
|
17
|
+
// accumulate a list of circular references.
|
|
18
|
+
circular: "ignore",
|
|
19
|
+
onCircular: (path) => {
|
|
20
|
+
circularRefs2.add(`#${path.split("#")[1]}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
var dereferenceStates = /* @__PURE__ */ new WeakMap();
|
|
26
|
+
function getDereferenceState(definition) {
|
|
27
|
+
let state = dereferenceStates.get(definition);
|
|
28
|
+
if (!state) {
|
|
29
|
+
state = {
|
|
30
|
+
processing: false,
|
|
31
|
+
complete: false,
|
|
32
|
+
circularRefs: [],
|
|
33
|
+
promises: []
|
|
34
|
+
};
|
|
35
|
+
dereferenceStates.set(definition, state);
|
|
36
|
+
}
|
|
37
|
+
return state;
|
|
38
|
+
}
|
|
39
|
+
async function dereferenceOas(definition, opts) {
|
|
40
|
+
const state = getDereferenceState(definition);
|
|
41
|
+
if (state.complete && state.result) {
|
|
42
|
+
return state.result;
|
|
43
|
+
}
|
|
44
|
+
if (state.processing) {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
state.promises.push({ resolve, reject });
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
state.processing = true;
|
|
50
|
+
const circularRefs2 = /* @__PURE__ */ new Set();
|
|
51
|
+
const dereferencingOptions = getDereferencingOptions(circularRefs2);
|
|
52
|
+
const { promises } = state;
|
|
53
|
+
return dereference(definition, dereferencingOptions).then((dereferenced) => {
|
|
54
|
+
const result = {
|
|
55
|
+
api: dereferenced,
|
|
56
|
+
circularRefs: [...circularRefs2]
|
|
57
|
+
};
|
|
58
|
+
state.result = result;
|
|
59
|
+
state.circularRefs = result.circularRefs;
|
|
60
|
+
state.processing = false;
|
|
61
|
+
state.complete = true;
|
|
62
|
+
if (opts?.cb) {
|
|
63
|
+
opts.cb();
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}).then((result) => {
|
|
67
|
+
promises.forEach((deferred) => deferred.resolve(result));
|
|
68
|
+
state.promises = [];
|
|
69
|
+
return result;
|
|
70
|
+
}).catch((err) => {
|
|
71
|
+
state.processing = false;
|
|
72
|
+
promises.forEach((deferred) => deferred.reject(err));
|
|
73
|
+
state.promises = [];
|
|
74
|
+
throw err;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
12
77
|
|
|
13
78
|
// src/analyzer/queries/openapi.ts
|
|
14
79
|
function additionalProperties(definition) {
|
|
@@ -20,9 +85,8 @@ function callbacks(definition) {
|
|
|
20
85
|
);
|
|
21
86
|
}
|
|
22
87
|
async function circularRefs(definition) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const results = oas.getCircularReferences();
|
|
88
|
+
const { circularRefs: refs } = await dereferenceOas(structuredClone(definition));
|
|
89
|
+
const results = [...refs];
|
|
26
90
|
results.sort();
|
|
27
91
|
return results;
|
|
28
92
|
}
|
|
@@ -32,14 +96,12 @@ function commonParameters(definition) {
|
|
|
32
96
|
function discriminators(definition) {
|
|
33
97
|
return query(["$..discriminator"], definition).map((res) => refizePointer(res.pointer));
|
|
34
98
|
}
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
const originalSizeInBytes = Buffer.from(JSON.stringify(oas.api)).length;
|
|
99
|
+
function fileSize(definition, definitionDereferenced) {
|
|
100
|
+
const originalSizeInBytes = Buffer.from(JSON.stringify(definition)).length;
|
|
38
101
|
const raw = Number((originalSizeInBytes / (1024 * 1024)).toFixed(2));
|
|
39
|
-
await oas.dereference();
|
|
40
102
|
let dereferenced;
|
|
41
103
|
try {
|
|
42
|
-
const dereferencedSizeInBytes = Buffer.from(JSON.stringify(
|
|
104
|
+
const dereferencedSizeInBytes = Buffer.from(JSON.stringify(definitionDereferenced)).length;
|
|
43
105
|
dereferenced = Number((dereferencedSizeInBytes / (1024 * 1024)).toFixed(2));
|
|
44
106
|
} catch (err) {
|
|
45
107
|
if (err instanceof RangeError) {
|
|
@@ -77,9 +139,6 @@ function polymorphism(definition) {
|
|
|
77
139
|
function references(definition) {
|
|
78
140
|
return query(["$..$ref^"], definition).map((res) => refizePointer(res.pointer));
|
|
79
141
|
}
|
|
80
|
-
function refNames(definition) {
|
|
81
|
-
return query(["$..['x-readme-ref-name']"], definition).map((res) => refizePointer(res.pointer));
|
|
82
|
-
}
|
|
83
142
|
function securityTypes(definition) {
|
|
84
143
|
return Array.from(new Set(query(["$.components.securitySchemes..type"], definition).map((res) => res.value)));
|
|
85
144
|
}
|
|
@@ -126,17 +185,18 @@ function xmlSchemas(definition) {
|
|
|
126
185
|
|
|
127
186
|
// src/analyzer/index.ts
|
|
128
187
|
async function analyzer(definition) {
|
|
188
|
+
const clonedDefinition = structuredClone(definition);
|
|
189
|
+
const { api: dereferencedApi, circularRefs: dereferencedCircularRefs } = await dereferenceOas(clonedDefinition);
|
|
129
190
|
const additionalProperties2 = additionalProperties(definition);
|
|
130
191
|
const callbacks2 = callbacks(definition);
|
|
131
|
-
const circularRefs2 =
|
|
192
|
+
const circularRefs2 = [...dereferencedCircularRefs].toSorted();
|
|
132
193
|
const commonParameters2 = commonParameters(definition);
|
|
133
194
|
const discriminators2 = discriminators(definition);
|
|
134
|
-
const { raw: rawFileSize, dereferenced: dereferencedFileSize } =
|
|
195
|
+
const { raw: rawFileSize, dereferenced: dereferencedFileSize } = fileSize(definition, dereferencedApi);
|
|
135
196
|
const links2 = links(definition);
|
|
136
197
|
const parameterSerialization2 = parameterSerialization(definition);
|
|
137
198
|
const polymorphism2 = polymorphism(definition);
|
|
138
199
|
const references2 = references(definition);
|
|
139
|
-
const refNames2 = refNames(definition);
|
|
140
200
|
const serverVariables2 = serverVariables(definition);
|
|
141
201
|
const xmlSchemas2 = xmlSchemas(definition);
|
|
142
202
|
const xmlRequests2 = xmlRequests(definition);
|
|
@@ -202,10 +262,6 @@ async function analyzer(definition) {
|
|
|
202
262
|
present: !!references2.length,
|
|
203
263
|
locations: references2
|
|
204
264
|
},
|
|
205
|
-
refNames: {
|
|
206
|
-
present: !!refNames2.length,
|
|
207
|
-
locations: refNames2
|
|
208
|
-
},
|
|
209
265
|
serverVariables: {
|
|
210
266
|
present: !!serverVariables2.length,
|
|
211
267
|
locations: serverVariables2
|
|
@@ -241,7 +297,6 @@ export {
|
|
|
241
297
|
mediaTypes as analyzeMediaTypes,
|
|
242
298
|
parameterSerialization as analyzeParameterSerialization,
|
|
243
299
|
polymorphism as analyzePolymorphism,
|
|
244
|
-
refNames as analyzeRefNames,
|
|
245
300
|
references as analyzeReferences,
|
|
246
301
|
securityTypes as analyzeSecurityTypes,
|
|
247
302
|
serverVariables as analyzeServerVariables,
|