swagger-api / swagger-api/swagger-codegen

Boolean body parameters are not sent when `false`

Open
#5,847 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: JavaScript/Node.js Issue: Invalid spec
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When a body parameter is of type boolean and is false, then parameter does not get sent to the server.

Swagger-codegen version

2.2.2

Swagger declaration file content or url

Example parameter:

      parameters:
        - name: approved
          in: body
          required: true
          description: Whether to approve or disapprove the entity.
          schema:
            type: boolean

If approved is set as true, then the call works perfectly. Otherwise, it fails, since the code (in ApiClient.js in the function callApi) contains the following:

    } else if (bodyParam) {
      request.send(bodyParam);
    }

Of course, bodyParam is false, so it is not sent.

Command line used for generation
java -jar swagger-codegen-cli.jar generate -i ../swagger.yaml -l javascript --additional-properties usePromises=true
Steps to reproduce

Use this Swagger definition:

  /approve:

    post:
      parameters:
        - name: approved
          in: body
          required: true
          schema:
            type: boolean

and see the generated call. Try to use it with both approved as true and as false.

Related issues

Could not find.

Suggest a Fix

If there is a body parameter defined in the swagger definition, always send it. Except, perhaps, if it is undefined.

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 ApiClient.js and the callApi function identified in the issue, then reproduce the generated JavaScript client from the provided Swagger definition with both true and false body values. Done means a false boolean body is sent to the server while an undefined body remains omitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.