Skip to content

Commit

Permalink
fix: JSDoc parser ignores empty annotations (#973)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenlandis-rl committed Oct 5, 2021
1 parent d79836c commit c6d7eab
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/AnnotationsReader/BasicAnnotationsReader.ts
Expand Up @@ -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)) {
Expand Down
5 changes: 3 additions & 2 deletions src/AnnotationsReader/ExtendedAnnotationsReader.ts
Expand Up @@ -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 };
}
}
6 changes: 6 additions & 0 deletions test/valid-data-other.test.ts
Expand Up @@ -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"));
Expand Down
4 changes: 4 additions & 0 deletions test/valid-data/annotation-empty/main.ts
@@ -0,0 +1,4 @@
/**
* @customEmptyAnnotation
*/
export interface MyObject {}
11 changes: 11 additions & 0 deletions 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"
}
}
}

0 comments on commit c6d7eab

Please sign in to comment.