Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hochgi opened this issue Nov 6, 2024 · 0 comments
Open

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

hochgi opened this issue Nov 6, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@hochgi
Copy link
Contributor

hochgi commented Nov 6, 2024

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.

@hochgi hochgi added the enhancement New feature or request label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant