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

title not rendered in Enumeratum-derived String Enums #268

Open
dvgica opened this issue Jun 14, 2022 · 1 comment
Open

title not rendered in Enumeratum-derived String Enums #268

dvgica opened this issue Jun 14, 2022 · 1 comment
Assignees
Labels

Comments

@dvgica
Copy link

dvgica commented Jun 14, 2022

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.

@andyglow
Copy link
Owner

Hello, @dvgica.. yup.. this seems like a bug
Fill free to submit PR, if anything

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

No branches or pull requests

2 participants