Skip to content

Eliminate intermediary "*Union" wrappers for object-typed oneOf traits #15

Description

@marcprux

The following schema:

{
  "$ref": "#/definitions/FooBar",
  "definitions": {
    "FooBar": {
      "oneOf": [
        { "$ref": "#/definitions/Foo" },
        { "$ref": "#/definitions/Bar" }
      ]
    },
    "Foo": {
      "type": "object",
      "properties": {
        "foo": {
          "type": "string"
        }
      }
    },
    "Bar": {
      "type": "object",
      "properties": {
        "bar": {
          "type": "integer"
        }
      }
    }
  }
}

will yield this:

sealed trait FooBarUnion
case class FooBarFoo(x: Foo) extends FooBarUnion
case class FooBarBar(x: Bar) extends FooBarUnion
case class Foo(foo: Option[String] = None)
case class Bar(bar: Option[Int] = None)

It would be nice if the intermediary wrappers could be eliminated and this could be simplified to:

sealed trait FooBarUnion
case class Foo(foo: Option[String] = None) extends FooBarUnion
case class Bar(bar: Option[Int] = None) extends FooBarUnion

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions