Skip to content

[gen] accept OpenAPI "open" types like "any" & "anyObject" #3199

@hochgi

Description

@hochgi

defining "Any" in OpenAPI according to the docs: https://swagger.io/docs/specification/v3_0/data-models/data-types/
Screenshot 2024-11-06 at 8 50 01

These won't work in zio-http-gen.

Expectation:

components:
  schemas:
    Foo:
      type: object
      properties:
        name:
          type: string
        anything: {}

should be rendered as:

case class Foo(name: String, anything: Any)

Also, support "free form objects:
Screenshot 2024-11-06 at 17 33 55
e.g:

components:
  schemas:
    Foo:
      type: object
      properties:
        name:
          type: string
        anything:
          type: object
          additionalProperties: {} # or true, or nothing at all

should be rendered as:

case class Foo(name: String, anything: Map[String, Any])

Also, since Any is not really nice to use, and a more common use case would be to generate with Json:

case class Foo(name: String, anything: Json)

or:

case class Foo(name: String, anything: Json.Obj)

instead of Any/Map[String, Any]

we should add an ability to configure this.
Obviously we need to provide a way to generate a zio-json compatible code,
but perhaps other Json ASTs could be supported (like circe/playjson/etc'…)?
This controls both the code, and the required imports.

default should be Any/Map[String, Any], since it would be surprising to generate code that would fail to compile unless you add a 3rd party dependency.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions