quicktype-core 23.3.12 → 23.3.14

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.
@@ -780,8 +780,10 @@ function addTypesInSchema(resolver, typeBuilder, references, attributeProducers)
780
780
  const includeArray = enumArray === undefined &&
781
781
  !isConst &&
782
782
  (typeSet === undefined || typeSet.has("array"));
783
+ const enumArrayHasString = (enumArray === null || enumArray === void 0 ? void 0 : enumArray.find((x) => typeof x === "string")) !== undefined;
784
+ const constIsString = isConst && typeof schema.const === "string";
783
785
  const needStringEnum = includedTypes.has("string") &&
784
- (enumArray === null || enumArray === void 0 ? void 0 : enumArray.find((x) => typeof x === "string")) !== undefined;
786
+ (enumArrayHasString || constIsString);
785
787
  const needUnion = typeSet !== undefined ||
786
788
  schema.properties !== undefined ||
787
789
  schema.additionalProperties !== undefined ||
@@ -807,8 +809,13 @@ function addTypesInSchema(resolver, typeBuilder, references, attributeProducers)
807
809
  unionTypes.push(typeBuilder.getPrimitiveType(kind, attributes));
808
810
  }
809
811
  const stringAttributes = (0, TypeAttributes_1.combineTypeAttributes)("union", inferredAttributes, combineProducedAttributes(({ forString }) => forString));
810
- if (needStringEnum || isConst) {
811
- const cases = isConst
812
+ // FIXME: A non-string const never takes this path, so it
813
+ // degrades to its plain primitive type and the literal value is
814
+ // dropped, because enum case name generation only works with
815
+ // strings. To fix this, the cases below have to support all
816
+ // types.
817
+ if (needStringEnum) {
818
+ const cases = constIsString
812
819
  ? [schema.const]
813
820
  : ((_a = enumArray === null || enumArray === void 0 ? void 0 : enumArray.filter((x) => typeof x === "string")) !== null && _a !== void 0 ? _a : []);
814
821
  unionTypes.push(typeBuilder.getStringType(stringAttributes, StringTypes_1.StringTypes.fromCases(cases)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.3.12",
3
+ "version": "23.3.14",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",