oas 18.3.0 → 18.3.3

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.
@@ -2,8 +2,7 @@
2
2
  * Lookup a reference pointer within an OpenAPI definition and return the schema that it resolves
3
3
  * to.
4
4
  *
5
- * @deprecated
6
5
  * @param $ref Reference to look up a schema for.
7
- * @param definitions OpenAPI definition to look for the `$ref` pointer in.
6
+ * @param definition OpenAPI definition to look for the `$ref` pointer in.
8
7
  */
9
- export default function findSchemaDefinition($ref: string, definitions?: {}): any;
8
+ export default function findSchemaDefinition($ref: string, definition?: {}): any;
package/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ## <small>18.3.3 (2022-05-20)</small>
2
+
3
+ * fix: add protections for if a `requestBody` has no `schema` (#649) ([0aa38d3](https://github.com/readmeio/oas/commit/0aa38d3)), closes [#649](https://github.com/readmeio/oas/issues/649)
4
+
5
+
6
+
7
+ ## <small>18.3.2 (2022-05-16)</small>
8
+
9
+ * feat: adding $ref awareness to `Oas.getPaths()` (#648) ([9cf5786](https://github.com/readmeio/oas/commit/9cf5786)), closes [#648](https://github.com/readmeio/oas/issues/648)
10
+ * chore(deps-dev): bump @commitlint/cli from 16.2.3 to 16.2.4 (#644) ([7976d5b](https://github.com/readmeio/oas/commit/7976d5b)), closes [#644](https://github.com/readmeio/oas/issues/644)
11
+ * chore(deps-dev): bump @commitlint/config-conventional (#645) ([4addef9](https://github.com/readmeio/oas/commit/4addef9)), closes [#645](https://github.com/readmeio/oas/issues/645)
12
+ * chore(deps-dev): bump @readme/eslint-config from 8.7.2 to 8.7.3 (#641) ([ec78d08](https://github.com/readmeio/oas/commit/ec78d08)), closes [#641](https://github.com/readmeio/oas/issues/641)
13
+ * chore(deps-dev): bump typescript from 4.6.3 to 4.6.4 (#647) ([24048f3](https://github.com/readmeio/oas/commit/24048f3)), closes [#647](https://github.com/readmeio/oas/issues/647)
14
+ * chore(deps): bump github/codeql-action from 1 to 2 (#640) ([72da639](https://github.com/readmeio/oas/commit/72da639)), closes [#640](https://github.com/readmeio/oas/issues/640)
15
+ * chore(deps): bump glob from 7.2.0 to 8.0.1 (#646) ([5190e62](https://github.com/readmeio/oas/commit/5190e62)), closes [#646](https://github.com/readmeio/oas/issues/646)
16
+ * chore(deps): bump inquirer from 8.2.2 to 8.2.4 (#642) ([479aa5f](https://github.com/readmeio/oas/commit/479aa5f)), closes [#642](https://github.com/readmeio/oas/issues/642)
17
+ * chore(deps): bump openapi-types from 10.0.0 to 11.0.0 (#643) ([5c53b5e](https://github.com/readmeio/oas/commit/5c53b5e)), closes [#643](https://github.com/readmeio/oas/issues/643)
18
+
19
+
20
+
21
+ ## <small>18.3.1 (2022-04-26)</small>
22
+
23
+ * chore(deps): bumping out of date deps to get rid of node 18 compat issues (#639) ([13703c8](https://github.com/readmeio/oas/commit/13703c8)), closes [#639](https://github.com/readmeio/oas/issues/639)
24
+
25
+
26
+
1
27
  ## <small>18.2.2 (2022-04-11)</small>
2
28
 
3
29
  * fix: stop rewriting operationIds when we don't need to (#635) ([996cd40](https://github.com/readmeio/oas/commit/996cd40)), closes [#635](https://github.com/readmeio/oas/issues/635)
package/dist/index.js CHANGED
@@ -634,11 +634,16 @@ var Oas = /** @class */ (function () {
634
634
  * anything from within the paths object that isn't a known HTTP method.
635
635
  *
636
636
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#fixed-fields-7}
637
- * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#fixed-fields-7
637
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#fixed-fields-7}
638
638
  */
639
639
  var paths = {};
640
640
  Object.keys(this.api.paths ? this.api.paths : []).forEach(function (path) {
641
641
  paths[path] = {};
642
+ // Though this library is generally unaware of `$ref` pointers we're making a singular
643
+ // exception with this accessor out of convenience.
644
+ if ('$ref' in _this.api.paths[path]) {
645
+ _this.api.paths[path] = utils_1["default"].findSchemaDefinition(_this.api.paths[path].$ref, _this.api);
646
+ }
642
647
  Object.keys(_this.api.paths[path]).forEach(function (method) {
643
648
  if (!utils_1.supportedMethods.has(method))
644
649
  return;
@@ -3,18 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  exports.__esModule = true;
6
- // Nabbed from react-jsonschema-form, but this should probably be extracted into a slim NPM module.
7
6
  var jsonpointer_1 = __importDefault(require("jsonpointer"));
8
7
  /**
9
8
  * Lookup a reference pointer within an OpenAPI definition and return the schema that it resolves
10
9
  * to.
11
10
  *
12
- * @deprecated
13
11
  * @param $ref Reference to look up a schema for.
14
- * @param definitions OpenAPI definition to look for the `$ref` pointer in.
12
+ * @param definition OpenAPI definition to look for the `$ref` pointer in.
15
13
  */
16
- function findSchemaDefinition($ref, definitions) {
17
- if (definitions === void 0) { definitions = {}; }
14
+ function findSchemaDefinition($ref, definition) {
15
+ if (definition === void 0) { definition = {}; }
18
16
  var origRef = $ref;
19
17
  $ref = $ref.trim();
20
18
  if ($ref === '') {
@@ -28,7 +26,7 @@ function findSchemaDefinition($ref, definitions) {
28
26
  else {
29
27
  throw new Error("Could not find a definition for ".concat(origRef, "."));
30
28
  }
31
- var current = jsonpointer_1["default"].get(definitions, $ref);
29
+ var current = jsonpointer_1["default"].get(definition, $ref);
32
30
  if (current === undefined) {
33
31
  throw new Error("Could not find a definition for ".concat(origRef, "."));
34
32
  }
@@ -121,7 +121,7 @@ function getParametersAsJsonSchema(operation, api, opts) {
121
121
  var mediaType = requestBody[0], mediaTypeObject = requestBody[1];
122
122
  var type = mediaType === 'application/x-www-form-urlencoded' ? 'formData' : 'body';
123
123
  // If this schema is completely empty, don't bother processing it.
124
- if (!Object.keys(mediaTypeObject.schema).length) {
124
+ if (!mediaTypeObject.schema || !Object.keys(mediaTypeObject.schema).length) {
125
125
  return null;
126
126
  }
127
127
  var prevSchemas = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas",
3
- "version": "18.3.0",
3
+ "version": "18.3.3",
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)",
@@ -37,11 +37,10 @@
37
37
  "scripts": {
38
38
  "build": "tsc",
39
39
  "lint": "eslint . --ext .js,.ts",
40
- "lint:docs": "alex . .github/",
41
40
  "prebuild": "rm -rf dist/ @types/",
42
41
  "prepack": "npm run build",
43
42
  "prepare": "husky install",
44
- "pretest": "npm run lint && npm run lint:docs",
43
+ "pretest": "npm run lint",
45
44
  "prettier": "prettier --list-different --write \"./**/**.{js,ts}\"",
46
45
  "release": "npx conventional-changelog-cli -i CHANGELOG.md -s && git add CHANGELOG.md",
47
46
  "test": "tsc; jest --coverage",
@@ -53,32 +52,31 @@
53
52
  "@types/json-schema": "^7.0.11",
54
53
  "cardinal": "^2.1.1",
55
54
  "chalk": "^4.1.2",
56
- "glob": "^7.1.2",
55
+ "glob": "^8.0.1",
57
56
  "inquirer": "^8.1.2",
58
57
  "json-schema-merge-allof": "^0.8.1",
59
58
  "json2yaml": "^1.1.0",
60
59
  "jsonpointer": "^5.0.0",
61
60
  "memoizee": "^0.4.14",
62
61
  "minimist": "^1.2.0",
63
- "oas-normalize": "^5.2.0",
64
- "openapi-types": "^10.0.0",
62
+ "oas-normalize": "^6.0.0",
63
+ "openapi-types": "^11.0.0",
65
64
  "path-to-regexp": "^6.2.0",
66
- "swagger-inline": "^5.2.0"
65
+ "swagger-inline": "^6.0.0"
67
66
  },
68
67
  "devDependencies": {
69
68
  "@commitlint/cli": "^16.2.3",
70
69
  "@commitlint/config-conventional": "^16.0.0",
71
- "@readme/eslint-config": "^8.5.1",
72
- "@readme/oas-examples": "^5.0.0",
73
- "@readme/openapi-parser": "^2.0.4",
70
+ "@readme/eslint-config": "^8.7.2",
71
+ "@readme/oas-examples": "^5.1.1",
72
+ "@readme/openapi-parser": "^2.2.0",
74
73
  "@types/jest": "^27.0.2",
75
74
  "@types/json-schema-merge-allof": "^0.6.1",
76
75
  "@types/memoizee": "^0.4.6",
77
- "alex": "^10.0.0",
78
- "eslint": "^8.12.0",
76
+ "eslint": "^8.14.0",
79
77
  "husky": "^7.0.2",
80
78
  "jest": "^27.0.3",
81
- "prettier": "^2.6.1",
79
+ "prettier": "^2.6.2",
82
80
  "ts-jest": "^27.1.4",
83
81
  "typescript": "^4.6.3"
84
82
  },
package/src/index.ts CHANGED
@@ -657,12 +657,19 @@ export default class Oas {
657
657
  * anything from within the paths object that isn't a known HTTP method.
658
658
  *
659
659
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#fixed-fields-7}
660
- * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#fixed-fields-7
660
+ * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#fixed-fields-7}
661
661
  */
662
662
  const paths: Record<string, Record<RMOAS.HttpMethods, Operation | Webhook>> = {};
663
663
 
664
664
  Object.keys(this.api.paths ? this.api.paths : []).forEach(path => {
665
665
  paths[path] = {} as Record<RMOAS.HttpMethods, Operation | Webhook>;
666
+
667
+ // Though this library is generally unaware of `$ref` pointers we're making a singular
668
+ // exception with this accessor out of convenience.
669
+ if ('$ref' in this.api.paths[path]) {
670
+ this.api.paths[path] = utils.findSchemaDefinition(this.api.paths[path].$ref, this.api);
671
+ }
672
+
666
673
  Object.keys(this.api.paths[path]).forEach((method: RMOAS.HttpMethods) => {
667
674
  if (!supportedMethods.has(method)) return;
668
675
 
@@ -1,15 +1,13 @@
1
- // Nabbed from react-jsonschema-form, but this should probably be extracted into a slim NPM module.
2
1
  import jsonpointer from 'jsonpointer';
3
2
 
4
3
  /**
5
4
  * Lookup a reference pointer within an OpenAPI definition and return the schema that it resolves
6
5
  * to.
7
6
  *
8
- * @deprecated
9
7
  * @param $ref Reference to look up a schema for.
10
- * @param definitions OpenAPI definition to look for the `$ref` pointer in.
8
+ * @param definition OpenAPI definition to look for the `$ref` pointer in.
11
9
  */
12
- export default function findSchemaDefinition($ref: string, definitions = {}) {
10
+ export default function findSchemaDefinition($ref: string, definition = {}) {
13
11
  const origRef = $ref;
14
12
 
15
13
  $ref = $ref.trim();
@@ -25,7 +23,7 @@ export default function findSchemaDefinition($ref: string, definitions = {}) {
25
23
  throw new Error(`Could not find a definition for ${origRef}.`);
26
24
  }
27
25
 
28
- const current = jsonpointer.get(definitions, $ref);
26
+ const current = jsonpointer.get(definition, $ref);
29
27
  if (current === undefined) {
30
28
  throw new Error(`Could not find a definition for ${origRef}.`);
31
29
  }
@@ -117,7 +117,7 @@ export default function getParametersAsJsonSchema(
117
117
  const type = mediaType === 'application/x-www-form-urlencoded' ? 'formData' : 'body';
118
118
 
119
119
  // If this schema is completely empty, don't bother processing it.
120
- if (!Object.keys(mediaTypeObject.schema).length) {
120
+ if (!mediaTypeObject.schema || !Object.keys(mediaTypeObject.schema).length) {
121
121
  return null;
122
122
  }
123
123