oas 20.0.1 → 20.1.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +8 -4
  3. package/dist/analyzer/index.d.ts +53 -0
  4. package/dist/analyzer/index.js +200 -0
  5. package/dist/analyzer/queries/openapi.d.ts +94 -0
  6. package/dist/analyzer/queries/openapi.js +222 -0
  7. package/dist/analyzer/queries/readme.d.ts +56 -0
  8. package/dist/analyzer/queries/readme.js +112 -0
  9. package/dist/analyzer/util.d.ts +16 -0
  10. package/dist/analyzer/util.js +28 -0
  11. package/dist/index.d.ts +4 -4
  12. package/dist/index.js +1 -1
  13. package/dist/lib/get-auth.d.ts +1 -1
  14. package/dist/lib/get-mediatype-examples.d.ts +2 -2
  15. package/dist/lib/openapi-to-json-schema.d.ts +3 -3
  16. package/dist/operation/get-callback-examples.d.ts +1 -1
  17. package/dist/operation/get-parameters-as-json-schema.d.ts +2 -2
  18. package/dist/operation/get-requestbody-examples.d.ts +1 -1
  19. package/dist/operation/get-response-examples.d.ts +1 -1
  20. package/dist/operation.d.ts +1 -1
  21. package/dist/operation.js +20 -8
  22. package/dist/{lib/reducer.d.ts → reducer/index.d.ts} +2 -2
  23. package/dist/{lib/reducer.js → reducer/index.js} +8 -7
  24. package/dist/rmoas.types.d.ts +26 -26
  25. package/package.json +16 -17
  26. package/src/analyzer/index.ts +185 -0
  27. package/src/analyzer/queries/openapi.ts +193 -0
  28. package/src/analyzer/queries/readme.ts +133 -0
  29. package/src/analyzer/util.ts +36 -0
  30. package/src/index.ts +2 -2
  31. package/src/lib/get-mediatype-examples.ts +2 -2
  32. package/src/lib/openapi-to-json-schema.ts +2 -2
  33. package/src/operation/get-parameters-as-json-schema.ts +2 -2
  34. package/src/operation.ts +16 -8
  35. package/src/{lib/reducer.ts → reducer/index.ts} +10 -10
  36. package/src/rmoas.types.ts +2 -2
