Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean body parameters are not sent when false #5847

Open
advance512 opened this issue Jun 14, 2017 · 9 comments
Open

Boolean body parameters are not sent when false #5847

advance512 opened this issue Jun 14, 2017 · 9 comments

Comments

@advance512
Copy link

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.

@wing328
Copy link
Contributor

wing328 commented Jun 16, 2017

@advance512 What does the HTTP request payload look like? I wonder if your definition using body parameters with just a boolean type is correct. Do you mean to use form parameter instead?

Ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameter-object

@advance512
Copy link
Author

Hey @wing328,

Thanks for the reply. What do you mean by "correct definition"? Is the definition not a valid definition of Swagger?

The body is empty, so there is nothing to show.

@wing328
Copy link
Contributor

wing328 commented Jun 19, 2017

If the HTTP request body is empty, why do you need to define a body parameter in your OpenAPI spec?

@ePaul
Copy link
Contributor

ePaul commented Jun 19, 2017

@wing328 As I understand, @advance512 wants to have a body of either true or false. But the generated JS client sents either true or an empty body.

@wing328 wing328 modified the milestones: v2.3.0, v2.2.3 Jul 16, 2017
@wing328
Copy link
Contributor

wing328 commented Jul 16, 2017

@advance512 Without the HTTP request, it would be not easy to understand the problem. Please provide an example so that we can help you out.

@wing328 wing328 closed this as completed Jul 16, 2017
@advance512
Copy link
Author

@wing328, @ePaul got it.

There are two types of HTTP requests made:

If the parameter is false, then the body parameter is not sent, the header 'Content-Length' is set to 0, and there is no body.

If the parameter is true, then the body parameter is sent, the header Content-Length is set to 4, and the body is: true.

You'd expect case 1 to have 'Content-Length' set to 5, and the body to be: false, no?

@wing328 wing328 reopened this Aug 5, 2017
@wing328 wing328 modified the milestones: v2.3.0, v2.4.0 Dec 17, 2017
@advance512
Copy link
Author

@wing328
Any update?

@advance512
Copy link
Author

@wing328
is there anything I can do to help this?

@advance512
Copy link
Author

FYI, this was fixed in:
OpenAPITools/openapi-generator#1432

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants