oas 18.0.7 → 18.1.1

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 CHANGED
@@ -1,3 +1,23 @@
1
+ ## <small>18.1.1 (2022-04-06)</small>
2
+
3
+ * feat: `operation.getOperationId()` will now always return a "clean" operationID (#631) ([6c91fbd](https://github.com/readmeio/oas/commit/6c91fbd)), closes [#631](https://github.com/readmeio/oas/issues/631)
4
+ * test: adding tests for openapi 3.1 $ref and description handling ([ac64a4c](https://github.com/readmeio/oas/commit/ac64a4c))
5
+ * chore(deps): bump inquirer from 8.2.0 to 8.2.2 (#630) ([1802fd6](https://github.com/readmeio/oas/commit/1802fd6)), closes [#630](https://github.com/readmeio/oas/issues/630)
6
+
7
+
8
+
9
+ ## 18.1.0 (2022-03-31)
10
+
11
+ * feat: moving us over to our json-schema-ref-parser fork (#629) ([b986f35](https://github.com/readmeio/oas/commit/b986f35)), closes [#629](https://github.com/readmeio/oas/issues/629)
12
+
13
+
14
+
15
+ ## <small>18.0.8 (2022-03-29)</small>
16
+
17
+ * 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)
18
+
19
+
20
+
1
21
  ## <small>18.0.7 (2022-03-24)</small>
2
22
 
3
23
  * 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)
package/dist/index.js CHANGED
@@ -74,7 +74,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
74
74
  };
75
75
  exports.__esModule = true;
76
76
  exports.utils = exports.Webhook = exports.Callback = exports.Operation = void 0;
77
- var json_schema_ref_parser_1 = __importDefault(require("@apidevtools/json-schema-ref-parser"));
77
+ var json_schema_ref_parser_1 = __importDefault(require("@readme/json-schema-ref-parser"));
78
78
  var path_to_regexp_1 = require("path-to-regexp");
79
79
  var get_auth_1 = __importDefault(require("./lib/get-auth"));
80
80
  var get_user_variable_1 = __importDefault(require("./lib/get-user-variable"));
@@ -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 matchStatement = (0, path_to_regexp_1.match)(cleanedPath, { decode: decodeURIComponent });
201
- var matchResult = matchStatement(prunedPathName);
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
@@ -335,7 +335,13 @@ var Operation = /** @class */ (function () {
335
335
  return "".concat(method).concat(operationId);
336
336
  }
337
337
  else if (this.hasOperationId()) {
338
- return operationId;
338
+ // If we aren't creating a programming language-friendly accessor off this operationID we
339
+ // should still make sure that it doesn't have any weird characters that might throw off
340
+ // something like AJV when it's set as an `$id` property in a JSON Schema representation.
341
+ //
342
+ // And though `_` is non-alphanumeric it's okay in this because it's a neutral enough
343
+ // character we can use for delineation and it won't harm anything.
344
+ return operationId.replace(/[^a-zA-Z0-9_]/g, '_').replace(/__+/g, '_');
339
345
  }
340
346
  return "".concat(method, "_").concat(operationId);
341
347
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas",
3
- "version": "18.0.7",
3
+ "version": "18.1.1",
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)",
@@ -49,8 +49,8 @@
49
49
  "watch": "tsc --watch"
50
50
  },
51
51
  "dependencies": {
52
- "@apidevtools/json-schema-ref-parser": "^9.0.6",
53
- "@types/json-schema": "^7.0.9",
52
+ "@readme/json-schema-ref-parser": "^1.1.0",
53
+ "@types/json-schema": "^7.0.11",
54
54
  "cardinal": "^2.1.1",
55
55
  "chalk": "^4.1.2",
56
56
  "glob": "^7.1.2",
@@ -60,28 +60,27 @@
60
60
  "jsonpointer": "^5.0.0",
61
61
  "memoizee": "^0.4.14",
62
62
  "minimist": "^1.2.0",
63
- "oas-normalize": "^5.1.2",
63
+ "oas-normalize": "^5.2.0",
64
64
  "openapi-types": "^10.0.0",
65
65
  "path-to-regexp": "^6.2.0",
66
- "swagger-inline": "^5.1.0"
66
+ "swagger-inline": "^5.2.0"
67
67
  },
68
68
  "devDependencies": {
69
- "@commitlint/cli": "^16.0.1",
69
+ "@commitlint/cli": "^16.2.3",
70
70
  "@commitlint/config-conventional": "^16.0.0",
71
- "@readme/eslint-config": "^8.5.0",
72
- "@readme/oas-examples": "^4.3.2",
71
+ "@readme/eslint-config": "^8.5.1",
72
+ "@readme/oas-examples": "^5.0.0",
73
73
  "@readme/openapi-parser": "^2.0.4",
74
74
  "@types/jest": "^27.0.2",
75
75
  "@types/json-schema-merge-allof": "^0.6.1",
76
76
  "@types/memoizee": "^0.4.6",
77
77
  "alex": "^10.0.0",
78
- "eslint": "^8.6.0",
79
- "eslint-plugin-jsdoc": "^37.0.3",
78
+ "eslint": "^8.12.0",
80
79
  "husky": "^7.0.2",
81
80
  "jest": "^27.0.3",
82
- "prettier": "^2.5.1",
83
- "ts-jest": "^27.0.7",
84
- "typescript": "^4.4.4"
81
+ "prettier": "^2.6.1",
82
+ "ts-jest": "^27.1.4",
83
+ "typescript": "^4.6.3"
85
84
  },
86
85
  "prettier": "@readme/eslint-config/prettier",
87
86
  "commitlint": {
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@ import type * as RMOAS from './rmoas.types';
2
2
  import type { OpenAPIV3_1 } from 'openapi-types';
3
3
  import type { MatchResult } from 'path-to-regexp';
4
4
 
5
- import $RefParser from '@apidevtools/json-schema-ref-parser';
5
+ import $RefParser from '@readme/json-schema-ref-parser';
6
6
  import { pathToRegexp, match } from 'path-to-regexp';
7
7
  import getAuth from './lib/get-auth';
8
8
  import getUserVariable from './lib/get-user-variable';
@@ -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
- const matchStatement = match(cleanedPath, { decode: decodeURIComponent });
151
- const matchResult = matchStatement(prunedPathName);
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
@@ -365,7 +365,13 @@ export default class Operation {
365
365
  operationId = operationId.charAt(0).toUpperCase() + operationId.slice(1);
366
366
  return `${method}${operationId}`;
367
367
  } else if (this.hasOperationId()) {
368
- return operationId;
368
+ // If we aren't creating a programming language-friendly accessor off this operationID we
369
+ // should still make sure that it doesn't have any weird characters that might throw off
370
+ // something like AJV when it's set as an `$id` property in a JSON Schema representation.
371
+ //
372
+ // And though `_` is non-alphanumeric it's okay in this because it's a neutral enough
373
+ // character we can use for delineation and it won't harm anything.
374
+ return operationId.replace(/[^a-zA-Z0-9_]/g, '_').replace(/__+/g, '_');
369
375
  }
370
376
 
371
377
  return `${method}_${operationId}`;