package/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 20.1.0 (2022-12-05)
2
+
3
+ * feat: new OpenAPI definition analyzer library (#722) ([5e0d563](https://github.com/readmeio/oas/commit/5e0d563)), closes [#722](https://github.com/readmeio/oas/issues/722)
4
+ * docs: adding a ReadMe badge to the readme (#720) ([919a887](https://github.com/readmeio/oas/commit/919a887)), closes [#720](https://github.com/readmeio/oas/issues/720)
5
+ * fix: keywords in package.json ([568e068](https://github.com/readmeio/oas/commit/568e068))
6
+ * fix: reversing the logic order for common summary+descriptions (#721) ([c7d0015](https://github.com/readmeio/oas/commit/c7d0015)), closes [#721](https://github.com/readmeio/oas/issues/721)
7
+ * chore: swapping out common param tests with a better spec ([ef54f63](https://github.com/readmeio/oas/commit/ef54f63))
8
+ * chore: update out of date dependencies (#719) ([23632ba](https://github.com/readmeio/oas/commit/23632ba)), closes [#719](https://github.com/readmeio/oas/issues/719)
9
+
10
+
11
+
1
12
  ## <small>20.0.1 (2022-11-01)</small>
2
13
 
3
14
  * fix: issue with non-camelCase operationID generation (#708) ([7af590c](https://github.com/readmeio/oas/commit/7af590c)), closes [#708](https://github.com/readmeio/oas/issues/708)
package/README.md CHANGED
@@ -9,10 +9,14 @@
9
9
  </p>
10
10
 
11
11
  <p align="center">
12
- <a href="https://npm.im/oas"><img src="https://img.shields.io/npm/v/oas.svg?style=for-the-badge" alt="NPM Version"></a>
13
- <a href="https://npm.im/oas"><img src="https://img.shields.io/node/v/oas.svg?style=for-the-badge" alt="Node Version"></a>
14
- <a href="https://npm.im/oas"><img src="https://img.shields.io/npm/l/oas.svg?style=for-the-badge" alt="MIT License"></a>
15
- <a href="https://github.com/readmeio/oas"><img src="https://img.shields.io/github/workflow/status/readmeio/oas/CI.svg?style=for-the-badge" alt="Build status"></a>
12
+ <a href="https://npm.im/oas"><img src="https://img.shields.io/npm/v/oas.svg?style=for-the-badge" alt="NPM Version" /></a>
13
+ <a href="https://npm.im/oas"><img src="https://img.shields.io/node/v/oas.svg?style=for-the-badge" alt="Node Version" /></a>
14
+ <a href="https://npm.im/oas"><img src="https://img.shields.io/npm/l/oas.svg?style=for-the-badge" alt="MIT License" /></a>
15
+ <a href="https://github.com/readmeio/oas"><img src="https://img.shields.io/github/workflow/status/readmeio/oas/CI.svg?style=for-the-badge" alt="Build status" /></a>
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="https://readme.com"><img src="https://raw.githubusercontent.com/readmeio/.github/main/oss-badge.svg" /></a>
16
20
  </p>
17
21
 
18
22
  `oas` is the library that we've built at [ReadMe](https://readme.com) for powering everything we do related to [OpenAPI](https://www.openapis.org/); from our [Reference Guides](https://readme.com/documentation), to our [Metrics product](https://readme.com/metrics) or to other in-house tooling like [code generation](https://npm.im/@readme/oas-to-snippet), [request execution](https://npm.im/@readme/oas-to-har), and [SDK code generation](https://api.readme.dev/).
@@ -0,0 +1,53 @@
1
+ import type { OASDocument } from '../rmoas.types';
2
+ interface OASAnalysisFeature {
3
+ present: boolean;
4
+ locations: number | string[];
5
+ }
6
+ interface OASAnalysisGeneral {
7
+ name: string;
8
+ found: number | string[];
9
+ }
10
+ export interface OASAnalysis {
11
+ general: {
12
+ mediaTypes: OASAnalysisGeneral;
13
+ operationTotal: OASAnalysisGeneral;
14
+ securityTypes: OASAnalysisGeneral;
15
+ };
16
+ openapi: {
17
+ additionalProperties: OASAnalysisFeature;
18
+ callbacks: OASAnalysisFeature;
19
+ circularRefs: OASAnalysisFeature;
20
+ discriminators: OASAnalysisFeature;
21
+ links: OASAnalysisFeature;
22
+ style: OASAnalysisFeature;
23
+ polymorphism: OASAnalysisFeature;
24
+ serverVariables: OASAnalysisFeature;
25
+ webhooks: OASAnalysisFeature;
26
+ xml: OASAnalysisFeature;
27
+ };
28
+ readme: {
29
+ 'x-default': OASAnalysisFeature;
30
+ 'x-readme.headers': OASAnalysisFeature;
31
+ 'x-readme.proxy-enabled': OASAnalysisFeature;
32
+ 'x-readme.samples-languages'?: OASAnalysisFeature;
33
+ 'x-readme.code-samples': OASAnalysisFeature;
34
+ 'x-readme.explorer-enabled': OASAnalysisFeature;
35
+ /**
36
+ * This extension is deprecated.
37
+ */
38
+ 'x-readme.samples-enabled'?: OASAnalysisFeature;
39
+ /**
40
+ * RAW_BODY is specific to our Manual API editor and we don't recommend anyone writing their
41
+ * own API definition should use it so this is considered deprecated.
42
+ */
43
+ raw_body?: OASAnalysisFeature;
44
+ };
45
+ }
46
+ /**
47
+ * Analyze a given OpenAPI or Swagger definition for any OpenAPI, JSON Schema, and ReadMe-specific
48
+ * feature uses it may contain.
49
+ *
50
+ * @todo this might be worth moving into the `oas` package at some point
51
+ */
52
+ export default function analyzer(definition: OASDocument): Promise<OASAnalysis>;
53
+ export {};
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ exports.__esModule = true;
62
+ var OPENAPI_QUERIES = __importStar(require("./queries/openapi"));
63
+ var README_QUERIES = __importStar(require("./queries/readme"));
64
+ /**
65
+ * Analyze a given OpenAPI or Swagger definition for any OpenAPI, JSON Schema, and ReadMe-specific
66
+ * feature uses it may contain.
67
+ *
68
+ * @todo this might be worth moving into the `oas` package at some point
69
+ */
70
+ function analyzer(definition) {
71
+ return __awaiter(this, void 0, void 0, function () {
72
+ var additionalProperties, callbacks, circularRefs, discriminators, links, parameterSerialization, polymorphism, serverVariables, webhooks, xml, authDefaults, codeSampleLanguages, customCodeSamples, codeSamplesDisabled, disabledCorsProxy, explorerDisabled, staticHeaders, rawBody, analysis;
73
+ return __generator(this, function (_a) {
74
+ switch (_a.label) {
75
+ case 0:
76
+ additionalProperties = OPENAPI_QUERIES.additionalProperties(definition);
77
+ callbacks = OPENAPI_QUERIES.callbacks(definition);
78
+ return [4 /*yield*/, OPENAPI_QUERIES.circularRefs(definition)];
79
+ case 1:
80
+ circularRefs = _a.sent();
81
+ discriminators = OPENAPI_QUERIES.discriminators(definition);
82
+ links = OPENAPI_QUERIES.links(definition);
83
+ parameterSerialization = OPENAPI_QUERIES.parameterSerialization(definition);
84
+ polymorphism = OPENAPI_QUERIES.polymorphism(definition);
85
+ serverVariables = OPENAPI_QUERIES.serverVariables(definition);
86
+ webhooks = OPENAPI_QUERIES.webhooks(definition);
87
+ xml = OPENAPI_QUERIES.xml(definition);
88
+ authDefaults = README_QUERIES.authDefaults(definition);
89
+ codeSampleLanguages = README_QUERIES.codeSampleLanguages(definition);
90
+ customCodeSamples = README_QUERIES.customCodeSamples(definition);
91
+ codeSamplesDisabled = README_QUERIES.codeSamplesDisabled(definition);
92
+ disabledCorsProxy = README_QUERIES.corsProxyDisabled(definition);
93
+ explorerDisabled = README_QUERIES.explorerDisabled(definition);
94
+ staticHeaders = README_QUERIES.staticHeaders(definition);
95
+ rawBody = README_QUERIES.rawBody(definition);
96
+ analysis = {
97
+ general: {
98
+ mediaTypes: {
99
+ name: 'Media Type',
100
+ found: OPENAPI_QUERIES.mediaTypes(definition)
101
+ },
102
+ operationTotal: {
103
+ name: 'Operation',
104
+ found: OPENAPI_QUERIES.totalOperations(definition)
105
+ },
106
+ securityTypes: {
107
+ name: 'Security Type',
108
+ found: OPENAPI_QUERIES.securityTypes(definition)
109
+ }
110
+ },
111
+ openapi: {
112
+ additionalProperties: {
113
+ present: !!additionalProperties.length,
114
+ locations: additionalProperties
115
+ },
116
+ callbacks: {
117
+ present: !!callbacks.length,
118
+ locations: callbacks
119
+ },
120
+ circularRefs: {
121
+ present: !!circularRefs.length,
122
+ locations: circularRefs
123
+ },
124
+ discriminators: {
125
+ present: !!discriminators.length,
126
+ locations: discriminators
127
+ },
128
+ links: {
129
+ present: !!links.length,
130
+ locations: links
131
+ },
132
+ style: {
133
+ present: !!parameterSerialization.length,
134
+ locations: parameterSerialization
135
+ },
136
+ polymorphism: {
137
+ present: !!polymorphism.length,
138
+ locations: polymorphism
139
+ },
140
+ serverVariables: {
141
+ present: !!serverVariables.length,
142
+ locations: serverVariables
143
+ },
144
+ webhooks: {
145
+ present: !!webhooks.length,
146
+ locations: webhooks
147
+ },
148
+ xml: {
149
+ present: !!xml.length,
150
+ locations: xml
151
+ }
152
+ },
153
+ readme: {
154
+ 'x-default': {
155
+ present: !!authDefaults.length,
156
+ locations: authDefaults
157
+ },
158
+ 'x-readme.code-samples': {
159
+ present: !!customCodeSamples.length,
160
+ locations: customCodeSamples
161
+ },
162
+ 'x-readme.headers': {
163
+ present: !!staticHeaders.length,
164
+ locations: staticHeaders
165
+ },
166
+ 'x-readme.explorer-enabled': {
167
+ present: !!explorerDisabled.length,
168
+ locations: explorerDisabled
169
+ },
170
+ 'x-readme.proxy-enabled': {
171
+ present: !!disabledCorsProxy.length,
172
+ locations: disabledCorsProxy
173
+ },
174
+ 'x-readme.samples-languages': {
175
+ present: !!codeSampleLanguages.length,
176
+ locations: codeSampleLanguages
177
+ }
178
+ }
179
+ };
180
+ // We should only surface analysis for deprecated features and extensions if they have them as
181
+ // there's no reason to give them information about something they can't use and should no longer
182
+ // know about.
183
+ if (codeSamplesDisabled.length) {
184
+ analysis.readme['x-readme.samples-enabled'] = {
185
+ present: !!codeSamplesDisabled.length,
186
+ locations: codeSamplesDisabled
187
+ };
188
+ }
189
+ if (rawBody.length) {
190
+ analysis.readme.raw_body = {
191
+ present: !!rawBody.length,
192
+ locations: rawBody
193
+ };
194
+ }
195
+ return [2 /*return*/, analysis];
196
+ }
197
+ });
198
+ });
199
+ }
200
+ exports["default"] = analyzer;
@@ -0,0 +1,94 @@
1
+ import type { OASDocument } from '../../rmoas.types';
2
+ /**
3
+ * Determine if a given API definition uses the `additionalProperties` schema property.
4
+ *
5
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}
6
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}
7
+ */
8
+ export declare function additionalProperties(definition: OASDocument): string[];
9
+ /**
10
+ * Determine if a given API definition utilizes `callbacks`.
11
+ *
12
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callbackObject}
13
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callbackObject}
14
+ */
15
+ export declare function callbacks(definition: OASDocument): string[];
16
+ /**
17
+ * Determine if a given API definition has circular refs.
18
+ *
19
+ * @todo improve the accuracy of this query
20
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}
21
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}
22
+ */
23
+ export declare function circularRefs(definition: OASDocument): Promise<string[]>;
24
+ /**
25
+ * Determine if a given API definition utilizes discriminators.
26
+ *
27
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminatorObject}
28
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#discriminatorObject}
29
+ */
30
+ export declare function discriminators(definition: OASDocument): string[];
31
+ /**
32
+ * Determine if a given API definition utilizes `links`.
33
+ *
34
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#linkObject}
35
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#linkObject}
36
+ */
37
+ export declare function links(definition: OASDocument): string[];
38
+ /**
39
+ * Determine all of the available media types used within an API definition.
40
+ *
41
+ * @todo This query currently picks up false positives if there is an object named `content`.
42
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#request-body-object}
43
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#request-body-object}
44
+ */
45
+ export declare function mediaTypes(definition: OASDocument): string[];
46
+ /**
47
+ * Determine if a given API definition uses parameter serialization.
48
+ *
49
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object}
50
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object}
51
+ */
52
+ export declare function parameterSerialization(definition: OASDocument): string[];
53
+ /**
54
+ * Determine if a given API definition utilizes schema polymorphism and/of interitance.
55
+ *
56
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}
57
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}
58
+ */
59
+ export declare function polymorphism(definition: OASDocument): string[];
60
+ /**
61
+ * Determine every kind of security type that a given API definition has documented.
62
+ *
63
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#securitySchemeObject}
64
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securitySchemeObject}
65
+ */
66
+ export declare function securityTypes(definition: OASDocument): string[];
67
+ /**
68
+ * Determine if a given API definition utilizes server variables.
69
+ *
70
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverVariableObject}
71
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverVariableObject}
72
+ */
73
+ export declare function serverVariables(definition: OASDocument): string[];
74
+ /**
75
+ * Determine how many operations are defined in a given API definition.
76
+ *
77
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operationObject}
78
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject}
79
+ */
80
+ export declare function totalOperations(definition: OASDocument): number;
81
+ /**
82
+ * Determine if a given API definition utilizes `webhooks` support in OpenAPI 3.1.
83
+ *
84
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oasObject}
85
+ */
86
+ export declare function webhooks(definition: OASDocument): string[];
87
+ /**
88
+ * Determine if a given API definition has XML schemas, payloads, or responses.
89
+ *
90
+ * @todo detect `+xml` media types
91
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#xmlObject}
92
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#xmlObject}
93
+ */
94
+ export declare function xml(definition: OASDocument): string[];
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ exports.__esModule = true;
42
+ exports.xml = exports.webhooks = exports.totalOperations = exports.serverVariables = exports.securityTypes = exports.polymorphism = exports.parameterSerialization = exports.mediaTypes = exports.links = exports.discriminators = exports.circularRefs = exports.callbacks = exports.additionalProperties = void 0;
43
+ var __1 = __importDefault(require("../.."));
44
+ var util_1 = require("../util");
45
+ /**
46
+ * Determine if a given API definition uses the `additionalProperties` schema property.
47
+ *
48
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}
49
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}
50
+ */
51
+ function additionalProperties(definition) {
52
+ return (0, util_1.query)(['$..additionalProperties'], definition).map(function (res) { return res.pointer; });
53
+ }
54
+ exports.additionalProperties = additionalProperties;
55
+ /**
56
+ * Determine if a given API definition utilizes `callbacks`.
57
+ *
58
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callbackObject}
59
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callbackObject}
60
+ */
61
+ function callbacks(definition) {
62
+ return (0, util_1.query)(['$.components.callbacks', '$.paths..callbacks'], definition).map(function (res) { return res.pointer; });
63
+ }
64
+ exports.callbacks = callbacks;
65
+ /**
66
+ * Determine if a given API definition has circular refs.
67
+ *
68
+ * @todo improve the accuracy of this query
69
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}
70
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}
71
+ */
72
+ function circularRefs(definition) {
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ var oas, results;
75
+ return __generator(this, function (_a) {
76
+ switch (_a.label) {
77
+ case 0:
78
+ oas = new __1["default"](JSON.parse(JSON.stringify(definition)));
79
+ // Dereferencing will update the passed in variable, which we don't want to do, so we
80
+ // instantiated `Oas` with a clone.
81
+ return [4 /*yield*/, oas.dereference()];
82
+ case 1:
83
+ // Dereferencing will update the passed in variable, which we don't want to do, so we
84
+ // instantiated `Oas` with a clone.
85
+ _a.sent();
86
+ results = Array.from(new Set((0, util_1.query)(['$..$ref'], oas.api).map(function (res) { return res.value; })));
87
+ results.sort();
88
+ return [2 /*return*/, results];
89
+ }
90
+ });
91
+ });
92
+ }
93
+ exports.circularRefs = circularRefs;
94
+ /**
95
+ * Determine if a given API definition utilizes discriminators.
96
+ *
97
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminatorObject}
98
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#discriminatorObject}
99
+ */
100
+ function discriminators(definition) {
101
+ return (0, util_1.query)(['$..discriminator'], definition).map(function (res) { return res.pointer; });
102
+ }
103
+ exports.discriminators = discriminators;
104
+ /**
105
+ * Determine if a given API definition utilizes `links`.
106
+ *
107
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#linkObject}
108
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#linkObject}
109
+ */
110
+ function links(definition) {
111
+ return (0, util_1.query)(['$..links'], definition).map(function (res) { return res.pointer; });
112
+ }
113
+ exports.links = links;
114
+ /**
115
+ * Determine all of the available media types used within an API definition.
116
+ *
117
+ * @todo This query currently picks up false positives if there is an object named `content`.
118
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#request-body-object}
119
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#request-body-object}
120
+ */
121
+ function mediaTypes(definition) {
122
+ var results = Array.from(new Set((0, util_1.query)(['$..paths..content'], definition)
123
+ .map(function (res) {
124
+ // This'll transform `results`, which looks like `[['application/json'], ['text/xml']]`
125
+ // into `['application/json', 'text/xml']`.
126
+ return Object.keys(res.value);
127
+ })
128
+ .flat()));
129
+ results.sort();
130
+ return results;
131
+ }
132
+ exports.mediaTypes = mediaTypes;
133
+ /**
134
+ * Determine if a given API definition uses parameter serialization.
135
+ *
136
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object}
137
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object}
138
+ */
139
+ function parameterSerialization(definition) {
140
+ return (0, util_1.query)(['$..parameters[*].style^'], definition).map(function (res) { return res.pointer; });
141
+ }
142
+ exports.parameterSerialization = parameterSerialization;
143
+ /**
144
+ * Determine if a given API definition utilizes schema polymorphism and/of interitance.
145
+ *
146
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}
147
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}
148
+ */
149
+ function polymorphism(definition) {
150
+ var results = Array.from(new Set((0, util_1.query)(['$..allOf^', '$..anyOf^', '$..oneOf^'], definition).map(function (res) { return res.pointer; })));
151
+ results.sort();
152
+ return results;
153
+ }
154
+ exports.polymorphism = polymorphism;
155
+ /**
156
+ * Determine every kind of security type that a given API definition has documented.
157
+ *
158
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#securitySchemeObject}
159
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securitySchemeObject}
160
+ */
161
+ function securityTypes(definition) {
162
+ return Array.from(new Set((0, util_1.query)(['$.components.securitySchemes..type'], definition).map(function (res) { return res.value; })));
163
+ }
164
+ exports.securityTypes = securityTypes;
165
+ /**
166
+ * Determine if a given API definition utilizes server variables.
167
+ *
168
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverVariableObject}
169
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverVariableObject}
170
+ */
171
+ function serverVariables(definition) {
172
+ return (0, util_1.query)(['$.servers..variables^'], definition).map(function (res) { return res.pointer; });
173
+ }
174
+ exports.serverVariables = serverVariables;
175
+ /**
176
+ * Determine how many operations are defined in a given API definition.
177
+ *
178
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operationObject}
179
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject}
180
+ */
181
+ function totalOperations(definition) {
182
+ return (0, util_1.query)(['$..paths[*]'], definition)
183
+ .map(function (res) { return Object.keys(res.value); })
184
+ .flat().length;
185
+ }
186
+ exports.totalOperations = totalOperations;
187
+ /**
188
+ * Determine if a given API definition utilizes `webhooks` support in OpenAPI 3.1.
189
+ *
190
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oasObject}
191
+ */
192
+ function webhooks(definition) {
193
+ return (0, util_1.query)(['$.webhooks[*]'], definition).map(function (res) { return res.pointer; });
194
+ }
195
+ exports.webhooks = webhooks;
196
+ /**
197
+ * Determine if a given API definition has XML schemas, payloads, or responses.
198
+ *
199
+ * @todo detect `+xml` media types
200
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#xmlObject}
201
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#xmlObject}
202
+ */
203
+ function xml(definition) {
204
+ return (0, util_1.query)([
205
+ '$.components.schemas..xml^',
206
+ '$..parameters..xml^',
207
+ '$..requestBody..xml^',
208
+ "$..requestBody..['application/xml']",
209
+ "$..requestBody..['application/xml-external-parsed-entity']",
210
+ "$..requestBody..['application/xml-dtd']",
211
+ "$..requestBody..['text/xml']",
212
+ "$..requestBody..['text/xml-external-parsed-entity']",
213
+ '$..requestBody.content[?(@property.match(/\\+xml$/i))]',
214
+ "$..responses..['application/xml']",
215
+ "$..responses..['application/xml-external-parsed-entity']",
216
+ "$..responses..['application/xml-dtd']",
217
+ "$..responses..['text/xml']",
218
+ "$..responses..['text/xml-external-parsed-entity']",
219
+ '$..responses[*].content[?(@property.match(/\\+xml$/i))]',
220
+ ], definition).map(function (res) { return res.pointer; });
221
+ }
222
+ exports.xml = xml;