fix(plugin): infer response type for models imported from workspace p… - #4008
Open
thegoldenflow wants to merge 1 commit into
Open
fix(plugin): infer response type for models imported from workspace p…#4008thegoldenflow wants to merge 1 commit into
thegoldenflow wants to merge 1 commit into
Conversation
…ackages The controller visitor bailed whenever the inferred response type resolved through node_modules (e.g. a pnpm-symlinked workspace package), emitting ApiResponse without a type and leaving the operation with no response schema. Remove that guard so control falls through to the existing typeReferenceToIdentifier -> replaceImportPath -> normalizePackagePath chain, aligning the controller response path with the model/property path (nestjs#3798). Fixes nestjs#4006
4 tasks
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.
The controller visitor bailed whenever the inferred response type resolved through
node_modules(e.g. a pnpm-symlinked workspace package), emittingApiResponsewithout atypeand leaving the operation with no response schema. Remove that guard so control falls through to the existingtypeReferenceToIdentifier->replaceImportPath->normalizePackagePathchain, aligning the controller response path with the model/property path (#3798).Fixes #4006
PR Checklist
PR Type
What is the current behavior?
Issue Number: #4006
When a controller method's return type is a DTO imported from a workspace package that resolves through
node_modules(pnpm symlink), the CLI plugin resolves the type name asimport("/abs/path/node_modules/@scope/pkg/dist/index").Dto, hits thetypeName.includes('node_modules')guard inControllerClassVisitor#createTypePropertyAssignment(), and returns early. The generated code isopenapi.ApiResponse({ status: 200 })with notype, so the OpenAPI operation has no response content schema. The DTO's own_OPENAPI_METADATA_FACTORYis unaffected — only the inferred controller response reference is lost.What is the new behavior?
The guard is removed, so the resolved type flows into
typeReferenceToIdentifier->replaceImportPath->normalizePackagePath, which strips thenode_modulesprefix and emits the package specifier. The generated response now carries the type, e.g.openapi.ApiResponse({ status: 200, type: require('@scope/pkg').Dto }), and the operation gets its response schema. This matches how the model/property path already handles workspace-package imports (#3798).Does this PR introduce a breaking change?
Additive to the generated OpenAPI document (response schemas that were previously absent now appear). See Other information for the behavioral scope.
Other information
Scope / tradeoff. Removing the guard means the controller response path now emits a
typefor any return type that resolves throughnode_modules, not only symlinked workspace packages — e.g.StreamableFile,Buffer, or rxjs types would surface a response schema where previously none was emitted. This is the same tradeoff already accepted for the model/property path in #3798; the blast radius is somewhat larger here since controller return types more often reference framework/third-party types. If you'd prefer to avoid broadening the default, I'm happy to gate this behind a newPluginOptionsflag (default off) so workspace-package response types are only referenced when explicitly enabled — just let me know.Testing. Added a #4006-shaped case to
normalize-package-path.spec.tscovering the specifier normalization. The transpile-based plugin unit harness can't reproduce a real pnpmnode_modulessymlink layout, so end-to-end behavior was verified manually against the reporter's minimal reproduction (<PASTE GIST URL FROM #4006>): the generated controller emits the responsetypeas expected. I can follow up with a runtime integration test that materializes a physicalnode_modules/@scope/pkgin a temp dir and asserts the emitted type, if committed end-to-end coverage is preferred.