adonis-autoswagger icon indicating copy to clipboard operation
adonis-autoswagger copied to clipboard

Comment parser breaks with numeric literal separators

Open pumpkinlink opened this issue 1 year ago • 4 comments

the comment parser breaks if the controller file has a number with javascript literal number separator (underscore), like 1_000_000 for one million, instead of 1000000. This feature is part of Javascript as of ES2021: https://v8.dev/features/numeric-separators

affected controller example:

export default class ImagemController {

  private readonly pageSize = 10_000 // <------ the JSDoc only works if the underscore is removed

  /**
   * @findByKM
   * @paramQuery id - id do km -  @type(number) @required
   * @paramQuery type - tipo da foto - @type(string)
   */
  async findByKM({ request }: HttpContext) {    
    const page = 1
    const perPage = this.pageSize
    const result = await Imagem.query()
      .where('id_km_trecho_gasoduto', request.qs().id)
      .if(
        request.qs().type === '',
        (query) => query.whereNull('tipo_foto'),
        (query) => query.where('tipo_foto', request.qs()['type'])
      )
      .paginate(page, perPage)
    return result.serialize()
}

this seems to be a limitation in the Esprima library. you can debug the problem by putting a breakpoint in this block inside the tokenize() function in esprima.js

catch (e) {
	  tokenizer.errorHandler.tolerate(e);
}

pumpkinlink avatar Nov 06 '24 17:11 pumpkinlink

related issue: https://github.com/jquery/esprima/issues/1989

pumpkinlink avatar Nov 07 '24 16:11 pumpkinlink

It seems Esprima only supports up to ES2019. And the project is abandoned and scheduled for archival.

There is an older fork called esprima-next with stable ES2022 support, and a more mantained fork by the Eslint team called Espree

pumpkinlink avatar Nov 07 '24 16:11 pumpkinlink

dang! unfortunately nothing I can do here... It's an upstream issue.

I can only mention it in the readme, for others to be aware of

ad-on-is avatar Jan 11 '25 18:01 ad-on-is

Hi @pumpkinlink , I've published a new package to integrate Swagger/OpenAPI into your AdonisJS project easily.

More details: https://github.com/DreamsHive/open-swagger

DeVoresyah avatar Sep 19 '25 08:09 DeVoresyah