swagger-api / swagger-api/swagger-codegen

Swagger generated Java Client has no overloaded calls, even though the query parameter is marked as optional

Open
#8,939 1 comment 1 reaction 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

I'm introducing an optional "query parameter" (with default value) for one of my API endpoint ( i.e. /foo2) but hoping that existing API consumers don't have to make any changes in their application when they regenerate the java client stub from the new swagger file.

I was expecting that the generated java client will offer overloaded methods, to operate with and without a method parameter, so that my existing API consumers can work without any changes to their call. At the same time, they can switch to its more generic offering.

public void foo2Get() throws ApiException {
public void foo2Get(String type) throws ApiException {

But it generates ONLY the latter. I don't see the former.

At the same time, generated python client from same swagger throws a var arg and this way it more flexible and hence old and new offerings will work without any issues.

def foo_get(self, **kwargs): 

(swagger sample used: attached)

Description

Is there a way to overcome this limitation with java code generator.

swagger-generator version

swagger 2.0

Swagger declaration file content or url

sample.zip

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 the attached sample.zip and compare the generated Java client methods for the optional query parameter with the expected overloaded calls described in the issue. Trace the Java client generation path and determine how optional parameters are represented; done means the generated client supports calls with and without that parameter while preserving the existing call form.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
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.