oas 19.0.2 → 19.0.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## <small>19.0.3 (2022-10-27)</small>
2
+
3
+ * fix: various compatibility issues with `api` codegen (#700) ([01a6554](https://github.com/readmeio/oas/commit/01a6554)), closes [#700](https://github.com/readmeio/oas/issues/700)
4
+
5
+
6
+
1
7
  ## <small>19.0.2 (2022-10-26)</small>
2
8
 
3
9
  * fix: quirks with discriminators and the `transformer` JSON Schema option (#698) ([b84c57f](https://github.com/readmeio/oas/commit/b84c57f)), closes [#698](https://github.com/readmeio/oas/issues/698)
package/dist/index.js CHANGED
@@ -636,6 +636,10 @@ var Oas = /** @class */ (function () {
636
636
  */
637
637
  var paths = {};
638
638
  Object.keys(this.api.paths ? this.api.paths : []).forEach(function (path) {
639
+ // If this is a specification extension then we should ignore it.
640
+ if (path.startsWith('x-')) {
641
+ return;
642
+ }
639
643
  paths[path] = {};
640
644
  // Though this library is generally unaware of `$ref` pointers we're making a singular
641
645
  // exception with this accessor out of convenience.
@@ -288,7 +288,9 @@ function getParametersAsJSONSchema(operation, api, opts) {
288
288
  // Parameter descriptions don't exist in `current.schema` so `constructSchema` will never
289
289
  // have access to it.
290
290
  if (current.description) {
291
- schema.description = current.description;
291
+ if (!(0, openapi_to_json_schema_1.isPrimitive)(schema)) {
292
+ schema.description = current.description;
293
+ }
292
294
  }
293
295
  prev[current.name] = schema;
294
296
  if (current.required) {
package/dist/operation.js CHANGED
@@ -325,16 +325,22 @@ var Operation = /** @class */ (function () {
325
325
  if (this.hasOperationId()) {
326
326
  operationId = sanitize(operationId);
327
327
  }
328
+ // Never start with a number.
329
+ operationId = operationId.replace(/^[0-9]/g, function (match) { return "_".concat(match); });
330
+ // Ensure that the first character of an `operationId` is always lowercase.
331
+ operationId = operationId.charAt(0).toLowerCase() + operationId.slice(1);
328
332
  // If the generated `operationId` already starts with the method (eg. `getPets`) we don't want
329
333
  // to double it up into `getGetPets`.
330
334
  if (operationId.startsWith(method)) {
331
335
  return operationId;
332
336
  }
333
- // If this operation already has an operationId and we just cleaned it up then we shouldn't
337
+ // If this operation already has an `operationId` and we just cleaned it up then we shouldn't
334
338
  // prefix it with an HTTP method.
335
339
  if (this.hasOperationId()) {
336
340
  return operationId;
337
341
  }
342
+ // Because we're merging the `operationId` into an HTTP method we need to reset the first
343
+ // character of it back to lowercase so end up with `getBuster`, not `getbuster`.
338
344
  operationId = operationId.charAt(0).toUpperCase() + operationId.slice(1);
339
345
  return "".concat(method).concat(operationId);
340
346
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas",
3
- "version": "19.0.2",
3
+ "version": "19.0.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)",
package/src/index.ts CHANGED
@@ -670,6 +670,11 @@ export default class Oas {
670
670
  const paths: Record<string, Record<RMOAS.HttpMethods, Operation | Webhook>> = {};
671
671
 
672
672
  Object.keys(this.api.paths ? this.api.paths : []).forEach(path => {
673
+ // If this is a specification extension then we should ignore it.
674
+ if (path.startsWith('x-')) {
675
+ return;
676
+ }
677
+
673
678
  paths[path] = {} as Record<RMOAS.HttpMethods, Operation | Webhook>;
674
679
 
675
680
  // Though this library is generally unaware of `$ref` pointers we're making a singular
@@ -310,7 +310,9 @@ export default function getParametersAsJSONSchema(
310
310
  // Parameter descriptions don't exist in `current.schema` so `constructSchema` will never
311
311
  // have access to it.
312
312
  if (current.description) {
313
- schema.description = current.description;
313
+ if (!isPrimitive(schema)) {
314
+ schema.description = current.description;
315
+ }
314
316
  }
315
317
 
316
318
  prev[current.name] = schema;
package/src/operation.ts CHANGED
@@ -360,18 +360,26 @@ export default class Operation {
360
360
  operationId = sanitize(operationId);
361
361
  }
362
362
 
363
+ // Never start with a number.
364
+ operationId = operationId.replace(/^[0-9]/g, match => `_${match}`);
365
+
366
+ // Ensure that the first character of an `operationId` is always lowercase.
367
+ operationId = operationId.charAt(0).toLowerCase() + operationId.slice(1);
368
+
363
369
  // If the generated `operationId` already starts with the method (eg. `getPets`) we don't want
364
370
  // to double it up into `getGetPets`.
365
371
  if (operationId.startsWith(method)) {
366
372
  return operationId;
367
373
  }
368
374
 
369
- // If this operation already has an operationId and we just cleaned it up then we shouldn't
375
+ // If this operation already has an `operationId` and we just cleaned it up then we shouldn't
370
376
  // prefix it with an HTTP method.
371
377
  if (this.hasOperationId()) {
372
378
  return operationId;
373
379
  }
374
380
 
381
+ // Because we're merging the `operationId` into an HTTP method we need to reset the first
382
+ // character of it back to lowercase so end up with `getBuster`, not `getbuster`.
375
383
  operationId = operationId.charAt(0).toUpperCase() + operationId.slice(1);
376
384
  return `${method}${operationId}`;
377
385
  } else if (this.hasOperationId()) {