osury 0.7.0 → 0.7.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.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "osury",
3
3
  "type": "module",
4
4
  "description": "Generate ReScript types with Sury schemas from OpenAPI specifications",
5
- "version": "0.7.0",
5
+ "version": "0.7.1",
6
6
  "license": "MIT",
7
7
  "bin": {
8
8
  "osury": "./bin/osury.mjs"
@@ -251,6 +251,23 @@ function isRefOnlyUnion(types) {
251
251
  });
252
252
  }
253
253
 
254
+ function isPrimitiveOnlyUnion(types) {
255
+ return types.every(t => {
256
+ if (typeof t === "object") {
257
+ return false;
258
+ }
259
+ switch (t) {
260
+ case "String" :
261
+ case "Number" :
262
+ case "Integer" :
263
+ case "Boolean" :
264
+ return true;
265
+ default:
266
+ return false;
267
+ }
268
+ });
269
+ }
270
+
254
271
  function generateInlineRecord(refName, schemasDict) {
255
272
  let other = schemasDict[refName];
256
273
  if (other !== undefined) {
@@ -566,12 +583,19 @@ function generateTypeDefWithSkipSet(namedSchema, _skipSet, schemasDict) {
566
583
  @schema
567
584
  type ` + typeName + ` = ` + variantBody;
568
585
  }
569
- let variantBody$1 = generateVariantBody(types$1);
570
- return `@genType
586
+ if (isPrimitiveOnlyUnion(types$1)) {
587
+ let variantBody$1 = generateVariantBody(types$1);
588
+ return `@genType
571
589
  @tag("_tag")
572
590
  @unboxed
573
591
  @schema
574
592
  type ` + typeName + ` = ` + variantBody$1;
593
+ }
594
+ let variantBody$2 = generateVariantBody(types$1);
595
+ return `@genType
596
+ @tag("_tag")
597
+ @schema
598
+ type ` + typeName + ` = ` + variantBody$2;
575
599
  }
576
600
  let typeBody = generateType(namedSchema.schema);
577
601
  return `@genType
@@ -645,6 +669,7 @@ export {
645
669
  generateUnion,
646
670
  hasUnion,
647
671
  isRefOnlyUnion,
672
+ isPrimitiveOnlyUnion,
648
673
  generateInlineRecord,
649
674
  generateInlineVariantBody,
650
675
  getUnionName,