Surnet / swagger-jsdoc

Generates swagger/openapi specification based on jsDoc comments and YAML files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve Syntax Error reporting

lamuertepeluda opened this issue · comments

Hello and thank you very much for this tool!

I am using it but I found out that it is difficult to find the file that caused a syntax error.

Currently, a syntax error is reported like this:

YAMLSemanticError: Nested mappings are not allowed in compact mappings at line 23, column 25:

                  type: string
                        ^^^^^^…

No idea where this occurred, though! I was using a glob pattern like src/api/**/index.js where I have hundreds of folders with several API definitions per file... You can imagine my frustration!
I had to use the debugger to find it out. Of course this is not the best-comfort solution for an information that is already available to the parser!

Proposed solution

Why don't you include the filePath into the error? The information is already available here https://github.com/Surnet/swagger-jsdoc/blob/master/src/specification.js#L182

Just find a way to include it in the pushed errors https://github.com/Surnet/swagger-jsdoc/blob/master/src/specification.js#L198 and in the throwed errors https://github.com/Surnet/swagger-jsdoc/blob/master/src/specification.js#L264

Should I make a PR or do you prefer to handle this by yourself?

Hi @lamuertepeluda thanks for the issue. Feel free to open a PR and implement this since you are fresh with the main idea of the issue.

I will just ask you to add tests and prints on the final pr.

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.