Skip to content

Generated controllers can import unused decorators/empty constructor. #3335

@evantrimboli

Description

@evantrimboli

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

See here: https://github.com/strongloop/loopback-next/blob/72cb8aafad31588deff96fb1af6d33fa03fe5fd5/packages/cli/generators/openapi/templates/src/controllers/controller-template.ts.ejs#L2

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions