guardrail-dev / guardrail

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

Unsupported JSON structures in formData fields #154

Open blast-hardcheese opened 5 years ago

blast-hardcheese commented 5 years ago

While working on #148/#150, I discovered that type: object is not supported for formData parameters. I've not needed this feature, but opening it here in case someone else needs it.

Minimal example:

swagger: '2.0'
paths:
  /test:
    put:
      operationId: updateFoo
      consumes:
        - multipart/form-data
      parameters:
        - in: formData
          name: structure
          type: object
          schema:
            $ref: '#/definitions/Foo'
      responses:
        202:
          schema:
            $ref: '#/definitions/Foo'
definitions:
  Foo:
    type: object
    required:
    - name
    properties:
      name:
        type: string

Errors:

[error] .../guardrail/modules/sample/src/main/scala/issues/issue148/client/akkaHttp/Client.scala:60:224: could not find implicit value for parameter ev: issues.issue148.client.akkaHttp.Implicits.Show[io.circe.Json]
[error]       () => List(Some(Multipart.FormData.BodyPart("foo", Formatter.show(foo))), bar.map(v => Multipart.FormData.BodyPart("bar", Formatter.show(v))), structure.map(v => Multipart.FormData.BodyPart("structure", Formatter.show(v)))).flatten.iterator
[error]                                                                                                                                                                                                                                ^
[error] .../guardrail/modules/sample/src/main/scala/issues/issue148/client/http4s/Client.scala:59:210: could not find implicit value for parameter ev: issues.issue148.client.http4s.Implicits.Show[io.circe.Json]
[error] Error occurred in an application involving default arguments.
[error]     val _multipart = Multipart(List(Some(Part.formData[F]("foo", Formatter.show(foo))), bar.map(v => Part.formData[F]("bar", Formatter.show(v))), structure.map(v => Part.formData[F]("structure", Formatter.show(v)))).flatten.toVector)
[error]                                                                                                                                                                                                                  ^
[error] two errors found
[error] (sample / Compile / compileIncremental) Compilation failed
[error] Total time: 18 s, completed Jan 6, 2019 7:10:46 PM
blast-hardcheese commented 5 years ago

Related to #74