oas 17.3.0 → 17.4.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.
@@ -44,6 +44,8 @@ export default class Operation {
44
44
  response: Array<string>;
45
45
  };
46
46
  constructor(api: RMOAS.OASDocument, path: string, method: RMOAS.HttpMethods, operation: RMOAS.OperationObject);
47
+ getSummary(): string;
48
+ getDescription(): string;
47
49
  getContentType(): string;
48
50
  isFormUrlEncoded(): boolean;
49
51
  isMultipart(): boolean;
package/@types/utils.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import findSchemaDefinition from './lib/find-schema-definition';
2
2
  import getSchema from './lib/get-schema';
3
+ declare const supportedMethods: Set<string>;
3
4
  declare const _default: {
4
5
  findSchemaDefinition: typeof findSchemaDefinition;
5
6
  getSchema: typeof getSchema;
@@ -16,3 +17,4 @@ declare const _default: {
16
17
  };
17
18
  };
18
19
  export default _default;
20
+ export { supportedMethods };
package/CHANGELOG.md CHANGED
@@ -1,3 +1,41 @@
1
+ ## <small>17.4.1 (2022-01-03)</small>
2
+
3
+ * chore(deps-dev): bump @commitlint/cli from 15.0.0 to 16.0.1 (#569) ([ca515a9](https://github.com/readmeio/oas/commit/ca515a9)), closes [#569](https://github.com/readmeio/oas/issues/569)
4
+ * chore(deps-dev): bump @commitlint/config-conventional (#567) ([c4c6cc0](https://github.com/readmeio/oas/commit/c4c6cc0)), closes [#567](https://github.com/readmeio/oas/issues/567)
5
+ * chore(deps-dev): bump @types/jest from 27.0.3 to 27.4.0 (#574) ([eb21296](https://github.com/readmeio/oas/commit/eb21296)), closes [#574](https://github.com/readmeio/oas/issues/574)
6
+ * chore(deps-dev): bump eslint from 8.3.0 to 8.6.0 (#570) ([0dd19b1](https://github.com/readmeio/oas/commit/0dd19b1)), closes [#570](https://github.com/readmeio/oas/issues/570)
7
+ * chore(deps-dev): bump eslint-plugin-jsdoc from 37.1.0 to 37.5.0 (#571) ([b21ebfe](https://github.com/readmeio/oas/commit/b21ebfe)), closes [#571](https://github.com/readmeio/oas/issues/571)
8
+ * chore(deps-dev): bump jest from 27.4.3 to 27.4.5 (#573) ([4266065](https://github.com/readmeio/oas/commit/4266065)), closes [#573](https://github.com/readmeio/oas/issues/573)
9
+ * chore(deps-dev): bump prettier from 2.5.0 to 2.5.1 (#568) ([b4548c0](https://github.com/readmeio/oas/commit/b4548c0)), closes [#568](https://github.com/readmeio/oas/issues/568)
10
+ * chore(deps-dev): bump ts-jest from 27.0.7 to 27.1.2 (#566) ([16edcb0](https://github.com/readmeio/oas/commit/16edcb0)), closes [#566](https://github.com/readmeio/oas/issues/566)
11
+ * chore(deps-dev): bump typescript from 4.5.2 to 4.5.4 (#565) ([7bafc0d](https://github.com/readmeio/oas/commit/7bafc0d)), closes [#565](https://github.com/readmeio/oas/issues/565)
12
+ * chore(deps): bump actions/setup-node from 2.5.0 to 2.5.1 (#564) ([125afbe](https://github.com/readmeio/oas/commit/125afbe)), closes [#564](https://github.com/readmeio/oas/issues/564)
13
+ * chore(deps): bump openapi-types from 9.3.1 to 10.0.0 (#572) ([43e681b](https://github.com/readmeio/oas/commit/43e681b)), closes [#572](https://github.com/readmeio/oas/issues/572)
14
+ * chore(deps): upgrading oas-normalize ([851cf95](https://github.com/readmeio/oas/commit/851cf95))
15
+ * fix: improved support for common params (#563) ([ae3cb83](https://github.com/readmeio/oas/commit/ae3cb83)), closes [#563](https://github.com/readmeio/oas/issues/563)
16
+
17
+
18
+
19
+ ## 17.4.0 (2021-12-17)
20
+
21
+ * feat: adding accessors for operation summary and description (#562) ([1dd6a9f](https://github.com/readmeio/oas/commit/1dd6a9f)), closes [#562](https://github.com/readmeio/oas/issues/562)
22
+
23
+
24
+
25
+ ## <small>17.3.2 (2021-12-14)</small>
26
+
27
+ * fix: exclude readonly params from deprecatedProps (#561) ([3342bf2](https://github.com/readmeio/oas/commit/3342bf2)), closes [#561](https://github.com/readmeio/oas/issues/561)
28
+ * test: adding a regression case for the enum typescript quirk (#560) ([fabf01b](https://github.com/readmeio/oas/commit/fabf01b)), closes [#560](https://github.com/readmeio/oas/issues/560)
29
+
30
+
31
+
32
+ ## <small>17.3.1 (2021-12-08)</small>
33
+
34
+ * fix: upgrading oas-normalize to fix a rare npm installation issue (#558) ([ce6123d](https://github.com/readmeio/oas/commit/ce6123d)), closes [#558](https://github.com/readmeio/oas/issues/558)
35
+ * fix(jsonschema): move the version identifier to a better location (#557) ([1b52aec](https://github.com/readmeio/oas/commit/1b52aec)), closes [#557](https://github.com/readmeio/oas/issues/557)
36
+
37
+
38
+
1
39
  ## 17.3.0 (2021-12-06)
2
40
 
3
41
  * feat: OAS 3.1 for JSON Schemas (#530) ([91475da](https://github.com/readmeio/oas/commit/91475da)), closes [#530](https://github.com/readmeio/oas/issues/530)
package/dist/index.js CHANGED
@@ -78,7 +78,7 @@ var operation_1 = __importStar(require("./operation"));
78
78
  exports.Operation = operation_1["default"];
79
79
  exports.Callback = operation_1.Callback;
80
80
  exports.Webhook = operation_1.Webhook;
81
- var utils_1 = __importDefault(require("./utils"));
81
+ var utils_1 = __importStar(require("./utils"));
82
82
  exports.utils = utils_1["default"];
83
83
  /**
84
84
  * @param url URL to ensure that it has an HTTP protocol.
@@ -611,12 +611,11 @@ var Oas = /** @class */ (function () {
611
611
  // the paths object that isn't a known HTTP method.
612
612
  // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#fixed-fields-7
613
613
  // https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#fixed-fields-7
614
- var supportedMethods = new Set(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']);
615
614
  var paths = {};
616
615
  Object.keys(this.api.paths ? this.api.paths : []).forEach(function (path) {
617
616
  paths[path] = {};
618
617
  Object.keys(_this.api.paths[path]).forEach(function (method) {
619
- if (!supportedMethods.has(method))
618
+ if (!utils_1.supportedMethods.has(method))
620
619
  return;
621
620
  paths[path][method] = _this.operation(path, method);
622
621
  });
@@ -107,11 +107,11 @@ exports["default"] = (function (path, operation, api, globalDefaults) {
107
107
  var deprecatedBody = cloneObject(schema);
108
108
  // Booleans are not valid for required in draft 4, 7 or 2020. Not sure why the typing thinks they are.
109
109
  var requiredParams = (schema.required || []);
110
- // Find all top-level deprecated properties from the schema - required params are excluded
110
+ // Find all top-level deprecated properties from the schema - required and readOnly params are excluded
111
111
  var allDeprecatedProps = {};
112
112
  Object.keys(deprecatedBody.properties).forEach(function (key) {
113
113
  var deprecatedProp = deprecatedBody.properties[key];
114
- if (deprecatedProp.deprecated && !requiredParams.includes(key)) {
114
+ if (deprecatedProp.deprecated && !requiredParams.includes(key) && !deprecatedProp.readOnly) {
115
115
  allDeprecatedProps[key] = deprecatedProp;
116
116
  }
117
117
  });
@@ -132,7 +132,7 @@ exports["default"] = (function (path, operation, api, globalDefaults) {
132
132
  });
133
133
  return {
134
134
  type: type,
135
- schema: deprecatedSchema
135
+ schema: __assign(__assign({}, deprecatedSchema), { $schema: getSchemaVersionString(deprecatedSchema, api) })
136
136
  };
137
137
  }
138
138
  /**
@@ -164,10 +164,9 @@ exports["default"] = (function (path, operation, api, globalDefaults) {
164
164
  return null;
165
165
  }
166
166
  return {
167
- $schema: getSchemaVersionString(cleanedSchema, api),
168
167
  type: type,
169
168
  label: exports.types[type],
170
- schema: cleanedSchema,
169
+ schema: __assign(__assign({}, cleanedSchema), { $schema: getSchemaVersionString(cleanedSchema, api) }),
171
170
  deprecatedProps: getDeprecated(cleanedSchema, type)
172
171
  };
173
172
  }
package/dist/operation.js CHANGED
@@ -46,6 +46,7 @@ var get_requestbody_examples_1 = __importDefault(require("./operation/get-reques
46
46
  var get_callback_examples_1 = __importDefault(require("./operation/get-callback-examples"));
47
47
  var get_response_examples_1 = __importDefault(require("./operation/get-response-examples"));
48
48
  var matches_mimetype_1 = __importDefault(require("./lib/matches-mimetype"));
49
+ var utils_1 = require("./utils");
49
50
  var Operation = /** @class */ (function () {
50
51
  function Operation(api, path, method, operation) {
51
52
  this.schema = operation;
@@ -57,6 +58,20 @@ var Operation = /** @class */ (function () {
57
58
  this.responseExamples = undefined;
58
59
  this.callbackExamples = undefined;
59
60
  }
61
+ Operation.prototype.getSummary = function () {
62
+ var _a;
63
+ if (this.api.paths[this.path].summary) {
64
+ return this.api.paths[this.path].summary;
65
+ }
66
+ return ((_a = this.schema) === null || _a === void 0 ? void 0 : _a.summary) ? this.schema.summary.trim() : undefined;
67
+ };
68
+ Operation.prototype.getDescription = function () {
69
+ var _a;
70
+ if (this.api.paths[this.path].description) {
71
+ return this.api.paths[this.path].description;
72
+ }
73
+ return ((_a = this.schema) === null || _a === void 0 ? void 0 : _a.description) ? this.schema.description.trim() : undefined;
74
+ };
60
75
  Operation.prototype.getContentType = function () {
61
76
  var _this = this;
62
77
  if (this.contentType) {
@@ -453,6 +468,8 @@ var Operation = /** @class */ (function () {
453
468
  var exp = cb[expression];
454
469
  if (!RMOAS.isRef(exp)) {
455
470
  Object.keys(exp).forEach(function (method) {
471
+ if (!utils_1.supportedMethods.has(method))
472
+ return;
456
473
  callbackOperations.push(_this.getCallback(callback, expression, method));
457
474
  });
458
475
  }
package/dist/utils.js CHANGED
@@ -3,10 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  exports.__esModule = true;
6
+ exports.supportedMethods = void 0;
6
7
  var find_schema_definition_1 = __importDefault(require("./lib/find-schema-definition"));
7
8
  var get_schema_1 = __importDefault(require("./lib/get-schema"));
8
9
  var matches_mimetype_1 = __importDefault(require("./lib/matches-mimetype"));
9
10
  var get_parameters_as_json_schema_1 = require("./operation/get-parameters-as-json-schema");
11
+ var supportedMethods = new Set(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']);
12
+ exports.supportedMethods = supportedMethods;
10
13
  exports["default"] = {
11
14
  findSchemaDefinition: find_schema_definition_1["default"],
12
15
  getSchema: get_schema_1["default"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas",
3
- "version": "17.3.0",
3
+ "version": "17.4.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)",
@@ -59,14 +59,14 @@
59
59
  "jsonpointer": "^5.0.0",
60
60
  "memoizee": "^0.4.14",
61
61
  "minimist": "^1.2.0",
62
- "oas-normalize": "^5.0.1",
63
- "openapi-types": "^9.3.0",
62
+ "oas-normalize": "^5.1.0",
63
+ "openapi-types": "^10.0.0",
64
64
  "path-to-regexp": "^6.2.0",
65
65
  "swagger-inline": "^5.0.2"
66
66
  },
67
67
  "devDependencies": {
68
- "@commitlint/cli": "^15.0.0",
69
- "@commitlint/config-conventional": "^15.0.0",
68
+ "@commitlint/cli": "^16.0.1",
69
+ "@commitlint/config-conventional": "^16.0.0",
70
70
  "@readme/eslint-config": "^8.0.2",
71
71
  "@readme/oas-examples": "^4.3.2",
72
72
  "@types/jest": "^27.0.2",
package/src/index.ts CHANGED
@@ -7,7 +7,7 @@ import { pathToRegexp, match } from 'path-to-regexp';
7
7
  import getAuth from './lib/get-auth';
8
8
  import getUserVariable from './lib/get-user-variable';
9
9
  import Operation, { Callback, Webhook } from './operation';
10
- import utils from './utils';
10
+ import utils, { supportedMethods } from './utils';
11
11
 
12
12
  type PathMatch = {
13
13
  url: {
@@ -640,7 +640,6 @@ export default class Oas {
640
640
  // the paths object that isn't a known HTTP method.
641
641
  // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#fixed-fields-7
642
642
  // https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#fixed-fields-7
643
- const supportedMethods = new Set(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']);
644
643
  const paths: Record<string, Record<RMOAS.HttpMethods, Operation | Webhook>> = {};
645
644
 
646
645
  Object.keys(this.api.paths ? this.api.paths : []).forEach(path => {
@@ -89,12 +89,12 @@ export default (path: string, operation: OperationObject, api: OASDocument, glob
89
89
  // Booleans are not valid for required in draft 4, 7 or 2020. Not sure why the typing thinks they are.
90
90
  const requiredParams = (schema.required || []) as Array<string>;
91
91
 
92
- // Find all top-level deprecated properties from the schema - required params are excluded
92
+ // Find all top-level deprecated properties from the schema - required and readOnly params are excluded
93
93
  const allDeprecatedProps: { [key: string]: SchemaObject } = {};
94
94
 
95
95
  Object.keys(deprecatedBody.properties).forEach(key => {
96
96
  const deprecatedProp = deprecatedBody.properties[key] as SchemaObject;
97
- if (deprecatedProp.deprecated && !requiredParams.includes(key)) {
97
+ if (deprecatedProp.deprecated && !requiredParams.includes(key) && !deprecatedProp.readOnly) {
98
98
  allDeprecatedProps[key] = deprecatedProp;
99
99
  }
100
100
  });
@@ -119,7 +119,10 @@ export default (path: string, operation: OperationObject, api: OASDocument, glob
119
119
 
120
120
  return {
121
121
  type,
122
- schema: deprecatedSchema,
122
+ schema: {
123
+ ...deprecatedSchema,
124
+ $schema: getSchemaVersionString(deprecatedSchema, api),
125
+ },
123
126
  };
124
127
  }
125
128
 
@@ -156,10 +159,12 @@ export default (path: string, operation: OperationObject, api: OASDocument, glob
156
159
  }
157
160
 
158
161
  return {
159
- $schema: getSchemaVersionString(cleanedSchema, api),
160
162
  type,
161
163
  label: types[type],
162
- schema: cleanedSchema,
164
+ schema: {
165
+ ...cleanedSchema,
166
+ $schema: getSchemaVersionString(cleanedSchema, api),
167
+ },
163
168
  deprecatedProps: getDeprecated(cleanedSchema, type),
164
169
  };
165
170
  }
package/src/operation.ts CHANGED
@@ -11,6 +11,7 @@ import getRequestBodyExamples from './operation/get-requestbody-examples';
11
11
  import getCallbackExamples from './operation/get-callback-examples';
12
12
  import getResponseExamples from './operation/get-response-examples';
13
13
  import matchesMimeType from './lib/matches-mimetype';
14
+ import { supportedMethods } from './utils';
14
15
 
15
16
  type SecurityType = 'Basic' | 'Bearer' | 'Query' | 'Header' | 'Cookie' | 'OAuth2' | 'http' | 'apiKey';
16
17
 
@@ -75,6 +76,22 @@ export default class Operation {
75
76
  this.callbackExamples = undefined;
76
77
  }
77
78
 
79
+ getSummary(): string {
80
+ if (this.api.paths[this.path].summary) {
81
+ return this.api.paths[this.path].summary;
82
+ }
83
+
84
+ return this.schema?.summary ? this.schema.summary.trim() : undefined;
85
+ }
86
+
87
+ getDescription(): string {
88
+ if (this.api.paths[this.path].description) {
89
+ return this.api.paths[this.path].description;
90
+ }
91
+
92
+ return this.schema?.description ? this.schema.description.trim() : undefined;
93
+ }
94
+
78
95
  getContentType(): string {
79
96
  if (this.contentType) {
80
97
  return this.contentType;
@@ -519,6 +536,8 @@ export default class Operation {
519
536
 
520
537
  if (!RMOAS.isRef(exp)) {
521
538
  Object.keys(exp).forEach((method: RMOAS.HttpMethods) => {
539
+ if (!supportedMethods.has(method)) return;
540
+
522
541
  callbackOperations.push(this.getCallback(callback, expression, method));
523
542
  });
524
543
  }
package/src/utils.ts CHANGED
@@ -3,9 +3,13 @@ import getSchema from './lib/get-schema';
3
3
  import matchesMimeType from './lib/matches-mimetype';
4
4
  import { types as jsonSchemaTypes } from './operation/get-parameters-as-json-schema';
5
5
 
6
+ const supportedMethods = new Set(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']);
7
+
6
8
  export default {
7
9
  findSchemaDefinition,
8
10
  getSchema,
9
11
  jsonSchemaTypes,
10
12
  matchesMimeType,
11
13
  };
14
+
15
+ export { supportedMethods };