diff --git a/src/NodeParser/MappedTypeNodeParser.ts b/src/NodeParser/MappedTypeNodeParser.ts index 625cee6e6..62cefadc7 100644 --- a/src/NodeParser/MappedTypeNodeParser.ts +++ b/src/NodeParser/MappedTypeNodeParser.ts @@ -4,6 +4,7 @@ import type { NodeParser } from "../NodeParser.js"; import { Context } from "../NodeParser.js"; import type { SubNodeParser } from "../SubNodeParser.js"; import { AnnotatedType } from "../Type/AnnotatedType.js"; +import { AnyType } from "../Type/AnyType.js"; import { ArrayType } from "../Type/ArrayType.js"; import type { BaseType } from "../Type/BaseType.js"; import { DefinitionType } from "../Type/DefinitionType.js"; @@ -55,7 +56,8 @@ export class MappedTypeNodeParser implements SubNodeParser { if ( keyListType instanceof StringType || keyListType instanceof NumberType || - keyListType instanceof SymbolType + keyListType instanceof SymbolType || + keyListType instanceof AnyType ) { if (constraintType?.getId() === "number") { const type = this.childNodeParser.createType( diff --git a/test/valid-data/type-mapped-any/index.test.ts b/test/valid-data/type-mapped-any/index.test.ts new file mode 100644 index 000000000..5e2b60e07 --- /dev/null +++ b/test/valid-data/type-mapped-any/index.test.ts @@ -0,0 +1,4 @@ +import { assertValidSchema } from "../../utils"; +import { test } from "node:test"; + +test("type-mapped-any", assertValidSchema("type-mapped-any", "MyObject")); diff --git a/test/valid-data/type-mapped-any/main.ts b/test/valid-data/type-mapped-any/main.ts new file mode 100644 index 000000000..90a70e9f9 --- /dev/null +++ b/test/valid-data/type-mapped-any/main.ts @@ -0,0 +1 @@ +export type MyObject = Record; diff --git a/test/valid-data/type-mapped-any/schema.json b/test/valid-data/type-mapped-any/schema.json new file mode 100644 index 000000000..cd0c3baa4 --- /dev/null +++ b/test/valid-data/type-mapped-any/schema.json @@ -0,0 +1,12 @@ +{ + "$ref": "#/definitions/MyObject", + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "MyObject": { + "additionalProperties": { + "type": "string" + }, + "type": "object" + } + } +} diff --git a/test/valid-data/type-mapped-template-literal/index.test.ts b/test/valid-data/type-mapped-template-literal/index.test.ts new file mode 100644 index 000000000..09f0ba4bc --- /dev/null +++ b/test/valid-data/type-mapped-template-literal/index.test.ts @@ -0,0 +1,4 @@ +import { assertValidSchema } from "../../utils"; +import { test } from "node:test"; + +test("type-mapped-template-literal", assertValidSchema("type-mapped-template-literal", "MyObject")); diff --git a/test/valid-data/type-mapped-template-literal/main.ts b/test/valid-data/type-mapped-template-literal/main.ts new file mode 100644 index 000000000..17cc9c22c --- /dev/null +++ b/test/valid-data/type-mapped-template-literal/main.ts @@ -0,0 +1,3 @@ +type AorB = "A" | "B"; + +export type MyObject = Record<`letter-${AorB}`, string>; diff --git a/test/valid-data/type-mapped-template-literal/schema.json b/test/valid-data/type-mapped-template-literal/schema.json new file mode 100644 index 000000000..09634fa92 --- /dev/null +++ b/test/valid-data/type-mapped-template-literal/schema.json @@ -0,0 +1,22 @@ +{ + "$ref": "#/definitions/MyObject", + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "MyObject": { + "additionalProperties": false, + "properties": { + "letter-A": { + "type": "string" + }, + "letter-B": { + "type": "string" + } + }, + "required": [ + "letter-A", + "letter-B" + ], + "type": "object" + } + } +}