oas 17.1.3 → 17.2.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.
@@ -1,4 +1,4 @@
1
- declare function _exports(path: string, operation: any, api: any, globalDefaults?: Object): any;
1
+ declare function _exports(path: string, operation: Operation, api: OpenAPI.Document, globalDefaults?: Object): array<object>;
2
2
  declare namespace _exports {
3
3
  export { types };
4
4
  }
@@ -119,7 +119,7 @@ export default class Operation {
119
119
  * @param globalDefaults An object of global defaults to apply as a `default` in the returned JSON Schema.
120
120
  * @returns An array of JSON Schema objects.
121
121
  */
122
- getParametersAsJsonSchema(globalDefaults?: unknown): any;
122
+ getParametersAsJsonSchema(globalDefaults?: unknown): array<object>;
123
123
  /**
124
124
  * Get a single response for this status code, formatted as JSON schema.
125
125
  *
package/CHANGELOG.md CHANGED
@@ -1,3 +1,42 @@
1
+ ## 17.2.0 (2021-12-02)
2
+
3
+ * chore(deps-dev): bump @commitlint/cli from 14.1.0 to 15.0.0 (#552) ([b03dbd3](https://github.com/readmeio/oas/commit/b03dbd3)), closes [#552](https://github.com/readmeio/oas/issues/552)
4
+ * chore(deps-dev): bump @commitlint/config-conventional (#547) ([6b1c0b7](https://github.com/readmeio/oas/commit/6b1c0b7)), closes [#547](https://github.com/readmeio/oas/issues/547)
5
+ * chore(deps-dev): bump @types/jest from 27.0.2 to 27.0.3 (#549) ([6356929](https://github.com/readmeio/oas/commit/6356929)), closes [#549](https://github.com/readmeio/oas/issues/549)
6
+ * chore(deps-dev): bump eslint from 8.2.0 to 8.3.0 (#553) ([8d945f6](https://github.com/readmeio/oas/commit/8d945f6)), closes [#553](https://github.com/readmeio/oas/issues/553)
7
+ * chore(deps-dev): bump eslint-plugin-jsdoc from 37.0.3 to 37.1.0 (#554) ([f7567a1](https://github.com/readmeio/oas/commit/f7567a1)), closes [#554](https://github.com/readmeio/oas/issues/554)
8
+ * chore(deps-dev): bump jest from 27.3.1 to 27.4.3 (#544) ([6b9e3f1](https://github.com/readmeio/oas/commit/6b9e3f1)), closes [#544](https://github.com/readmeio/oas/issues/544)
9
+ * chore(deps-dev): bump prettier from 2.4.1 to 2.5.0 (#555) ([c09af34](https://github.com/readmeio/oas/commit/c09af34)), closes [#555](https://github.com/readmeio/oas/issues/555)
10
+ * chore(deps-dev): bump typescript from 4.4.4 to 4.5.2 (#548) ([f30435c](https://github.com/readmeio/oas/commit/f30435c)), closes [#548](https://github.com/readmeio/oas/issues/548)
11
+ * chore(deps): bump actions/checkout from 2.3.5 to 2.4.0 (#543) ([770a69e](https://github.com/readmeio/oas/commit/770a69e)), closes [#543](https://github.com/readmeio/oas/issues/543)
12
+ * chore(deps): bump actions/setup-node from 2.4.1 to 2.5.0 (#542) ([16aabb8](https://github.com/readmeio/oas/commit/16aabb8)), closes [#542](https://github.com/readmeio/oas/issues/542)
13
+ * chore(deps): bump oas-normalize from 5.0.1 to 5.0.2 (#550) ([f5cb67a](https://github.com/readmeio/oas/commit/f5cb67a)), closes [#550](https://github.com/readmeio/oas/issues/550)
14
+ * chore(deps): bump oas-normalize from 5.0.2 to 5.0.3 (#556) ([f3a829b](https://github.com/readmeio/oas/commit/f3a829b)), closes [#556](https://github.com/readmeio/oas/issues/556)
15
+ * chore(deps): bump openapi-types from 9.3.0 to 9.3.1 (#546) ([aeafb36](https://github.com/readmeio/oas/commit/aeafb36)), closes [#546](https://github.com/readmeio/oas/issues/546)
16
+ * chore(deps): bump swagger-inline from 4.2.2 to 5.0.2 (#551) ([0d095d3](https://github.com/readmeio/oas/commit/0d095d3)), closes [#551](https://github.com/readmeio/oas/issues/551)
17
+ * ci: ignoring chalk updates because its now an esm-only package ([d0c97f1](https://github.com/readmeio/oas/commit/d0c97f1))
18
+
19
+
20
+
21
+ ## <small>17.1.6 (2021-11-29)</small>
22
+
23
+ * fix: exposing response header descriptions in response json schema (#541) ([d6abf9e](https://github.com/readmeio/oas/commit/d6abf9e)), closes [#541](https://github.com/readmeio/oas/issues/541)
24
+
25
+
26
+
27
+ ## <small>17.1.5 (2021-11-22)</small>
28
+
29
+ * fix: don't fail to dereference if the api definition is nullish ([e1e33a6](https://github.com/readmeio/oas/commit/e1e33a6))
30
+ * test: adding more tests for null specs in `getAuth()` ([c8585c9](https://github.com/readmeio/oas/commit/c8585c9))
31
+
32
+
33
+
34
+ ## <small>17.1.4 (2021-11-22)</small>
35
+
36
+ * fix: more protections for when `api` is undefined ([3d217a3](https://github.com/readmeio/oas/commit/3d217a3))
37
+
38
+
39
+
1
40
  ## <small>17.1.3 (2021-11-20)</small>
2
41
 
3
42
  * 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))
package/dist/index.js CHANGED
@@ -88,12 +88,12 @@ function ensureProtocol(url) {
88
88
  // Add protocol to urls starting with // e.g. //example.com
89
89
  // This is because httpsnippet throws a HARError when it doesnt have a protocol
90
90
  if (url.match(/^\/\//)) {
91
- return "https:" + url;
91
+ return "https:".concat(url);
92
92
  }
93
93
  // Add protocol to urls with no // within them
94
94
  // This is because httpsnippet throws a HARError when it doesnt have a protocol
95
95
  if (!url.match(/\/\//)) {
96
- return "https://" + url;
96
+ return "https://".concat(url);
97
97
  }
98
98
  return url;
99
99
  }
@@ -188,7 +188,7 @@ function generatePathMatches(paths, pathName, origin) {
188
188
  var slugs = {};
189
189
  if (matchResult && Object.keys(matchResult.params).length) {
190
190
  Object.keys(matchResult.params).forEach(function (param) {
191
- slugs[":" + param] = matchResult.params[param];
191
+ slugs[":".concat(param)] = matchResult.params[param];
192
192
  });
193
193
  }
194
194
  return {
@@ -326,7 +326,7 @@ var Oas = /** @class */ (function () {
326
326
  var value = part.replace(/[{}]/g, '');
327
327
  // To ensure unique keys, we're going to create a key
328
328
  // with the value concatenated to its index.
329
- var key = value + "-" + i;
329
+ var key = "".concat(value, "-").concat(i);
330
330
  if (!isVariable) {
331
331
  return {
332
332
  type: 'text',
@@ -591,8 +591,8 @@ var Oas = /** @class */ (function () {
591
591
  * @returns Found auth keys for the found security schemes.
592
592
  */
593
593
  Oas.prototype.getAuth = function (user, selectedApp) {
594
- if (Object.keys(this.api.components || {}).length === 0 ||
595
- 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)) {
596
596
  return {};
597
597
  }
598
598
  return (0, get_auth_1["default"])(this.api, user, selectedApp);
@@ -727,7 +727,7 @@ var Oas = /** @class */ (function () {
727
727
  });
728
728
  }
729
729
  return [2 /*return*/, json_schema_ref_parser_1["default"]
730
- .dereference(api, {
730
+ .dereference(api || {}, {
731
731
  resolve: {
732
732
  // We shouldn't be resolving external pointers at this point so just ignore them.
733
733
  external: false
@@ -23,11 +23,11 @@ function findSchemaDefinition($ref, definitions) {
23
23
  $ref = decodeURIComponent($ref.substring(1));
24
24
  }
25
25
  else {
26
- throw new Error("Could not find a definition for " + origRef + ".");
26
+ throw new Error("Could not find a definition for ".concat(origRef, "."));
27
27
  }
28
28
  var current = jsonpointer_1["default"].get(definitions, $ref);
29
29
  if (current === undefined) {
30
- throw new Error("Could not find a definition for " + origRef + ".");
30
+ throw new Error("Could not find a definition for ".concat(origRef, "."));
31
31
  }
32
32
  return current;
33
33
  }
@@ -68,7 +68,8 @@ exports.getByScheme = getByScheme;
68
68
  * @returns Found auth keys for the found security schemes.
69
69
  */
70
70
  function getAuth(api, user, selectedApp) {
71
- 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) || {})
72
73
  .map(function (scheme) {
73
74
  var _a;
74
75
  return _a = {},
@@ -137,7 +137,7 @@ function searchForExampleByPointer(pointer, examples) {
137
137
  var pointers = [];
138
138
  var point = '';
139
139
  for (var i = 0; i < locSplit.length; i += 1) {
140
- point = "/" + locSplit[i] + point;
140
+ point = "/".concat(locSplit[i]).concat(point);
141
141
  pointers.push(point);
142
142
  }
143
143
  var example;
@@ -230,7 +230,7 @@ function toJSONSchema(data, opts) {
230
230
  if (polyType in schema && Array.isArray(schema[polyType])) {
231
231
  schema[polyType].forEach(function (item, idx) {
232
232
  var polyOptions = {
233
- currentLocation: currentLocation + "/" + idx,
233
+ currentLocation: "".concat(currentLocation, "/").concat(idx),
234
234
  globalDefaults: globalDefaults,
235
235
  isPolymorphicAllOfChild: polyType === 'allOf',
236
236
  prevSchemas: prevSchemas,
@@ -360,7 +360,7 @@ function toJSONSchema(data, opts) {
360
360
  else {
361
361
  // Run through the arrays contents and clean them up.
362
362
  schema.items = toJSONSchema(schema.items, {
363
- currentLocation: currentLocation + "/0",
363
+ currentLocation: "".concat(currentLocation, "/0"),
364
364
  globalDefaults: globalDefaults,
365
365
  prevSchemas: prevSchemas,
366
366
  refLogger: refLogger
@@ -384,7 +384,7 @@ function toJSONSchema(data, opts) {
384
384
  if ('properties' in schema) {
385
385
  Object.keys(schema.properties).map(function (prop) {
386
386
  schema.properties[prop] = toJSONSchema(schema.properties[prop], {
387
- currentLocation: currentLocation + "/" + encodePointer(prop),
387
+ currentLocation: "".concat(currentLocation, "/").concat(encodePointer(prop)),
388
388
  globalDefaults: globalDefaults,
389
389
  prevSchemas: prevSchemas,
390
390
  refLogger: refLogger
@@ -422,14 +422,14 @@ function toJSONSchema(data, opts) {
422
422
  // `format` and `type` they adhere to.
423
423
  if ('format' in schema) {
424
424
  var formatUpper = schema.format.toUpperCase();
425
- if (formatUpper + "_MIN" in FORMAT_OPTIONS) {
426
- if ((!schema.minimum && schema.minimum !== 0) || schema.minimum < FORMAT_OPTIONS[formatUpper + "_MIN"]) {
427
- schema.minimum = FORMAT_OPTIONS[formatUpper + "_MIN"];
425
+ if ("".concat(formatUpper, "_MIN") in FORMAT_OPTIONS) {
426
+ if ((!schema.minimum && schema.minimum !== 0) || schema.minimum < FORMAT_OPTIONS["".concat(formatUpper, "_MIN")]) {
427
+ schema.minimum = FORMAT_OPTIONS["".concat(formatUpper, "_MIN")];
428
428
  }
429
429
  }
430
- if (formatUpper + "_MAX" in FORMAT_OPTIONS) {
431
- if ((!schema.maximum && schema.maximum !== 0) || schema.maximum > FORMAT_OPTIONS[formatUpper + "_MAX"]) {
432
- schema.maximum = FORMAT_OPTIONS[formatUpper + "_MAX"];
430
+ if ("".concat(formatUpper, "_MAX") in FORMAT_OPTIONS) {
431
+ if ((!schema.maximum && schema.maximum !== 0) || schema.maximum > FORMAT_OPTIONS["".concat(formatUpper, "_MAX")]) {
432
+ schema.maximum = FORMAT_OPTIONS["".concat(formatUpper, "_MAX")];
433
433
  }
434
434
  }
435
435
  }
@@ -172,7 +172,7 @@ module.exports = function (path, operation, api, globalDefaults) {
172
172
  if (current.deprecated)
173
173
  currentSchema.deprecated = current.deprecated;
174
174
  schema = __assign({}, toJSONSchema(currentSchema, {
175
- currentLocation: "/" + current.name,
175
+ currentLocation: "/".concat(current.name),
176
176
  globalDefaults: globalDefaults,
177
177
  refLogger: refLogger
178
178
  }));
@@ -212,7 +212,7 @@ module.exports = function (path, operation, api, globalDefaults) {
212
212
  if (current.deprecated)
213
213
  currentSchema.deprecated = current.deprecated;
214
214
  schema = __assign({}, toJSONSchema(currentSchema, {
215
- currentLocation: "/" + current.name,
215
+ currentLocation: "/".concat(current.name),
216
216
  globalDefaults: globalDefaults,
217
217
  refLogger: refLogger
218
218
  }));
@@ -22,6 +22,9 @@ function buildHeadersSchema(response) {
22
22
  // This means they can have content instead of schema.
23
23
  // We should probably support that in the future
24
24
  headersSchema.properties[key] = toJSONSchema(headers[key].schema);
25
+ if (headers[key].description) {
26
+ headersSchema.properties[key].description = headers[key].description;
27
+ }
25
28
  }
26
29
  });
27
30
  var headersWrapper = {
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 || [];
@@ -256,7 +257,7 @@ var Operation = /** @class */ (function () {
256
257
  .replace(/^-|-$/g, '') // Don't start or end with -
257
258
  .replace(/--+/g, '-') // Remove double --'s
258
259
  .toLowerCase();
259
- return this.method.toLowerCase() + "_" + url;
260
+ return "".concat(this.method.toLowerCase(), "_").concat(url);
260
261
  };
261
262
  /**
262
263
  * @returns An array of all tags, and their metadata, that exist on this operation.
@@ -25,11 +25,11 @@ var primitive = function (schema) {
25
25
  schema = (0, utils_1.objectify)(schema);
26
26
  var type = schema.type, format = schema.format;
27
27
  // @todo add support for if `type` is an array
28
- var fn = primitives[type + "_" + format] || primitives[type];
28
+ var fn = primitives["".concat(type, "_").concat(format)] || primitives[type];
29
29
  if ((0, utils_1.isFunc)(fn)) {
30
30
  return fn(schema);
31
31
  }
32
- return "Unknown Type: " + schema.type;
32
+ return "Unknown Type: ".concat(schema.type);
33
33
  };
34
34
  /**
35
35
  * Generate a piece of sample data from a JSON Schema object. If `example` declarations are present they will be
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas",
3
- "version": "17.1.3",
3
+ "version": "17.2.0",
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)",
@@ -61,11 +61,11 @@
61
61
  "oas-normalize": "^5.0.1",
62
62
  "openapi-types": "^9.3.0",
63
63
  "path-to-regexp": "^6.2.0",
64
- "swagger-inline": "^4.1.5"
64
+ "swagger-inline": "^5.0.2"
65
65
  },
66
66
  "devDependencies": {
67
- "@commitlint/cli": "^14.1.0",
68
- "@commitlint/config-conventional": "^14.1.0",
67
+ "@commitlint/cli": "^15.0.0",
68
+ "@commitlint/config-conventional": "^15.0.0",
69
69
  "@readme/eslint-config": "^8.0.2",
70
70
  "@readme/oas-examples": "^4.3.2",
71
71
  "@types/jest": "^27.0.2",
package/src/index.ts CHANGED
@@ -620,10 +620,7 @@ export default class Oas {
620
620
  * @returns Found auth keys for the found security schemes.
621
621
  */
622
622
  getAuth(user: RMOAS.User, selectedApp?: string | number) {
623
- if (
624
- Object.keys(this.api.components || {}).length === 0 ||
625
- Object.keys(this.api.components.securitySchemes || {}).length === 0
626
- ) {
623
+ if (!this.api?.components?.securitySchemes) {
627
624
  return {};
628
625
  }
629
626
 
@@ -768,7 +765,7 @@ export default class Oas {
768
765
  }
769
766
 
770
767
  return $RefParser
771
- .dereference(api, {
768
+ .dereference(api || {}, {
772
769
  resolve: {
773
770
  // We shouldn't be resolving external pointers at this point so just ignore them.
774
771
  external: false,
@@ -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(
@@ -25,6 +25,9 @@ function buildHeadersSchema(response) {
25
25
  // This means they can have content instead of schema.
26
26
  // We should probably support that in the future
27
27
  headersSchema.properties[key] = toJSONSchema(headers[key].schema);
28
+ if (headers[key].description) {
29
+ headersSchema.properties[key].description = headers[key].description;
30
+ }
28
31
  }
29
32
  });
30
33
 
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