diff --git a/src/Utils/removeUnreachable.ts b/src/Utils/removeUnreachable.ts index 430ccb1ed..479c99d89 100644 --- a/src/Utils/removeUnreachable.ts +++ b/src/Utils/removeUnreachable.ts @@ -39,7 +39,7 @@ function addReachable( } } else if (definition.not) { addReachable(definition.not, definitions, reachable); - } else if (definition.type === "object") { + } else if (definition.type?.includes("object")) { for (const prop in definition.properties || {}) { const propDefinition = definition.properties![prop]; addReachable(propDefinition, definitions, reachable); @@ -49,7 +49,7 @@ function addReachable( if (additionalProperties) { addReachable(additionalProperties, definitions, reachable); } - } else if (definition.type === "array") { + } else if (definition.type?.includes("array")) { const items = definition.items; if (Array.isArray(items)) { for (const item of items) { diff --git a/test/valid-data-annotations.test.ts b/test/valid-data-annotations.test.ts index 4cead7918..ffa9e1ba1 100644 --- a/test/valid-data-annotations.test.ts +++ b/test/valid-data-annotations.test.ts @@ -73,4 +73,6 @@ describe("valid-data-annotations", () => { it("annotation-writeOnly", assertValidSchema("annotation-writeOnly", "MyObject", "basic")); it("annotation-union-if-then", assertValidSchema("annotation-union-if-then", "Animal", "basic")); + + it("annotation-nullable-definition", assertValidSchema("annotation-nullable-definition", "MyObject", "extended")); }); diff --git a/test/valid-data/annotation-nullable-definition/main.ts b/test/valid-data/annotation-nullable-definition/main.ts new file mode 100644 index 000000000..b78627f98 --- /dev/null +++ b/test/valid-data/annotation-nullable-definition/main.ts @@ -0,0 +1,10 @@ +export class Definition { + name: string +} + +export class MyObject { + /** + * @nullable + */ + optional?: Definition[] +} diff --git a/test/valid-data/annotation-nullable-definition/schema.json b/test/valid-data/annotation-nullable-definition/schema.json new file mode 100644 index 000000000..217292f05 --- /dev/null +++ b/test/valid-data/annotation-nullable-definition/schema.json @@ -0,0 +1,33 @@ +{ + "$schema":"http://json-schema.org/draft-07/schema#", + "$ref":"#/definitions/MyObject", + "definitions":{ + "MyObject":{ + "type":"object", + "properties":{ + "optional":{ + "type":[ + "array", + "null" + ], + "items":{ + "$ref":"#/definitions/Definition" + } + } + }, + "additionalProperties":false + }, + "Definition":{ + "type":"object", + "properties":{ + "name":{ + "type":"string" + } + }, + "required":[ + "name" + ], + "additionalProperties":false + } + } +}