scala-jsonschema
scala-jsonschema copied to clipboard
title not rendered in Enumeratum-derived String Enums
Describe the bug
If I create an Enumeratum Enum, and use either the @title annotation or withTitle directly on the schema, the title is not shown in the rendered JSON Schema.
To Reproduce
Welcome to Scala 2.12.15 (OpenJDK 64-Bit Server VM, Java 11.0.15).
Type in expressions for evaluation. Or try :help.
scala> import enumeratum.Enum
import enumeratum.Enum
scala> import enumeratum.EnumEntry
import enumeratum.EnumEntry
scala> import json.schema._
import json.schema._
scala> :paste
// Entering paste mode (ctrl-D to finish)
@title("foo")
sealed trait Foo extends EnumEntry
object Foo extends Enum[Foo] {
val values = findValues
case object Bar extends Foo
case object Baz extends Foo
import com.github.andyglow.jsonschema.EnumeratumSupport._
implicit val jsonSchema = json.Json.schema[Foo]
}
// Exiting paste mode, now interpreting.
defined trait Foo
defined object Foo
scala> println(Foo.jsonSchema)
enum[string]("Bar","Baz") title=`foo`
scala> import com.github.andyglow.jsonschema.AsCirce._
import com.github.andyglow.jsonschema.AsCirce._
scala> import json.schema.Version._
import json.schema.Version._
scala> Foo.jsonSchema.asCirce(Draft04()).spaces2
res1: String =
{
"$schema" : "http://json-schema.org/draft-04/schema#",
"type" : "string",
"enum" : [
"Bar",
"Baz"
]
}
Expected behavior I expect the output to be
{
"$schema" : "http://json-schema.org/draft-04/schema#",
"type" : "string",
"title": "foo",
"enum" : [
"Bar",
"Baz"
]
}
Actual results See above.
Versions:
- 0.7.8
- 2.12.15
Additional context
I tried additional Draft versions, all behave the same. I had a look at json-schema.org and didn't see anything that suggested the title shouldn't be there. Using an app like http://json-schema.app, the title attribute is used if I manually add it.
Hello, @dvgica.. yup.. this seems like a bug Fill free to submit PR, if anything