swagger-api / swagger-api/swagger-codegen

Suggestion: use final in method parameters

Open
#3,008 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

General: Suggestion
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I always make all operation parameters final, I consider it a 'best practice'. It is also recommended in the default checkstyle configuration.

As a justification for it, I came across code like this a couple of years ago:


  class X {
  ...
    private B b;
  ...
    someOperation(B b) {
       // some code
       B x = some transformation that depends on b.
       // some code.
       b = x;   // The intention was this.b = x;
    }
   ...
  }

I spent more than 1/2 an hour tracking the bug, so now I am as strong supporter of final in method parameters.

Suggest a Fix

I suggest to include final in method parameters as a coding convention rule in swagger.

I also like adding checkstyle as part of the build, so it is very easy to fix some convention violations.

All thoughts appreciated.

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 by locating the repository's default Checkstyle configuration and the Java generation templates or build entry points. Determine whether the convention applies to generated Java method parameters and how Checkstyle is integrated; done means the agreed rule is enabled and the affected build or validation path passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.