scala-jsonschema icon indicating copy to clipboard operation
scala-jsonschema copied to clipboard

@discriminatorKey doesn't work on case objects in ADTs

Open gabrieljones opened this issue 2 years ago • 4 comments

Describe the bug

To Reproduce

@discriminator("type", phantom = true)
sealed trait Command

object Command {
  @discriminatorKey("m") //WORKS
  case class Move(meters: Int) extends Command
  @discriminatorKey("r") // WORKS
  case class Rotate(degrees: Int) extends Command
  @discriminatorKey("j") // DOES NOT WORK - IGNORED
  case object Jump extends Command
}

Expected behavior

        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "type": {
              "enum": [
                "j"
              ]
            }
          },
          "required": [
            "type"
          ]
        }

Actual results

        {
          "type": "string",
          "enum": [
            "Jump"
          ]
        },

Versions:

  • jsonschema version 0.7.9
  • scala version 2.13.10

gabrieljones avatar Jan 12 '23 23:01 gabrieljones