Skip to content

Commit

Permalink
fix: conditional-generic-default (#1830)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-josendal authored Dec 6, 2023
1 parent f5cb7c0 commit 8bff094
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Utils/nodeKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions test/valid-data-other.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
5 changes: 5 additions & 0 deletions test/valid-data/generic-default-conditional/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type MyObject = ConditionalGeneric;

export type ConditionalGeneric<T = string extends 'foo' ? 'bar' : 'baz'> = {
foo: T;
}
22 changes: 22 additions & 0 deletions test/valid-data/generic-default-conditional/schema.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}

0 comments on commit 8bff094

Please sign in to comment.