guardrail-dev / guardrail

Principled code generation from OpenAPI specifications
https://guardrail.dev
MIT License
522 stars 132 forks source link

Odd behavior with OpenAPI v3 specs and form data adding an extra 'body' param #237

Open kelnos opened 5 years ago

kelnos commented 5 years ago

The OpenAPI Form Data examples include type: object when defining schemas for the form parameters. When doing this, however, Guardrail emits the form params, plus an extra body param. Unclear if this is intended (and if leaving out type is correct), or if this is a problem with the OpenAPI parser or with how Guardrail is interpreting the parser's output. For reference, this triggers the issue:

openapi: 3.0.2
info:
  title: Whatever
  version: 1.0.0
paths:
  /foo:
    post:
      operationId: doFoo
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
             type: object
              properties:
                bar:
                  type: integer
                  format: int64
                baz:
                  type: string
      responses:
        '200':
          description: OK
dpblh commented 5 years ago

I hope this helps you. https://github.com/twilio/guardrail/blob/67b94a0f97b6ff7a30d125c393bdb05ad916cc9a/modules/sample/src/main/resources/multipart-form-data.yaml

kelnos commented 5 years ago

@dpblh can you clarify? I wrote that yaml file; not sure how it's relevant to this?

dpblh commented 5 years ago

@kelnos

Including type causes us to emit the three form parameters as expected, but also a fourth body parameter of an uspecified JSON object type.

From the file commentary it follows that by excluding type from yaml file, you can achieve the expected effect. It works for me)

kelnos commented 5 years ago

@dpblh yes, I know. That's the point of this issue; it shouldn't do that. type: object should be fine there.