diff --git a/src/NodeParser/MappedTypeNodeParser.ts b/src/NodeParser/MappedTypeNodeParser.ts index a1603b7b1..9da5ebe42 100644 --- a/src/NodeParser/MappedTypeNodeParser.ts +++ b/src/NodeParser/MappedTypeNodeParser.ts @@ -18,6 +18,7 @@ import { derefAnnotatedType, derefType } from "../Utils/derefType.js"; import { getKey } from "../Utils/nodeKey.js"; import { preserveAnnotation } from "../Utils/preserveAnnotation.js"; import { removeUndefined } from "../Utils/removeUndefined.js"; +import { uniqueTypeArray } from "../Utils/uniqueTypeArray.js"; export class MappedTypeNodeParser implements SubNodeParser { public constructor( @@ -102,8 +103,7 @@ export class MappedTypeNodeParser implements SubNodeParser { } protected getProperties(node: ts.MappedTypeNode, keyListType: UnionType, context: Context): ObjectProperty[] { - return keyListType - .getFlattenedTypes(derefType) + return uniqueTypeArray(keyListType.getFlattenedTypes(derefType)) .filter((type): type is LiteralType => type instanceof LiteralType) .map((type) => [type, this.mapKey(node, type, context)]) .filter((value): value is [LiteralType, LiteralType] => value[1] instanceof LiteralType) diff --git a/test/valid-data-type.test.ts b/test/valid-data-type.test.ts index d91be0ac2..1f2192447 100644 --- a/test/valid-data-type.test.ts +++ b/test/valid-data-type.test.ts @@ -102,6 +102,7 @@ describe("valid-data-type", () => { it("type-mapped-additional-props", assertValidSchema("type-mapped-additional-props", "MyObject")); it("type-mapped-array", assertValidSchema("type-mapped-array", "MyObject")); it("type-mapped-union-intersection", assertValidSchema("type-mapped-union-intersection", "MyObject")); + it("type-mapped-union-union", assertValidSchema("type-mapped-union-union", "MyType")); it("type-mapped-enum", assertValidSchema("type-mapped-enum", "MyObject")); it("type-mapped-enum-optional", assertValidSchema("type-mapped-enum-optional", "MyObject")); it("type-mapped-enum-null", assertValidSchema("type-mapped-enum-null", "MyObject")); diff --git a/test/valid-data/type-mapped-union/main.ts b/test/valid-data/type-mapped-union-union/main.ts similarity index 100% rename from test/valid-data/type-mapped-union/main.ts rename to test/valid-data/type-mapped-union-union/main.ts diff --git a/test/valid-data/type-mapped-union/schema.json b/test/valid-data/type-mapped-union-union/schema.json similarity index 100% rename from test/valid-data/type-mapped-union/schema.json rename to test/valid-data/type-mapped-union-union/schema.json