oas 20.3.0 → 20.4.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 20.4.0 (2023-01-12)
2
+
3
+ * feat: pass through requestBody descriptions (#730) ([3272137](https://github.com/readmeio/oas/commit/3272137)), closes [#730](https://github.com/readmeio/oas/issues/730)
4
+
5
+
6
+
1
7
  ## 20.3.0 (2023-01-03)
2
8
 
3
9
  * chore: bumping deps ([ed5e473](https://github.com/readmeio/oas/commit/ed5e473))
@@ -5,6 +5,7 @@ export interface SchemaWrapper {
5
5
  type: string;
6
6
  label?: string;
7
7
  schema: SchemaObject;
8
+ description?: string;
8
9
  deprecatedProps?: SchemaWrapper;
9
10
  }
10
11
  /**
@@ -127,7 +127,7 @@ function getParametersAsJSONSchema(operation, api, opts) {
127
127
  var requestBody = operation.getRequestBody();
128
128
  if (!requestBody || !Array.isArray(requestBody))
129
129
  return null;
130
- var mediaType = requestBody[0], mediaTypeObject = requestBody[1];
130
+ var mediaType = requestBody[0], mediaTypeObject = requestBody[1], description = requestBody[2];
131
131
  var type = mediaType === 'application/x-www-form-urlencoded' ? 'formData' : 'body';
132
132
  // If this schema is completely empty, don't bother processing it.
133
133
  if (!mediaTypeObject.schema || !Object.keys(mediaTypeObject.schema).length) {
@@ -157,14 +157,9 @@ function getParametersAsJSONSchema(operation, api, opts) {
157
157
  if (!Object.keys(cleanedSchema).length) {
158
158
  return null;
159
159
  }
160
- return {
161
- type: type,
162
- label: exports.types[type],
163
- schema: (0, openapi_to_json_schema_1.isPrimitive)(cleanedSchema)
160
+ return __assign({ type: type, label: exports.types[type], schema: (0, openapi_to_json_schema_1.isPrimitive)(cleanedSchema)
164
161
  ? cleanedSchema
165
- : __assign(__assign({}, cleanedSchema), { $schema: (0, openapi_to_json_schema_1.getSchemaVersionString)(cleanedSchema, api) }),
166
- deprecatedProps: getDeprecated(cleanedSchema, type)
167
- };
162
+ : __assign(__assign({}, cleanedSchema), { $schema: (0, openapi_to_json_schema_1.getSchemaVersionString)(cleanedSchema, api) }), deprecatedProps: getDeprecated(cleanedSchema, type) }, (description ? { description: description } : {}));
168
163
  }
169
164
  function transformComponents() {
170
165
  if (!('components' in api)) {
@@ -210,7 +210,7 @@ export default class Operation {
210
210
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#mediaTypeObject}
211
211
  * @param mediaType Specific request body media type to retrieve if present.
212
212
  */
213
- getRequestBody(mediaType?: string): false | RMOAS.MediaTypeObject | [string, RMOAS.MediaTypeObject];
213
+ getRequestBody(mediaType?: string): false | RMOAS.MediaTypeObject | [string, RMOAS.MediaTypeObject, ...string[]];
214
214
  /**
215
215
  * Retrieve an array of request body examples that this operation has.
216
216
  *
package/dist/operation.js CHANGED
@@ -48,6 +48,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
48
48
  __setModuleDefault(result, mod);
49
49
  return result;
50
50
  };
51
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
52
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
53
+ if (ar || !(i in from)) {
54
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
55
+ ar[i] = from[i];
56
+ }
57
+ }
58
+ return to.concat(ar || Array.prototype.slice.call(from));
59
+ };
51
60
  var __importDefault = (this && this.__importDefault) || function (mod) {
52
61
  return (mod && mod.__esModule) ? mod : { "default": mod };
53
62
  };
@@ -543,7 +552,10 @@ var Operation = /** @class */ (function () {
543
552
  });
544
553
  }
545
554
  if (availableMediaType) {
546
- return [availableMediaType, requestBody.content[availableMediaType]];
555
+ return __spreadArray([
556
+ availableMediaType,
557
+ requestBody.content[availableMediaType]
558
+ ], (requestBody.description ? [requestBody.description] : []), true);
547
559
  }
548
560
  return false;
549
561
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas",
3
- "version": "20.3.0",
3
+ "version": "20.4.0",
4
4
  "description": "Comprehensive tooling for working with OpenAPI definitions",
5
5
  "license": "MIT",
6
6
  "author": "ReadMe <support@readme.io> (https://readme.com)",
@@ -13,6 +13,7 @@ export interface SchemaWrapper {
13
13
  type: string;
14
14
  label?: string;
15
15
  schema: SchemaObject;
16
+ description?: string;
16
17
  deprecatedProps?: SchemaWrapper;
17
18
  }
18
19
 
@@ -124,7 +125,7 @@ export default function getParametersAsJSONSchema(
124
125
  const requestBody = operation.getRequestBody();
125
126
  if (!requestBody || !Array.isArray(requestBody)) return null;
126
127
 
127
- const [mediaType, mediaTypeObject] = requestBody;
128
+ const [mediaType, mediaTypeObject, description] = requestBody;
128
129
  const type = mediaType === 'application/x-www-form-urlencoded' ? 'formData' : 'body';
129
130
 
130
131
  // If this schema is completely empty, don't bother processing it.
@@ -146,6 +147,7 @@ export default function getParametersAsJSONSchema(
146
147
  // We're cloning the request schema because we've had issues with request schemas that were
147
148
  // dereferenced being processed multiple times because their component is also processed.
148
149
  const requestSchema = cloneObject(mediaTypeObject.schema);
150
+
149
151
  const cleanedSchema = toJSONSchema(requestSchema, {
150
152
  globalDefaults: opts.globalDefaults,
151
153
  prevSchemas,
@@ -168,6 +170,7 @@ export default function getParametersAsJSONSchema(
168
170
  $schema: getSchemaVersionString(cleanedSchema, api),
169
171
  },
170
172
  deprecatedProps: getDeprecated(cleanedSchema, type),
173
+ ...(description ? { description } : {}),
171
174
  };
172
175
  }
173
176
 
package/src/operation.ts CHANGED
@@ -621,7 +621,7 @@ export default class Operation {
621
621
  * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#mediaTypeObject}
622
622
  * @param mediaType Specific request body media type to retrieve if present.
623
623
  */
624
- getRequestBody(mediaType?: string): false | RMOAS.MediaTypeObject | [string, RMOAS.MediaTypeObject] {
624
+ getRequestBody(mediaType?: string): false | RMOAS.MediaTypeObject | [string, RMOAS.MediaTypeObject, ...string[]] {
625
625
  if (!this.hasRequestBody()) {
626
626
  return false;
627
627
  }
@@ -660,7 +660,11 @@ export default class Operation {
660
660
  }
661
661
 
662
662
  if (availableMediaType) {
663
- return [availableMediaType, requestBody.content[availableMediaType]];
663
+ return [
664
+ availableMediaType,
665
+ requestBody.content[availableMediaType],
666
+ ...(requestBody.description ? [requestBody.description] : []),
667
+ ];
664
668
  }
665
669
 
666
670
  return false;