diff --git a/src/AnnotationsReader/BasicAnnotationsReader.ts b/src/AnnotationsReader/BasicAnnotationsReader.ts index f2d56e7a3..626688d79 100644 --- a/src/AnnotationsReader/BasicAnnotationsReader.ts +++ b/src/AnnotationsReader/BasicAnnotationsReader.ts @@ -79,11 +79,7 @@ export class BasicAnnotationsReader implements AnnotationsReader { } private parseJsDocTag(jsDocTag: ts.JSDocTagInfo): any { - if (!jsDocTag.text) { - return undefined; - } - - const text = jsDocTag.text?.map((part) => part.text).join(""); + const text = (jsDocTag.text ?? []).map((part) => part.text).join(""); if (BasicAnnotationsReader.textTags.has(jsDocTag.name)) { return text; } else if (BasicAnnotationsReader.jsonTags.has(jsDocTag.name)) { diff --git a/src/AnnotationsReader/ExtendedAnnotationsReader.ts b/src/AnnotationsReader/ExtendedAnnotationsReader.ts index f4a19db80..4edc7ae9e 100644 --- a/src/AnnotationsReader/ExtendedAnnotationsReader.ts +++ b/src/AnnotationsReader/ExtendedAnnotationsReader.ts @@ -63,10 +63,11 @@ export class ExtendedAnnotationsReader extends BasicAnnotationsReader { } const jsDocTag = jsDocTags.find((tag) => tag.name === "asType"); - if (!jsDocTag || !jsDocTag.text) { + if (!jsDocTag) { return undefined; } - return { type: jsDocTag.text[0].text }; + const text = (jsDocTag.text ?? []).map((part) => part.text).join(""); + return { type: text }; } } diff --git a/test/valid-data-other.test.ts b/test/valid-data-other.test.ts index 130835ac3..af2601aed 100644 --- a/test/valid-data-other.test.ts +++ b/test/valid-data-other.test.ts @@ -70,6 +70,12 @@ describe("valid-data-other", () => { ]) ); + it("annotation-empty-basic", assertValidSchema("annotation-empty", "MyObject", "basic", ["customEmptyAnnotation"])); + it( + "annotation-empty-extended", + assertValidSchema("annotation-empty", "MyObject", "extended", ["customEmptyAnnotation"]) + ); + it("nullable-null", assertValidSchema("nullable-null", "MyObject")); it("undefined-alias", assertValidSchema("undefined-alias", "MyType")); diff --git a/test/valid-data/annotation-empty/main.ts b/test/valid-data/annotation-empty/main.ts new file mode 100644 index 000000000..3cab0c315 --- /dev/null +++ b/test/valid-data/annotation-empty/main.ts @@ -0,0 +1,4 @@ +/** + * @customEmptyAnnotation + */ +export interface MyObject {} diff --git a/test/valid-data/annotation-empty/schema.json b/test/valid-data/annotation-empty/schema.json new file mode 100644 index 000000000..163ea704c --- /dev/null +++ b/test/valid-data/annotation-empty/schema.json @@ -0,0 +1,11 @@ +{ + "$ref": "#/definitions/MyObject", + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "MyObject": { + "customEmptyAnnotation": "", + "additionalProperties": false, + "type": "object" + } + } +}