fix(plugin): avoid duplicate keys when auto-generating @ApiOperation#3871
Merged
kamilmysliwiec merged 1 commit intoApr 22, 2026
Merged
Conversation
Member
|
could you resolve conflicts? |
When `introspectComments` is enabled, the plugin unshifts an auto- generated `summary` (or `description`, depending on `controllerKeyOfComment`) onto the @apioperation decorator's argument object. It did not check whether the user had already supplied the same key, so a method annotated as: /** doc-summary */ @apioperation({ summary: 'user-summary' }) was transpiled to: openapi.ApiOperation({ summary: 'doc-summary', summary: 'user-summary' }) producing a duplicate-key object literal. Runtime behaviour happened to be correct (JavaScript picks the last one) but the output is clearly incorrect, trips strict linters, and is inconsistent with how the plugin already handles `description` (via `hasRemarksKey`) and `deprecated` (via `hasDeprecatedKey`). Skip the unshift when the existing @apioperation argument already contains the same key. No behaviour change for the common cases where the user does not explicitly set `summary`/`description`.
09e0f07 to
0afb905
Compare
Contributor
Author
|
Conflicts resolved (rebased onto master). CI re-running. |
Member
|
lgtm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix (plugin / transformer).
What is the current behavior?
When
introspectCommentsis enabled and the user has already suppliedsummary(ordescription, depending oncontrollerKeyOfComment) on an explicit@ApiOperation({...}), the plugin still unshifts an auto-generated key, producing a duplicate-key object literal.Minimal repro controller:
Transpiles to:
Runtime behaviour happens to be correct (JS picks the last duplicate key) but:
description(viahasRemarksKey) anddeprecated(viahasDeprecatedKey) against the exact same scenario.What is the new behavior?
The unshift only runs when the explicit
@ApiOperation({...})argument does not already contain the generated key. So the same input now produces:All other cases are unchanged: empty
@ApiOperation({}), missing decorator,@remarksblocks, and mixedsummary+descriptioncombinations still work exactly as before.Additional context
Added a new fixture
test/plugin/fixtures/app.controller-api-operation-dedupe.tsand a corresponding test incontroller-class-visitor.spec.tscovering both the plain and the@remarks-combined cases. The existingappControllerTextTranspiledsnapshot is untouched because none of its methods override the generated key.