swagger-api / swagger-api/swagger-codegen

Backward compatibility is broken in >=2.3.0 for language 'typescript-fetch'

Open
#11,837 0 comments 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

I've noticed that since commit swagger-codegen generates different APIs for the same swagger.json

Swagger declaration file content or url
{
    "paths": {
        "/list": {
            "get": {
                "operationId": "list_get",
                "parameters": [{ "in": "query", "name": "limit", "type": "integer"}]
            }
        }
    },
    "swagger": "2.0"
}
Command line used for generation
$ mvn clean package # (build v2.2.3 and v2.3.0)
$ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i swagger.json -l typescript-fetch -o /tmp/test

v2.2.3 generates the following method listGet:

export class DefaultApi extends BaseAPI {
    return {
        listGet(params: {  "limit"?: number; }, options?: any) {
            // ...
        }
    }
}

v2.3.0 (or later) generates the following method listGet:

export class DefaultApi extends BaseAPI {
    return {
        public listGet(limit?: number, options?: any) {
            // ...
        }
    }
}

As you can see method listGet has different notations of passing parameters from version to version:

  • v2.2.3 generates methods which accept object with parameters as the first argument (func({ param1: 'arg1', param2: 'arg2', ... }))
  • v2.3.0 generates methods which accept parameters which go one by one as method arguments (func(arg1, arg2, ...rest))
Suggest a fix/enhancement

Use object notation of passing parameters (as in 2.2.3) because API which is generated by >=2.3.0 becomes very inconvenient when the number of parameters grows.
Imagine the case when your method has 10 (or more) optional parameters and you need to pass only the tenth parameter:

func(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, "value");

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 reproducing the change with the supplied swagger.json and the typescript-fetch generator through modules/swagger-codegen-cli. Compare the output from v2.2.3 and v2.3.0, then inspect commit 3ecc374682de4d8ff7dafb27c6f154a801dd94b0 and the generator templates involved. Done means generated methods retain the object-style parameter API and cover the example with optional parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.