tsoa icon indicating copy to clipboard operation
tsoa copied to clipboard

Bug on JSDoc tag @author

Open aleneri97 opened this issue 4 years ago • 1 comments
trafficstars

Running tsoa spec with comments contain JSDoc Tag @author, I get the following message:

Generate swagger error.
 Error: tag.comment.startsWith is not a function 
 in 'Controller.function'

Sorting

  • I'm submitting a ...

    • [x] bug report
    • [ ] feature request
    • [ ] support request
  • I confirm that I

    • [x] used the search to make sure that a similar issue hasn't already been submit

Expected Behavior

I was expecting that this tag would be ignored (instead of causing an error) since it doesn't mean anything for Swagger, but it does for JSDoc.

    /**
     * Retrieves a lnumber
     * @param {number} Param 1
     * @returns {number} Value
     * @author Alejandro Neri <[email protected]>
     * @date 2021-09-20
     */
    @Get('/')
    myFun(param) {
        //do something
    }

Current Behavior

Instead of ignoring this tag, the command tsoa spec throws the error:

Generate swagger error.
 Error: tag.comment.startsWith is not a function 
 in 'Controller.function'
    at new GenerateMetadataError ([…]/node_modules/@tsoa/cli/dist/metadataGeneration/exceptions.js:22:28)
    at […]/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:95:23
    at Array.map (<anonymous>)
    at MethodGenerator.buildParameters ([…]/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:88:14)
    at MethodGenerator.Generate ([…]/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:63:31)
    at […]/node_modules/@tsoa/cli/dist/metadataGeneration/controllerGenerator.js:60:58
    at Array.map (<anonymous>)
    at ControllerGenerator.buildMethods ([…]/node_modules/@tsoa/cli/dist/metadataGeneration/controllerGenerator.js:60:14)
    at ControllerGenerator.Generate ([…]/node_modules/@tsoa/cli/dist/metadataGeneration/controllerGenerator.js:49:27)
    at […]/node_modules/@tsoa/cli/dist/metadataGeneration/metadataGenerator.js:236:58

And it doesn't generate the swagger documentation.

Steps to Reproduce

  1. Get your class ready.
  2. Add the JSDoc tag @author Your Name <[email protected]> to the first function of your class to be declared for Swagger file e.g:
     /**
     * Description of your FIRST function
     * @author Your Name <[email protected]>
     */
     @Get('/ep1')
     myFun1(){
         // do something
     }
    
  3. Run tsoe spec to get the Swagger file (as expected).
  4. Add a new function/endpoint with the JSDoc tag @author Your Name <[email protected]>.
     /**
     * Description of your SECOND function
     * @author Your Name <[email protected]>
     */
     @Get('/ep2')
     myFun2(){
         // do something
     }
    
  5. Run tsoe spec.
  6. See terminal to verify that you have the same error and Swagger file hasn't changed.

IMPORTANT: If only the first function/endpoint has declared this tag, tsoe works as expected; the bug happens when I add it to a second function/endpoint or if the only functions with the tag @author is not the first function of the class.

Context (Environment)

Version of the library: 3.11.2 Version of NodeJS: v16.1.0

Please let me know if further details are required. Thanks.

aleneri97 avatar Sep 20 '21 23:09 aleneri97

@aleneri97 can not reproduce with the latest version of code and example from https://github.com/lukeautry/tsoa-example

(I updated package version and code in regards to your report) - it's nice if you can provide minimal (or at least some) environment to reproduce

vvscode avatar Oct 09 '21 15:10 vvscode