OpenAPITools / OpenAPITools/openapi-generator

[BUG] typescript-angular api.service template contains unused locals

Open
#1,880 9 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

file
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache

contains the below comment
/* tslint:disable:no-unused-variable member-ordering */

attempting to avoid linting errors.

However, this prevents fixers (like prettier-tslint, etc) to actually attempt and fix the the unused local vars issue.

Also note that the specific problem of unused locals will not be avoided if the TS compiler has stricter config that does not allow unused locals.

openapi-generator version

3.3.2

OpenAPI declaration file content or url
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache
/* tslint:disable:no-unused-variable member-ordering */
Suggest a fix

Disabling the tslint rule does nobody a favor as TS can still catch you out.

The fix is to properly handle the conditionals of the template to correctly declare things only when needed.

Workaround

override the template to remove the comment and use a fixer - but this is not ideal

EDIT: override the template to disable TS(provided your TS version supports it)/ESLint/TSLint checks completely as auto-generated code should be ignored from specific codebase rules.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache and inspect its conditionals around declarations that can become unused. Remove the need for the no-unused-variable suppression by declaring locals only when required; done means generated TypeScript Angular services no longer produce unused locals under stricter compiler or lint settings.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.