swagger-api / swagger-api/swagger-codegen

[ALL] [3.0] Body param is now first in parameters list, used to be last

Open
#9,103 12 comments 10 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

When an operation has multiple types of parameters, i.e. query and body, the order of these parameters provided to the code generators in 2.x was such that body was last. This resulted in the generated clients to place the body argument after all the query arguments.

Example:

public Artifacts deleteArtifactsInBatch(String projectId, String refId, Artifacts body) throws ApiException {

In 3.0, the order has been changed such that body is first, before query parameters - verified with -DdebugOperations=true.

Example:

public Artifacts deleteArtifactsInBatch(Artifacts body, String projectId, String refId) throws ApiException {

This results in an API breakage in any language where argument order is used.

Swagger-codegen version

3.0.4 and 3.0.5-SNAPSHOT

Swagger declaration file content or url
  /projects/{project_id}/refs/{ref_id}/artifacts:
    parameters:
    - name: "project_id"
      in: "path"
      required: true
      description: "project identifier"
      type: "string"
    - name: "ref_id"
      in: "path"
      required: true
      description: "ref identifier"
      type: "string"
    delete:
      tags:
      - "artifact"
      summary: "Delete artifact(s) in batch"
      description: ""
      operationId: "deleteArtifactsInBatch"
      parameters:
      - in: "body"
        name: "body"
        description: ""
        schema:
          $ref: "#/definitions/Artifacts"
        required: true
Command line used for generation

java -jar swagger-codegen-cli-3.0.4.jar generate -i /path/to/swagger.yaml -l java -o /var/tmp/java-api-client -DdebugOperations=true

Steps to reproduce

See above.

Related issues/PRs
Suggest a fix/enhancement

The ordering of operations.contents.parameters (and perhaps allParams to ease the migration) in 3.0 should be made consistent with that in 2.x, namely putting body last. This should result in code generators for all languages maintaining the same order as it did in 2.x.

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 operations.contents.parameters ordering described in the issue and inspect how allParams is assembled. Reproduce the behavior with the supplied Swagger YAML and the swagger-codegen Java generation command using -DdebugOperations=true. Done means body parameters appear last, matching 2.x, and generated method signatures retain the prior argument order.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.