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

union type – complex types (collection []) is accepted but not supported #785

Open
mkows opened this issue Apr 8, 2019 · 0 comments
Open

Comments

@mkows
Copy link
Member

mkows commented Apr 8, 2019

Currently the below api.json definition is accepted by apibuilder:

  "unions": {
    "item_state": {
      "discriminator": "type",
      "types": [
        { "type": "t1" },
        { "type": "[t2]" }    // <-- NOTE a collection
      ]
    }
  },

where t1, t2 are e.g. enums or models or primitive types.

However, then when Scala code is generated (Play, http4s), it fails with Generator failed with HTTP 500: Unsupported response code[500]. Expected: 200, 409.

Reproduced locally for
https://app.apibuilder.io/michal/playground-api/0.0.3-dev
and the stack trace is

15:12:29.513 [application-akka.actor.default-dispatcher-3] ERROR application - java.lang.RuntimeException: illegal container type List(Enum(Namespaces(io.github.mkows.playground.api.v0),ItemStateFailedCause)) encountered in union [item_state_failed_cause]
java.lang.RuntimeException: illegal container type List(Enum(Namespaces(io.github.mkows.playground.api.v0),ItemStateFailedCause)) encountered in union [item_state_failed_cause]
    at scala.sys.package$.error(package.scala:30)
    at scala.generator.ScalaUnionType$.apply(ScalaService.scala:185)
    at scala.generator.ScalaUnion.$anonfun$types$1(ScalaService.scala:125)
    at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:237)
    at scala.collection.Iterator.foreach(Iterator.scala:941)
    at scala.collection.Iterator.foreach$(Iterator.scala:941)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1429)
    at scala.collection.IterableLike.foreach(IterableLike.scala:74)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
    at scala.collection.TraversableLike.map(TraversableLike.scala:237)
    at scala.collection.TraversableLike.map$(TraversableLike.scala:230)
    at scala.collection.AbstractTraversable.map(Traversable.scala:108)
    at scala.generator.ScalaUnion.<init>(ScalaService.scala:125)
    at scala.generator.ScalaService.$anonfun$unions$2(ScalaService.scala:36)
    at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:237)

(btw. prev version w/o an array union type works just fine 0.0.2-dev).

Docs:
https://app.apibuilder.io/doc/apiJson#union says for Union Type > type

type specifies the type to include in this union type. Acceptable values include the name of either an enum, a model, or a (primitive type).

So complex type (collection, map) such be rejected (as per current apibuilder docs) when such api.json is uploaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant