oas 17.1.0 → 17.1.4

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.
@@ -17,7 +17,8 @@ declare type authKey = null | unknown | {
17
17
  * @param selectedApp The user app to retrieve an auth key for.
18
18
  * @returns The found auth key for this security scheme.
19
19
  */
20
- export declare function getByScheme(user: RMOAS.User, scheme?: RMOAS.KeyedSecuritySchemeObject, selectedApp?: string | number): authKey;
20
+ export declare function getByScheme(user: RMOAS.User, scheme?: RMOAS.KeyedSecuritySchemeObject, // eslint-disable-line default-param-last
21
+ selectedApp?: string | number): authKey;
21
22
  /**
22
23
  * Retrieve auth keys for an API definition from a given user for a specific "app" that they have configured.
23
24
  *
package/CHANGELOG.md CHANGED
@@ -1,3 +1,36 @@
1
+ ## <small>17.1.4 (2021-11-22)</small>
2
+
3
+ * fix: more protections for when `api` is undefined ([3d217a3](https://github.com/readmeio/oas/commit/3d217a3))
4
+
5
+
6
+
7
+ ## <small>17.1.3 (2021-11-20)</small>
8
+
9
+ * fix: don't fail to fetch an extension on an operation if there's no API definition ([08bc1d6](https://github.com/readmeio/oas/commit/08bc1d6))
10
+
11
+
12
+
13
+ ## <small>17.1.2 (2021-11-20)</small>
14
+
15
+ * fix: issue where searching for an extension in an empty Oas object would fail ([15c7b88](https://github.com/readmeio/oas/commit/15c7b88))
16
+ * fix: upgrading eslint to eslint 8 (#540) ([4d76f71](https://github.com/readmeio/oas/commit/4d76f71)), closes [#540](https://github.com/readmeio/oas/issues/540)
17
+
18
+
19
+
20
+ ## <small>17.1.1 (2021-11-13)</small>
21
+
22
+ * fix: adding error handling to `Oas.operation()` for undefined API definitions ([9c1e633](https://github.com/readmeio/oas/commit/9c1e633))
23
+ * docs: updating the changelog for the 14.9.0 release ([f7e7fd5](https://github.com/readmeio/oas/commit/f7e7fd5))
24
+ * chore: removing some eslint rule exclusions for things that aren't happening ([9c37a43](https://github.com/readmeio/oas/commit/9c37a43))
25
+
26
+
27
+
28
+ ## 14.9.0 (2021-11-09)
29
+
30
+ * feat: replaying callback work on top of the 14.8 release series ([930120d](https://github.com/readmeio/oas/commit/930120d))
31
+
32
+
33
+
1
34
  ## 17.1.0 (2021-11-07)
2
35
 
3
36
  * chore: jest config cleanup ([9396fad](https://github.com/readmeio/oas/commit/9396fad))
package/dist/index.js CHANGED
@@ -285,6 +285,7 @@ var Oas = /** @class */ (function () {
285
285
  Oas.prototype.getDefinition = function () {
286
286
  return this.api;
287
287
  };
288
+ // eslint-disable-next-line default-param-last
288
289
  Oas.prototype.url = function (selected, variables) {
289
290
  if (selected === void 0) { selected = 0; }
290
291
  var url = normalizedUrl(this.api, selected);
@@ -441,7 +442,7 @@ var Oas = /** @class */ (function () {
441
442
  * @returns The found Operation or Webhook.
442
443
  */
443
444
  Oas.prototype.operation = function (path, method, opts) {
444
- var _a;
445
+ var _a, _b, _c, _d;
445
446
  if (opts === void 0) { opts = {}; }
446
447
  // If we're unable to locate an operation for this path+method combination within the API definition, we should
447
448
  // still set an empty schema on the operation in the `Operation` class because if we don't trying to use any of the
@@ -457,7 +458,7 @@ var Oas = /** @class */ (function () {
457
458
  return new operation_1.Webhook(api, path, method, operation);
458
459
  }
459
460
  }
460
- if (this.api.paths && this.api.paths[path] && this.api.paths[path][method]) {
461
+ if ((_d = (_c = (_b = this === null || this === void 0 ? void 0 : this.api) === null || _b === void 0 ? void 0 : _b.paths) === null || _c === void 0 ? void 0 : _c[path]) === null || _d === void 0 ? void 0 : _d[method]) {
461
462
  operation = this.api.paths[path][method];
462
463
  }
463
464
  return new operation_1["default"](this.api, path, method, operation);
@@ -590,8 +591,8 @@ var Oas = /** @class */ (function () {
590
591
  * @returns Found auth keys for the found security schemes.
591
592
  */
592
593
  Oas.prototype.getAuth = function (user, selectedApp) {
593
- if (Object.keys(this.api.components || {}).length === 0 ||
594
- Object.keys(this.api.components.securitySchemes || {}).length === 0) {
594
+ var _a, _b;
595
+ if (!((_b = (_a = this.api) === null || _a === void 0 ? void 0 : _a.components) === null || _b === void 0 ? void 0 : _b.securitySchemes)) {
595
596
  return {};
596
597
  }
597
598
  return (0, get_auth_1["default"])(this.api, user, selectedApp);
@@ -680,7 +681,7 @@ var Oas = /** @class */ (function () {
680
681
  * @returns The extension exists.
681
682
  */
682
683
  Oas.prototype.hasExtension = function (extension) {
683
- return extension in this.api;
684
+ return Boolean(this.api && extension in this.api);
684
685
  };
685
686
  /**
686
687
  * Retrieve a custom specification extension off of the API definition.
@@ -706,7 +707,9 @@ var Oas = /** @class */ (function () {
706
707
  var _this = this;
707
708
  return __generator(this, function (_b) {
708
709
  if (this.dereferencing.complete) {
709
- return [2 /*return*/, new Promise(function (resolve) { return resolve(true); })];
710
+ return [2 /*return*/, new Promise(function (resolve) {
711
+ resolve(true);
712
+ })];
710
713
  }
711
714
  if (this.dereferencing.processing) {
712
715
  return [2 /*return*/, new Promise(function (resolve, reject) {
@@ -47,7 +47,8 @@ function getKey(user, scheme) {
47
47
  * @param selectedApp The user app to retrieve an auth key for.
48
48
  * @returns The found auth key for this security scheme.
49
49
  */
50
- function getByScheme(user, scheme, selectedApp) {
50
+ function getByScheme(user, scheme, // eslint-disable-line default-param-last
51
+ selectedApp) {
51
52
  if (scheme === void 0) { scheme = {}; }
52
53
  if (user === null || user === void 0 ? void 0 : user.keys) {
53
54
  if (selectedApp) {
@@ -67,7 +68,8 @@ exports.getByScheme = getByScheme;
67
68
  * @returns Found auth keys for the found security schemes.
68
69
  */
69
70
  function getAuth(api, user, selectedApp) {
70
- return Object.keys(api.components.securitySchemes)
71
+ var _a;
72
+ return Object.keys(((_a = api === null || api === void 0 ? void 0 : api.components) === null || _a === void 0 ? void 0 : _a.securitySchemes) || {})
71
73
  .map(function (scheme) {
72
74
  var _a;
73
75
  return _a = {},
@@ -13,7 +13,6 @@ var get_response_examples_1 = __importDefault(require("./get-response-examples")
13
13
  function getCallbackExamples(operation) {
14
14
  var ret = [];
15
15
  // spreads the contents of the map for each callback so there's not nested arrays returned
16
- // eslint-disable-next-line sonarjs/no-empty-collection
17
16
  return ret.concat.apply(ret, Object.keys(operation.callbacks || {}).map(function (identifier) {
18
17
  var callback = operation.callbacks[identifier];
19
18
  // spreads the contents again so there's not nested arrays returned
package/dist/operation.js CHANGED
@@ -84,7 +84,8 @@ var Operation = /** @class */ (function () {
84
84
  * @returns Array of security requirement objects.
85
85
  */
86
86
  Operation.prototype.getSecurity = function () {
87
- if (!('components' in this.api) || !('securitySchemes' in this.api.components)) {
87
+ var _a, _b;
88
+ if (!((_b = (_a = this.api) === null || _a === void 0 ? void 0 : _a.components) === null || _b === void 0 ? void 0 : _b.securitySchemes)) {
88
89
  return [];
89
90
  }
90
91
  return this.schema.security || this.api.security || [];
@@ -438,7 +439,7 @@ var Operation = /** @class */ (function () {
438
439
  * @returns The extension exists.
439
440
  */
440
441
  Operation.prototype.hasExtension = function (extension) {
441
- return extension in this.schema;
442
+ return Boolean(this.schema && extension in this.schema);
442
443
  };
443
444
  /**
444
445
  * Retrieve a custom specification extension off of the operation.
@@ -481,6 +482,3 @@ var Webhook = /** @class */ (function (_super) {
481
482
  return Webhook;
482
483
  }(Operation));
483
484
  exports.Webhook = Webhook;
484
- module.exports = Operation;
485
- module.exports.Callback = Callback;
486
- module.exports.Webhook = Webhook;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas",
3
- "version": "17.1.0",
3
+ "version": "17.1.4",
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)",
@@ -66,12 +66,12 @@
66
66
  "devDependencies": {
67
67
  "@commitlint/cli": "^14.1.0",
68
68
  "@commitlint/config-conventional": "^14.1.0",
69
- "@readme/eslint-config": "^7.2.2",
69
+ "@readme/eslint-config": "^8.0.2",
70
70
  "@readme/oas-examples": "^4.3.2",
71
71
  "@types/jest": "^27.0.2",
72
72
  "@types/json-schema-merge-allof": "^0.6.1",
73
73
  "@types/memoizee": "^0.4.6",
74
- "eslint": "^7.31.0",
74
+ "eslint": "^8.2.0",
75
75
  "eslint-plugin-jsdoc": "^37.0.3",
76
76
  "husky": "^7.0.2",
77
77
  "jest": "^27.0.3",
@@ -27,7 +27,6 @@ exports.run = function () {
27
27
 
28
28
  let cmdUsage;
29
29
  if (cmd.swagger) {
30
- // eslint-disable-next-line sonarjs/no-nested-template-literals
31
30
  cmdUsage = `${pad(`${action} [oas.json]`)} ${chalk.grey(desc)}`;
32
31
  cmdUsage = cmdUsage.replace(/\[oas\.json\]/, chalk.grey('[oas.json]'));
33
32
  } else {
package/src/index.ts CHANGED
@@ -287,6 +287,7 @@ export default class Oas {
287
287
  return this.api;
288
288
  }
289
289
 
290
+ // eslint-disable-next-line default-param-last
290
291
  url(selected = 0, variables?: Variables) {
291
292
  const url = normalizedUrl(this.api, selected);
292
293
  return this.replaceUrl(url, variables || this.variables(selected)).trim();
@@ -469,7 +470,7 @@ export default class Oas {
469
470
  }
470
471
  }
471
472
 
472
- if (this.api.paths && this.api.paths[path] && this.api.paths[path][method]) {
473
+ if (this?.api?.paths?.[path]?.[method]) {
473
474
  operation = this.api.paths[path][method];
474
475
  }
475
476
 
@@ -619,10 +620,7 @@ export default class Oas {
619
620
  * @returns Found auth keys for the found security schemes.
620
621
  */
621
622
  getAuth(user: RMOAS.User, selectedApp?: string | number) {
622
- if (
623
- Object.keys(this.api.components || {}).length === 0 ||
624
- Object.keys(this.api.components.securitySchemes || {}).length === 0
625
- ) {
623
+ if (!this.api?.components?.securitySchemes) {
626
624
  return {};
627
625
  }
628
626
 
@@ -719,7 +717,7 @@ export default class Oas {
719
717
  * @returns The extension exists.
720
718
  */
721
719
  hasExtension(extension: string) {
722
- return extension in this.api;
720
+ return Boolean(this.api && extension in this.api);
723
721
  }
724
722
 
725
723
  /**
@@ -742,7 +740,9 @@ export default class Oas {
742
740
  */
743
741
  async dereference() {
744
742
  if (this.dereferencing.complete) {
745
- return new Promise(resolve => resolve(true));
743
+ return new Promise(resolve => {
744
+ resolve(true);
745
+ });
746
746
  }
747
747
 
748
748
  if (this.dereferencing.processing) {
@@ -44,7 +44,7 @@ function getKey(user: RMOAS.User, scheme: RMOAS.KeyedSecuritySchemeObject): auth
44
44
  */
45
45
  export function getByScheme(
46
46
  user: RMOAS.User,
47
- scheme = <RMOAS.KeyedSecuritySchemeObject>{},
47
+ scheme = <RMOAS.KeyedSecuritySchemeObject>{}, // eslint-disable-line default-param-last
48
48
  selectedApp?: string | number
49
49
  ): authKey {
50
50
  if (user?.keys) {
@@ -74,7 +74,7 @@ export default function getAuth(
74
74
  user: RMOAS.User,
75
75
  selectedApp?: string | number
76
76
  ) {
77
- return Object.keys(api.components.securitySchemes)
77
+ return Object.keys(api?.components?.securitySchemes || {})
78
78
  .map(scheme => {
79
79
  return {
80
80
  [scheme]: getByScheme(
@@ -18,7 +18,6 @@ export default function getCallbackExamples(operation: RMOAS.OperationObject) {
18
18
  const ret: CallbackExamples = [];
19
19
 
20
20
  // spreads the contents of the map for each callback so there's not nested arrays returned
21
- // eslint-disable-next-line sonarjs/no-empty-collection
22
21
  return ret.concat(
23
22
  ...Object.keys(operation.callbacks || {}).map(identifier => {
24
23
  const callback = operation.callbacks[identifier] as RMOAS.CallbackObject;
package/src/operation.ts CHANGED
@@ -131,7 +131,7 @@ export default class Operation {
131
131
  * @returns Array of security requirement objects.
132
132
  */
133
133
  getSecurity() {
134
- if (!('components' in this.api) || !('securitySchemes' in this.api.components)) {
134
+ if (!this.api?.components?.securitySchemes) {
135
135
  return [];
136
136
  }
137
137
 
@@ -524,7 +524,7 @@ export default class Operation {
524
524
  * @returns The extension exists.
525
525
  */
526
526
  hasExtension(extension: string) {
527
- return extension in this.schema;
527
+ return Boolean(this.schema && extension in this.schema);
528
528
  }
529
529
 
530
530
  /**
@@ -566,7 +566,3 @@ export class Callback extends Operation {
566
566
  }
567
567
 
568
568
  export class Webhook extends Operation {}
569
-
570
- module.exports = Operation;
571
- module.exports.Callback = Callback;
572
- module.exports.Webhook = Webhook;
@@ -1,5 +1,5 @@
1
1
  import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
2
- import type { JSONSchema4, JSONSchema6, JSONSchema7 } from 'json-schema'; // eslint-disable-line import/no-unresolved
2
+ import type { JSONSchema4, JSONSchema6, JSONSchema7 } from 'json-schema';
3
3
 
4
4
  /**
5
5
  * @param check Data to determine if it contains a ReferenceObject (`$ref` pointer`).