You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Swagger CLI Plugin, when using introspectComments feature, it will put the JSDoc comment found on the API Operation (i.e. on the controller method) into ApiOperation decorator metadata.
The issue is that by default, the plugin will populate the description key (i.e. the default value for plugin option controllerKeyOfComment is "description"). However, if you look at the api-operation-explorer.ts file, you will see that when applying this metadata to the controller method we only do const { summary, deprecated, tags } = metadata[key];.
In other words, with default plugin configuration the API Operation comment introspection actually doesn't work!
After spending a few hours on this and understanding the underlying issue, the obvious workaround is to update nest-cli.json file by setting "controllerKeyOfComment": "summary".
By default, these options are set to "description". This means the plugin will assign "Create some resource" to description key on the ApiOperation operator.
So I would expect the behavior to match the docs. Some ways to achieve that:
Update the api operation explorer to also set the description key on operation metadata
Update the default value for controllerKeyOfComment plugin setting to be 'summary' and also update the docs accordingly
Maybe some other combination of the two or something else entirely
Package version
7.1.17
NestJS version
10.3.0
Node.js version
v18.17.1
In which operating systems have you tested?
macOS
Windows
Linux
Other
The default options for the plugin are declared here. This is where the default value of description is coming from.
After that it gets put into metadata, and eventually the api-operation-explorer code will fail to read the description, expecting to get the summary instead.
A quick update. I've started work on this, and while adding a single line of code is easy enough, I'm still figuring out how to update the tests.
I'll update this thread when I've got something to show.
Is there an existing issue for this?
Current behavior
swagger/lib/explorers/api-operation.explorer.ts
Lines 29 to 45 in ed528d4
When using Swagger CLI Plugin, when using
introspectComments
feature, it will put the JSDoc comment found on the API Operation (i.e. on the controller method) intoApiOperation
decorator metadata.The issue is that by default, the plugin will populate the
description
key (i.e. the default value for plugin optioncontrollerKeyOfComment
is"description"
). However, if you look at theapi-operation-explorer.ts
file, you will see that when applying this metadata to the controller method we only doconst { summary, deprecated, tags } = metadata[key];
.In other words, with default plugin configuration the API Operation comment introspection actually doesn't work!
After spending a few hours on this and understanding the underlying issue, the obvious workaround is to update nest-cli.json file by setting
"controllerKeyOfComment": "summary"
.Minimum reproduction code
I hope the link to the "faulty" code is enough
Steps to reproduce
No response
Expected behavior
According to the docs (https://docs.nestjs.com/openapi/cli-plugin#comments-introspection)
So I would expect the behavior to match the docs. Some ways to achieve that:
description
key on operation metadatacontrollerKeyOfComment
plugin setting to be'summary'
and also update the docs accordinglyPackage version
7.1.17
NestJS version
10.3.0
Node.js version
v18.17.1
In which operating systems have you tested?
Other
The default options for the plugin are declared here. This is where the default value of
description
is coming from.swagger/lib/plugin/merge-options.ts
Lines 16 to 25 in ed528d4
And this is where it's being read.
swagger/lib/plugin/visitors/controller-class.visitor.ts
Line 202 in ed528d4
After that it gets put into metadata, and eventually the
api-operation-explorer
code will fail to read the description, expecting to get the summary instead.swagger/lib/explorers/api-operation.explorer.ts
Lines 29 to 45 in ed528d4
The text was updated successfully, but these errors were encountered: