apigee-127 / swagger-test-templates

Test code generated from Swagger
MIT License
166 stars 58 forks source link

Body parameter #118

Open bgaluszka opened 8 years ago

bgaluszka commented 8 years ago

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: example@example.com

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..

Remco75 commented 8 years ago

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 ;-)

bgaluszka commented 8 years ago

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

Remco75 commented 8 years ago

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

noahdietz commented 8 years ago

@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. :)

baynezy commented 7 years ago

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

bgaluszka commented 7 years ago

@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 :)

noahdietz commented 7 years ago

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).