oas 17.3.1 → 17.4.2

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;
@@ -210,7 +212,11 @@ export declare class Callback extends Operation {
210
212
  * The identifier that this callback is set to.
211
213
  */
212
214
  identifier: string;
213
- constructor(oas: RMOAS.OASDocument, path: string, method: RMOAS.HttpMethods, operation: RMOAS.OperationObject, identifier: string);
215
+ /**
216
+ * The parent path item object that this Callback exists within.
217
+ */
218
+ parentSchema: RMOAS.PathItemObject;
219
+ constructor(oas: RMOAS.OASDocument, path: string, method: RMOAS.HttpMethods, operation: RMOAS.OperationObject, identifier: string, parentPathItem: RMOAS.PathItemObject);
214
220
  /**
215
221
  * Return the primary identifier for this callback.
216
222
  *
@@ -219,6 +225,8 @@ export declare class Callback extends Operation {
219
225
  * @returns {string}
220
226
  */
221
227
  getIdentifier(): string;
228
+ getSummary(): string;
229
+ getDescription(): string;
222
230
  }
223
231
  export declare class Webhook extends Operation {
224
232
  }
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.2 (2022-01-05)</small>
2
+
3
+ * fix: callbacks not having path-level data to retrieve common summaries (#575) ([c7d1144](https://github.com/readmeio/oas/commit/c7d1144)), closes [#575](https://github.com/readmeio/oas/issues/575)
4
+ * test: adding test coverage for OpenAPI 3.1 `pathItems` components ([77b596e](https://github.com/readmeio/oas/commit/77b596e))
5
+
6
+
7
+
8
+ ## <small>17.4.1 (2022-01-03)</small>
9
+
10
+ * 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)
11
+ * 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)
12
+ * 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)
13
+ * 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)
14
+ * 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)
15
+ * 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)
16
+ * 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)
17
+ * 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)
18
+ * 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)
19
+ * 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)
20
+ * 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)
21
+ * chore(deps): upgrading oas-normalize ([851cf95](https://github.com/readmeio/oas/commit/851cf95))
22
+ * fix: improved support for common params (#563) ([ae3cb83](https://github.com/readmeio/oas/commit/ae3cb83)), closes [#563](https://github.com/readmeio/oas/issues/563)
23
+
24
+
25
+
26
+ ## 17.4.0 (2021-12-17)
27
+
28
+ * 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)
29
+
30
+
31
+
32
+ ## <small>17.3.2 (2021-12-14)</small>
33
+
34
+ * fix: exclude readonly params from deprecatedProps (#561) ([3342bf2](https://github.com/readmeio/oas/commit/3342bf2)), closes [#561](https://github.com/readmeio/oas/issues/561)
35
+ * 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)
36
+
37
+
38
+
1
39
  ## <small>17.3.1 (2021-12-08)</small>
2
40
 
3
41
  * 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)
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
  });
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) {
@@ -434,7 +449,7 @@ var Operation = /** @class */ (function () {
434
449
  : false;
435
450
  if (!callback || !callback[method])
436
451
  return false;
437
- return new Callback(this.api, expression, method, callback[method], identifier);
452
+ return new Callback(this.api, expression, method, callback[method], identifier, callback);
438
453
  };
439
454
  /**
440
455
  * Retrieve an array of operations created from each callback.
@@ -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
  }
@@ -501,9 +518,10 @@ var Operation = /** @class */ (function () {
501
518
  exports["default"] = Operation;
502
519
  var Callback = /** @class */ (function (_super) {
503
520
  __extends(Callback, _super);
504
- function Callback(oas, path, method, operation, identifier) {
521
+ function Callback(oas, path, method, operation, identifier, parentPathItem) {
505
522
  var _this = _super.call(this, oas, path, method, operation) || this;
506
523
  _this.identifier = identifier;
524
+ _this.parentSchema = parentPathItem;
507
525
  return _this;
508
526
  }
509
527
  /**
@@ -516,6 +534,20 @@ var Callback = /** @class */ (function (_super) {
516
534
  Callback.prototype.getIdentifier = function () {
517
535
  return this.identifier;
518
536
  };
537
+ Callback.prototype.getSummary = function () {
538
+ var _a;
539
+ if (this.parentSchema.summary) {
540
+ return this.parentSchema.summary;
541
+ }
542
+ return ((_a = this.schema) === null || _a === void 0 ? void 0 : _a.summary) ? this.schema.summary.trim() : undefined;
543
+ };
544
+ Callback.prototype.getDescription = function () {
545
+ var _a;
546
+ if (this.parentSchema.description) {
547
+ return this.parentSchema.description;
548
+ }
549
+ return ((_a = this.schema) === null || _a === void 0 ? void 0 : _a.description) ? this.schema.description.trim() : undefined;
550
+ };
519
551
  return Callback;
520
552
  }(Operation));
521
553
  exports.Callback = Callback;
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.1",
3
+ "version": "17.4.2",
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.5",
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
  });
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;
@@ -498,7 +515,7 @@ export default class Operation {
498
515
  : false;
499
516
 
500
517
  if (!callback || !callback[method]) return false;
501
- return new Callback(this.api, expression, method, callback[method], identifier);
518
+ return new Callback(this.api, expression, method, callback[method], identifier, callback);
502
519
  }
503
520
 
504
521
  /**
@@ -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
  }
@@ -574,16 +593,23 @@ export class Callback extends Operation {
574
593
  */
575
594
  identifier: string;
576
595
 
596
+ /**
597
+ * The parent path item object that this Callback exists within.
598
+ */
599
+ parentSchema: RMOAS.PathItemObject;
600
+
577
601
  constructor(
578
602
  oas: RMOAS.OASDocument,
579
603
  path: string,
580
604
  method: RMOAS.HttpMethods,
581
605
  operation: RMOAS.OperationObject,
582
- identifier: string
606
+ identifier: string,
607
+ parentPathItem: RMOAS.PathItemObject
583
608
  ) {
584
609
  super(oas, path, method, operation);
585
610
 
586
611
  this.identifier = identifier;
612
+ this.parentSchema = parentPathItem;
587
613
  }
588
614
 
589
615
  /**
@@ -596,6 +622,22 @@ export class Callback extends Operation {
596
622
  getIdentifier(): string {
597
623
  return this.identifier;
598
624
  }
625
+
626
+ getSummary(): string {
627
+ if (this.parentSchema.summary) {
628
+ return this.parentSchema.summary;
629
+ }
630
+
631
+ return this.schema?.summary ? this.schema.summary.trim() : undefined;
632
+ }
633
+
634
+ getDescription(): string {
635
+ if (this.parentSchema.description) {
636
+ return this.parentSchema.description;
637
+ }
638
+
639
+ return this.schema?.description ? this.schema.description.trim() : undefined;
640
+ }
599
641
  }
600
642
 
601
643
  export class Webhook extends Operation {}
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 };