Skip to content

Commit

Permalink
fix: const generation for not string types (#2333)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBretzigheimer committed Aug 17, 2023
1 parent 987c863 commit 6a2d472
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/quicktype-core/src/input/JSONSchemaInput.ts
Expand Up @@ -914,10 +914,9 @@ async function addTypesInSchema(

const includeObject = enumArray === undefined && !isConst && (typeSet === undefined || typeSet.has("object"));
const includeArray = enumArray === undefined && !isConst && (typeSet === undefined || typeSet.has("array"));
const needStringEnum =
includedTypes.has("string") &&
enumArray !== undefined &&
enumArray.find((x: any) => typeof x === "string") !== undefined;
const enumArrayHasString =
enumArray !== undefined && enumArray.find((x: any) => typeof x === "string") !== undefined;
const needStringEnum = includedTypes.has("string") && (enumArrayHasString || isConst);
const needUnion =
typeSet !== undefined ||
schema.properties !== undefined ||
Expand Down Expand Up @@ -952,7 +951,9 @@ async function addTypesInSchema(
combineProducedAttributes(({ forString }) => forString)
);

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

0 comments on commit 6a2d472

Please sign in to comment.