Skip to content

Commit 24b7f41

Browse files
fix: const generation for not string types (#2333)
1 parent 9b570a7 commit 24b7f41

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/quicktype-core/src/input/JSONSchemaInput.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -914,10 +914,9 @@ async function addTypesInSchema(
914914

915915
const includeObject = enumArray === undefined && !isConst && (typeSet === undefined || typeSet.has("object"));
916916
const includeArray = enumArray === undefined && !isConst && (typeSet === undefined || typeSet.has("array"));
917-
const needStringEnum =
918-
includedTypes.has("string") &&
919-
enumArray !== undefined &&
920-
enumArray.find((x: any) => typeof x === "string") !== undefined;
917+
const enumArrayHasString =
918+
enumArray !== undefined && enumArray.find((x: any) => typeof x === "string") !== undefined;
919+
const needStringEnum = includedTypes.has("string") && (enumArrayHasString || isConst);
921920
const needUnion =
922921
typeSet !== undefined ||
923922
schema.properties !== undefined ||
@@ -952,7 +951,9 @@ async function addTypesInSchema(
952951
combineProducedAttributes(({ forString }) => forString)
953952
);
954953

955-
if (needStringEnum || isConst) {
954+
if (needStringEnum) {
955+
// FIXME: Currently isConst only works for string values because the name generation only works with strings
956+
// to fix this issue the cases below have to support all types.
956957
const cases = isConst
957958
? [schema.const]
958959
: ((enumArray as any[]).filter(x => typeof x === "string") as string[]);

0 commit comments

Comments
 (0)