swagger-api / swagger-api/swagger-codegen

[Java] Create public variables for endpoints

Open
#9,589 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

Please create public static final variables for endpoints. For example currently we have this:

@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2019-07-22T09:19:43.787+02:00[Africa/Harare]")
@Api(value = "stuff", description = "the stuff API")
public interface StuffApi {

@ApiOperation(value = "Get stuff", nickname = "getStuff", notes = "Get stuff, response = Stuff.class, tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "good stuff", response = StuffList.class),
@RequestMapping(value = "/stuff" ...

This is ok, but if I write a integration test I have to do this:

stubFor(post(urlEqualTo("/stuff"))

Swagger-codegen version

3

Suggest a fix/enhancement

@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2019-07-22T09:19:43.787+02:00[Africa/Harare]")
@Api(value = "stuff", description = "the stuff API")
public interface StuffApi {
public static final String STUFF = "/stuff";

@ApiOperation(value = "Get stuff", nickname = "getStuff", notes = "Get stuff, response = Stuff.class, tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "good stuff", response = StuffList.class),
@RequestMapping(value =STUFF ...

}

And now my test looks like this:

stubFor(post(urlEqualTo(STUFF))..

Which means I can with an IDE easily go to the implementation (and not do a Search through entire codebase for the endpoint)

Thanks

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 tracing the Java SpringCodegen template that emits StuffApi and its @RequestMapping value; no repository file or test is named in the issue. Verify that generated interfaces expose a public static final endpoint constant and use it in the mapping, then confirm an integration test can reference that constant.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.