adonis-autoswagger
adonis-autoswagger copied to clipboard
Comment parser breaks with numeric literal separators
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);
}
related issue: https://github.com/jquery/esprima/issues/1989
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
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
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