diff --git a/src/Utils/nodeKey.ts b/src/Utils/nodeKey.ts index 5eefa6804..55ef4a923 100644 --- a/src/Utils/nodeKey.ts +++ b/src/Utils/nodeKey.ts @@ -52,5 +52,5 @@ export function getKey(node: Node, context: Context): string { const id = ids.join("-"); const args = context.getArguments(); - return args.length ? `${id}<${args.map((arg) => arg.getId()).join(",")}>` : id; + return args.length ? `${id}<${args.map((arg) => arg?.getId()).join(",")}>` : id; } diff --git a/test/valid-data-other.test.ts b/test/valid-data-other.test.ts index bf5825550..05bbb94ed 100644 --- a/test/valid-data-other.test.ts +++ b/test/valid-data-other.test.ts @@ -63,6 +63,7 @@ describe("valid-data-other", () => { it("generic-anonymous", assertValidSchema("generic-anonymous", "MyObject")); it("generic-recursive", assertValidSchema("generic-recursive", "MyObject")); it("generic-hell", assertValidSchema("generic-hell", "MyObject")); + it("generic-default-conditional", assertValidSchema("generic-default-conditional", "MyObject")); it("generic-default", assertValidSchema("generic-default", "MyObject")); it("generic-nested", assertValidSchema("generic-nested", "MyObject")); it("generic-prefixed-number", assertValidSchema("generic-prefixed-number", "MyObject")); diff --git a/test/valid-data/generic-default-conditional/main.ts b/test/valid-data/generic-default-conditional/main.ts new file mode 100644 index 000000000..665853d17 --- /dev/null +++ b/test/valid-data/generic-default-conditional/main.ts @@ -0,0 +1,5 @@ +export type MyObject = ConditionalGeneric; + +export type ConditionalGeneric = { + foo: T; +} diff --git a/test/valid-data/generic-default-conditional/schema.json b/test/valid-data/generic-default-conditional/schema.json new file mode 100644 index 000000000..83ee90d22 --- /dev/null +++ b/test/valid-data/generic-default-conditional/schema.json @@ -0,0 +1,22 @@ +{ + "$ref": "#/definitions/MyObject", + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "ConditionalGeneric": { + "additionalProperties": false, + "properties": { + "foo": { + "type": "string", + "const": "baz" + } + }, + "required": [ + "foo" + ], + "type": "object" + }, + "MyObject": { + "$ref": "#/definitions/ConditionalGeneric" + } + } +}