andyglow / scala-jsonschema

Scala JSON Schema
Other
122 stars 38 forks source link

@discriminatorKey doesn't work on case objects in ADTs #293

Open gabrieljones opened 1 year ago

gabrieljones commented 1 year ago

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:

gabrieljones commented 1 year ago

this may be a dupe of #291

gabrieljones commented 1 year ago

Is there already a feature request related to producing a const instead of a single value enum on the descriminator?

andyglow commented 1 year ago

nope, I don't think so. Please file a new one

gabrieljones commented 1 year ago

nope, I don't think so. Please file a new one

https://github.com/andyglow/scala-jsonschema/issues/294