loopbackio / loopbackio/loopback-next
Generated controllers can import unused decorators/empty constructor.
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 27
Description
Steps to reproduce
Using the open api generator, generate a controller that does not use any request bodies or does not pass any parameters.
This can be problematic depending on the compiler options, for example having unused parameters. The same could be said for an empty parameterless constructor.
Current Behavior
The param and requestBody decorators are imported in the controller file. An empty constructor is generated.
Expected Behavior
The param and requestBody decorators should not be imported. The constructor should be omitted.
Link to reproduction sandbox
The imports are made unconditionally.
Additional information
win32 x64 12.5.0
├─ @loopback/boot@1.4.4
├─ @loopback/context@1.20.2
├─ @loopback/core@1.8.5
├─ @loopback/http-server@1.4.4
├─ @loopback/metadata@1.2.5
├─ @loopback/openapi-v3@1.7.0
├─ @loopback/repository-json-schema@1.8.0
├─ @loopback/repository@1.8.2
├─ @loopback/rest-explorer@1.2.5
├─ @loopback/rest@1.16.3
├─ @loopback/service-proxy@1.2.5
├─ loopback-connector@4.8.0
├─ loopback-datasource-juggler@4.8.2
Related Issues
N/A
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open packages/cli/generators/openapi/templates/src/controllers/controller-template.ts.ejs, where the issue identifies unconditional imports. Generate a controller with no request bodies or parameters and inspect the emitted controller. Done means unused param/requestBody decorator imports and the empty constructor are omitted; check any generator tests covering this template if present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- backend-api-design, cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100