Skip to content

Suggestion: populate annotations using comment/JSDoc values #111

@thw0rted

Description

@thw0rted

I see that you can set schema annotations like "description", and "examples" manually using the @JSONSchema decorator, but this information is lost when building a typing (.d.ts) file. For example, if you write

@JSONSchema({description: 'Full name of user'}
@IsString()
@MaxLength(40)
name: string;

the generated .d.ts file just has name: string. On the other hand, if you put the description in a comment (/** Full name of user */) above the property declaration, and set removeComments: false in tsconfig.json, the generated file includes the comment. This allows consumers of the emitted typings to get helpful tooltips in their IDE. Unfortunately, getting the tooltip in both places -- the .d.ts file, and the JSON Schema output -- requires duplicating the annotation in both the JSDoc comment and the JSONSchema decorator.

I don't know if the generator has the full TS AST available to it during schema generation, but if possible, it would be great to pull any matching annotations from JSDoc and set the corresponding values in the emitted schema. I think it would be possible to copy description (from @description tag or just the body of the comment), deprecated, default, and examples.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions