oas 20.8.2 → 20.8.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>20.8.3 (2023-05-11)</small>
2
+
3
+ * feat: split mixed json schema types with booleans out into a oneOf (#763) ([0e1014a](https://github.com/readmeio/oas/commit/0e1014a)), closes [#763](https://github.com/readmeio/oas/issues/763)
4
+
5
+
6
+
1
7
  ## <small>20.8.2 (2023-05-04)</small>
2
8
 
3
9
  * feat: adding a broken skipped test, retaining soeme more jsonschema props ([94436b8](https://github.com/readmeio/oas/commit/94436b8))
@@ -411,7 +411,7 @@ function toJSONSchema(data, opts) {
411
411
  if (schema.type.length === 1) {
412
412
  schema.type = schema.type.shift();
413
413
  }
414
- else if (schema.type.includes('array') || schema.type.includes('object')) {
414
+ else if (schema.type.includes('array') || schema.type.includes('boolean') || schema.type.includes('object')) {
415
415
  // If we have a `null` type but there's only two types present then we can remove `null`
416
416
  // as an option and flag the whole schema as `nullable`.
417
417
  var isNullable_1 = schema.type.includes('null');
@@ -422,10 +422,11 @@ function toJSONSchema(data, opts) {
422
422
  // If this mixed type has non-primitives then we for convenience of our implementation
423
423
  // we're moving them into a `oneOf`.
424
424
  var nonPrimitives_1 = [];
425
- // Because we're moving an `array` and/or an `object` into a `oneOf` we also want to take
426
- // with it its specific properties that maybe present on our current schema.
425
+ // Because arrays, booleans, and objects are not compatible with any other schem type
426
+ // other than null we're moving them into an isolated `oneOf`, and as such want to take
427
+ // with it its specific properties that may be present on our current schema.
427
428
  Object.entries({
428
- // json-schema.org/understanding-json-schema/reference/array.html
429
+ // https://json-schema.org/understanding-json-schema/reference/array.html
429
430
  array: [
430
431
  'additionalItems',
431
432
  'contains',
@@ -437,6 +438,10 @@ function toJSONSchema(data, opts) {
437
438
  'prefixItems',
438
439
  'uniqueItems',
439
440
  ],
441
+ // https://json-schema.org/understanding-json-schema/reference/boolean.html
442
+ boolean: [
443
+ // Booleans don't have any boolean-specific properties.
444
+ ],
440
445
  // https://json-schema.org/understanding-json-schema/reference/object.html
441
446
  object: [
442
447
  'additionalProperties',
@@ -471,7 +476,7 @@ function toJSONSchema(data, opts) {
471
476
  });
472
477
  nonPrimitives_1.push(reducedSchema);
473
478
  });
474
- schema.type = schema.type.filter(function (t) { return t !== 'array' && t !== 'object'; });
479
+ schema.type = schema.type.filter(function (t) { return t !== 'array' && t !== 'boolean' && t !== 'object'; });
475
480
  if (schema.type.length === 1) {
476
481
  schema.type = schema.type.shift();
477
482
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas",
3
- "version": "20.8.2",
3
+ "version": "20.8.3",
4
4
  "description": "Comprehensive tooling for working with OpenAPI definitions",
5
5
  "license": "MIT",
6
6
  "author": "ReadMe <support@readme.io> (https://readme.com)",
@@ -456,7 +456,7 @@ export default function toJSONSchema(
456
456
  // We don't need `type: [<type>]` when we can just as easily make it `type: <type>`.
457
457
  if (schema.type.length === 1) {
458
458
  schema.type = schema.type.shift();
459
- } else if (schema.type.includes('array') || schema.type.includes('object')) {
459
+ } else if (schema.type.includes('array') || schema.type.includes('boolean') || schema.type.includes('object')) {
460
460
  // If we have a `null` type but there's only two types present then we can remove `null`
461
461
  // as an option and flag the whole schema as `nullable`.
462
462
  const isNullable = schema.type.includes('null');
@@ -468,10 +468,11 @@ export default function toJSONSchema(
468
468
  // we're moving them into a `oneOf`.
469
469
  const nonPrimitives: any[] = [];
470
470
 
471
- // Because we're moving an `array` and/or an `object` into a `oneOf` we also want to take
472
- // with it its specific properties that maybe present on our current schema.
471
+ // Because arrays, booleans, and objects are not compatible with any other schem type
472
+ // other than null we're moving them into an isolated `oneOf`, and as such want to take
473
+ // with it its specific properties that may be present on our current schema.
473
474
  Object.entries({
474
- // json-schema.org/understanding-json-schema/reference/array.html
475
+ // https://json-schema.org/understanding-json-schema/reference/array.html
475
476
  array: [
476
477
  'additionalItems',
477
478
  'contains',
@@ -484,6 +485,11 @@ export default function toJSONSchema(
484
485
  'uniqueItems',
485
486
  ],
486
487
 
488
+ // https://json-schema.org/understanding-json-schema/reference/boolean.html
489
+ boolean: [
490
+ // Booleans don't have any boolean-specific properties.
491
+ ],
492
+
487
493
  // https://json-schema.org/understanding-json-schema/reference/object.html
488
494
  object: [
489
495
  'additionalProperties',
@@ -521,7 +527,7 @@ export default function toJSONSchema(
521
527
  nonPrimitives.push(reducedSchema);
522
528
  });
523
529
 
524
- schema.type = schema.type.filter(t => t !== 'array' && t !== 'object');
530
+ schema.type = schema.type.filter(t => t !== 'array' && t !== 'boolean' && t !== 'object');
525
531
  if (schema.type.length === 1) {
526
532
  schema.type = schema.type.shift();
527
533
  }