oas 18.0.5 → 18.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/index.js +12 -2
- package/dist/operation.js +33 -9
- package/package.json +2 -1
- package/src/index.ts +13 -2
- package/src/operation.ts +24 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
## <small>18.0.8 (2022-03-29)</small>
|
|
2
|
+
|
|
3
|
+
* fix: improved error handling on `Oas.findOperation()` calls (#628) ([22198dd](https://github.com/readmeio/oas/commit/22198dd)), closes [#628](https://github.com/readmeio/oas/issues/628)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## <small>18.0.7 (2022-03-24)</small>
|
|
8
|
+
|
|
9
|
+
* fix: getSecurity() should return an empty array for an empty securitySchemes object (#626) ([f96bee1](https://github.com/readmeio/oas/commit/f96bee1)), closes [#626](https://github.com/readmeio/oas/issues/626)
|
|
10
|
+
* fix: issue where a securityScheme may be corrupted with internal library data (#627) ([666ba9f](https://github.com/readmeio/oas/commit/666ba9f)), closes [#627](https://github.com/readmeio/oas/issues/627)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## <small>18.0.6 (2022-03-21)</small>
|
|
15
|
+
|
|
16
|
+
* feat: `camelCase` opt on `getOperationId()` should clean IDs if present (#625) ([6ab85df](https://github.com/readmeio/oas/commit/6ab85df)), closes [#625](https://github.com/readmeio/oas/issues/625)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
1
20
|
## <small>18.0.5 (2022-03-21)</small>
|
|
2
21
|
|
|
3
22
|
* fix: `operation.hasOperationId` should return false for an empty string (#624) ([bc23a43](https://github.com/readmeio/oas/commit/bc23a43)), closes [#624](https://github.com/readmeio/oas/issues/624)
|
package/dist/index.js
CHANGED
|
@@ -197,14 +197,23 @@ function generatePathMatches(paths, pathName, origin) {
|
|
|
197
197
|
return Object.keys(paths)
|
|
198
198
|
.map(function (path) {
|
|
199
199
|
var cleanedPath = normalizePath(path);
|
|
200
|
-
var
|
|
201
|
-
|
|
200
|
+
var matchResult;
|
|
201
|
+
try {
|
|
202
|
+
var matchStatement = (0, path_to_regexp_1.match)(cleanedPath, { decode: decodeURIComponent });
|
|
203
|
+
matchResult = matchStatement(prunedPathName);
|
|
204
|
+
}
|
|
205
|
+
catch (err) {
|
|
206
|
+
// If path matching fails for whatever reason (maybe they have a malformed path parameter)
|
|
207
|
+
// then we shouldn't also fail.
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
202
210
|
var slugs = {};
|
|
203
211
|
if (matchResult && Object.keys(matchResult.params).length) {
|
|
204
212
|
Object.keys(matchResult.params).forEach(function (param) {
|
|
205
213
|
slugs[":".concat(param)] = matchResult.params[param];
|
|
206
214
|
});
|
|
207
215
|
}
|
|
216
|
+
// eslint-disable-next-line consistent-return
|
|
208
217
|
return {
|
|
209
218
|
url: {
|
|
210
219
|
origin: origin,
|
|
@@ -216,6 +225,7 @@ function generatePathMatches(paths, pathName, origin) {
|
|
|
216
225
|
match: matchResult
|
|
217
226
|
};
|
|
218
227
|
})
|
|
228
|
+
.filter(Boolean)
|
|
219
229
|
.filter(function (p) { return p.match; });
|
|
220
230
|
}
|
|
221
231
|
/**
|
package/dist/operation.js
CHANGED
|
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
17
28
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
29
|
if (k2 === undefined) k2 = k;
|
|
19
30
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -122,7 +133,7 @@ var Operation = /** @class */ (function () {
|
|
|
122
133
|
*/
|
|
123
134
|
Operation.prototype.getSecurity = function () {
|
|
124
135
|
var _a, _b;
|
|
125
|
-
if (!((_b = (_a = this.api) === null || _a === void 0 ? void 0 : _a.components) === null || _b === void 0 ? void 0 : _b.securitySchemes)) {
|
|
136
|
+
if (!((_b = (_a = this.api) === null || _a === void 0 ? void 0 : _a.components) === null || _b === void 0 ? void 0 : _b.securitySchemes) || !Object.keys(this.api.components.securitySchemes).length) {
|
|
126
137
|
return [];
|
|
127
138
|
}
|
|
128
139
|
return this.schema.security || this.api.security || [];
|
|
@@ -185,8 +196,10 @@ var Operation = /** @class */ (function () {
|
|
|
185
196
|
else {
|
|
186
197
|
return false;
|
|
187
198
|
}
|
|
188
|
-
|
|
189
|
-
|
|
199
|
+
return {
|
|
200
|
+
type: type,
|
|
201
|
+
security: __assign(__assign({}, security), { _key: key })
|
|
202
|
+
};
|
|
190
203
|
});
|
|
191
204
|
if (filterInvalid)
|
|
192
205
|
return keysWithTypes.filter(function (key) { return key !== false; });
|
|
@@ -294,15 +307,18 @@ var Operation = /** @class */ (function () {
|
|
|
294
307
|
* @param opts.camelCase Generate a JS method-friendly operation ID when one isn't present.
|
|
295
308
|
*/
|
|
296
309
|
Operation.prototype.getOperationId = function (opts) {
|
|
310
|
+
var operationId;
|
|
297
311
|
if (this.hasOperationId()) {
|
|
298
|
-
|
|
312
|
+
operationId = this.schema.operationId;
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
operationId = this.path
|
|
316
|
+
.replace(/[^a-zA-Z0-9]/g, '-') // Remove weird characters
|
|
317
|
+
.replace(/^-|-$/g, '') // Don't start or end with -
|
|
318
|
+
.replace(/--+/g, '-') // Remove double --'s
|
|
319
|
+
.toLowerCase();
|
|
299
320
|
}
|
|
300
321
|
var method = this.method.toLowerCase();
|
|
301
|
-
var operationId = this.path
|
|
302
|
-
.replace(/[^a-zA-Z0-9]/g, '-') // Remove weird characters
|
|
303
|
-
.replace(/^-|-$/g, '') // Don't start or end with -
|
|
304
|
-
.replace(/--+/g, '-') // Remove double --'s
|
|
305
|
-
.toLowerCase();
|
|
306
322
|
if (opts === null || opts === void 0 ? void 0 : opts.camelCase) {
|
|
307
323
|
operationId = operationId.replace(/[^a-zA-Z0-9]+(.)/g, function (_, chr) { return chr.toUpperCase(); });
|
|
308
324
|
// If the generated `operationId` already starts with the method (eg. `getPets`) we don't want
|
|
@@ -310,9 +326,17 @@ var Operation = /** @class */ (function () {
|
|
|
310
326
|
if (operationId.startsWith(method)) {
|
|
311
327
|
return operationId;
|
|
312
328
|
}
|
|
329
|
+
// If this operation already has an operationId and we just cleaned it up then we shouldn't
|
|
330
|
+
// prefix it with an HTTP method.
|
|
331
|
+
if (this.hasOperationId()) {
|
|
332
|
+
return operationId;
|
|
333
|
+
}
|
|
313
334
|
operationId = operationId.charAt(0).toUpperCase() + operationId.slice(1);
|
|
314
335
|
return "".concat(method).concat(operationId);
|
|
315
336
|
}
|
|
337
|
+
else if (this.hasOperationId()) {
|
|
338
|
+
return operationId;
|
|
339
|
+
}
|
|
316
340
|
return "".concat(method, "_").concat(operationId);
|
|
317
341
|
};
|
|
318
342
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oas",
|
|
3
|
-
"version": "18.0.
|
|
3
|
+
"version": "18.0.8",
|
|
4
4
|
"description": "Working with OpenAPI definitions is hard. This makes it easier.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ReadMe <support@readme.io> (https://readme.com)",
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"@commitlint/config-conventional": "^16.0.0",
|
|
71
71
|
"@readme/eslint-config": "^8.5.0",
|
|
72
72
|
"@readme/oas-examples": "^4.3.2",
|
|
73
|
+
"@readme/openapi-parser": "^2.0.4",
|
|
73
74
|
"@types/jest": "^27.0.2",
|
|
74
75
|
"@types/json-schema-merge-allof": "^0.6.1",
|
|
75
76
|
"@types/memoizee": "^0.4.6",
|
package/src/index.ts
CHANGED
|
@@ -147,8 +147,17 @@ function generatePathMatches(paths: RMOAS.PathsObject, pathName: string, origin:
|
|
|
147
147
|
return Object.keys(paths)
|
|
148
148
|
.map(path => {
|
|
149
149
|
const cleanedPath = normalizePath(path);
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
|
|
151
|
+
let matchResult: MatchResult;
|
|
152
|
+
try {
|
|
153
|
+
const matchStatement = match(cleanedPath, { decode: decodeURIComponent });
|
|
154
|
+
matchResult = matchStatement(prunedPathName) as MatchResult;
|
|
155
|
+
} catch (err) {
|
|
156
|
+
// If path matching fails for whatever reason (maybe they have a malformed path parameter)
|
|
157
|
+
// then we shouldn't also fail.
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
152
161
|
const slugs: Record<string, string> = {};
|
|
153
162
|
|
|
154
163
|
if (matchResult && Object.keys(matchResult.params).length) {
|
|
@@ -157,6 +166,7 @@ function generatePathMatches(paths: RMOAS.PathsObject, pathName: string, origin:
|
|
|
157
166
|
});
|
|
158
167
|
}
|
|
159
168
|
|
|
169
|
+
// eslint-disable-next-line consistent-return
|
|
160
170
|
return {
|
|
161
171
|
url: {
|
|
162
172
|
origin,
|
|
@@ -168,6 +178,7 @@ function generatePathMatches(paths: RMOAS.PathsObject, pathName: string, origin:
|
|
|
168
178
|
match: matchResult,
|
|
169
179
|
};
|
|
170
180
|
})
|
|
181
|
+
.filter(Boolean)
|
|
171
182
|
.filter(p => p.match) as PathMatches;
|
|
172
183
|
}
|
|
173
184
|
|
package/src/operation.ts
CHANGED
|
@@ -146,7 +146,7 @@ export default class Operation {
|
|
|
146
146
|
*
|
|
147
147
|
*/
|
|
148
148
|
getSecurity(): RMOAS.SecurityRequirementObject[] {
|
|
149
|
-
if (!this.api?.components?.securitySchemes) {
|
|
149
|
+
if (!this.api?.components?.securitySchemes || !Object.keys(this.api.components.securitySchemes).length) {
|
|
150
150
|
return [];
|
|
151
151
|
}
|
|
152
152
|
|
|
@@ -204,9 +204,13 @@ export default class Operation {
|
|
|
204
204
|
return false;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
207
|
+
return {
|
|
208
|
+
type,
|
|
209
|
+
security: {
|
|
210
|
+
...security,
|
|
211
|
+
_key: key,
|
|
212
|
+
},
|
|
213
|
+
};
|
|
210
214
|
});
|
|
211
215
|
|
|
212
216
|
if (filterInvalid) return keysWithTypes.filter(key => key !== false);
|
|
@@ -331,17 +335,18 @@ export default class Operation {
|
|
|
331
335
|
* @param opts.camelCase Generate a JS method-friendly operation ID when one isn't present.
|
|
332
336
|
*/
|
|
333
337
|
getOperationId(opts?: { camelCase: boolean }): string {
|
|
338
|
+
let operationId;
|
|
334
339
|
if (this.hasOperationId()) {
|
|
335
|
-
|
|
340
|
+
operationId = this.schema.operationId;
|
|
341
|
+
} else {
|
|
342
|
+
operationId = this.path
|
|
343
|
+
.replace(/[^a-zA-Z0-9]/g, '-') // Remove weird characters
|
|
344
|
+
.replace(/^-|-$/g, '') // Don't start or end with -
|
|
345
|
+
.replace(/--+/g, '-') // Remove double --'s
|
|
346
|
+
.toLowerCase();
|
|
336
347
|
}
|
|
337
348
|
|
|
338
349
|
const method = this.method.toLowerCase();
|
|
339
|
-
let operationId = this.path
|
|
340
|
-
.replace(/[^a-zA-Z0-9]/g, '-') // Remove weird characters
|
|
341
|
-
.replace(/^-|-$/g, '') // Don't start or end with -
|
|
342
|
-
.replace(/--+/g, '-') // Remove double --'s
|
|
343
|
-
.toLowerCase();
|
|
344
|
-
|
|
345
350
|
if (opts?.camelCase) {
|
|
346
351
|
operationId = operationId.replace(/[^a-zA-Z0-9]+(.)/g, (_, chr) => chr.toUpperCase());
|
|
347
352
|
|
|
@@ -351,8 +356,16 @@ export default class Operation {
|
|
|
351
356
|
return operationId;
|
|
352
357
|
}
|
|
353
358
|
|
|
359
|
+
// If this operation already has an operationId and we just cleaned it up then we shouldn't
|
|
360
|
+
// prefix it with an HTTP method.
|
|
361
|
+
if (this.hasOperationId()) {
|
|
362
|
+
return operationId;
|
|
363
|
+
}
|
|
364
|
+
|
|
354
365
|
operationId = operationId.charAt(0).toUpperCase() + operationId.slice(1);
|
|
355
366
|
return `${method}${operationId}`;
|
|
367
|
+
} else if (this.hasOperationId()) {
|
|
368
|
+
return operationId;
|
|
356
369
|
}
|
|
357
370
|
|
|
358
371
|
return `${method}_${operationId}`;
|