swagger-test-templates icon indicating copy to clipboard operation
swagger-test-templates copied to clipboard

Body parameter

Open bgaluszka opened this issue 8 years ago • 7 comments

Currently this code https://github.com/apigee-127/swagger-test-templates/blob/master/templates/request/post/post.handlebars#L24-L28

        json: {
          {{#each bodyParameters}}
          {{this.name}}: 'DATA GOES HERE'{{#unless @last}},{{/unless}}
          {{/each}}
        }

based on this description

      parameters:
        - name: User
          description: User
          in: body
          required: true
          schema:
            type: object
            required:
              - email
            properties:
              email:
                description: Email
                type: string 
                format: email
                default: [email protected]

generates body that looks like this

{
    "User": {
        'DATA GOES HERE'
    }
}

but I think it should look like this

{
    'DATA GOES HERE'
}

this is because by http://swagger.io/specification/#parameterObject body is The payload that's appended to the HTTP request. Since there can only be one payload, there can only be one body parameter. The name of the body parameter has no effect on the parameter itself and is used for documentation purposes only..

bgaluszka avatar Sep 26 '16 10:09 bgaluszka

Yeah, I agree it looks a bit funny. ATM we are building the ability to include request-data during test generation, so you don't have to see the 'DATA GOES HERE' anymore ;-)

Remco75 avatar Sep 26 '16 17:09 Remco75

Point was that bodyParameters shouldn't be an array, looped through etc. :)

bgaluszka avatar Sep 27 '16 08:09 bgaluszka

check, I think we should fix that. @noahdietz do you have any thought about this? I think we should do #117 first before doing anymore work on the templates, right now it's very frustrating to work on them

Remco75 avatar Sep 27 '16 13:09 Remco75

@Remco75 agreed, #117 should be merged first before addressing this.

This will make for a straight forward change and good test of our workflow after #117 is finished. :)

noahdietz avatar Sep 27 '16 20:09 noahdietz

@bgaluszka - I believe that this has been resolved in #140 . Can you confirm?

baynezy avatar Aug 29 '17 10:08 baynezy

@baynezy unfortunately I don't have that code/spec anymore since we changed our toolkit and moved to swagger 3.0 :/ I've looked on that part of code and it still there https://github.com/apigee-127/swagger-test-templates/blob/master/templates/request/post/post.handlebars#L29-L31, so unless it's not used it's not fixed :)

bgaluszka avatar Aug 29 '17 11:08 bgaluszka

Really, I think the request body should be prepared as an object and just dropped in to the template. Example in a rewrite I'm playing with (excuse the awkward formatting, whitespace in handlebars is annoying).

noahdietz avatar Aug 29 '17 16:08 noahdietz