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

Derived Schema doesn't work with empty case class and case objects

Open IlyaHalsky opened this issue 2 years ago • 1 comments

Describe the bug DerivedSchema doesn't work with case classes without fields and case object types

To Reproduce

abstract class WithSchema[T: DerivedSchema] {
  def schema: Schema[T] = implicitly[DerivedSchema[T]].schema
}

object ExampleApp extends App {


  class MessageSchema extends WithSchema[Message]

  println(
    JsonFormatter.format(
      AsValue.schema(
        new MessageSchema().schema,
        Version.Draft04()
      )
    )
  )
}

case class Test() // Empty case class

case class Message(test: Test)

and second example:

case object Test

case class Message(test: Test.type)

Expected behavior Code runs without any errors Actual results Compiler fails with could not find implicit value for evidence parameter of type json.schema.derived.DerivedSchema[Message] Versions:

  • jsonschema version - 0.7.9
  • scala version - 2.13.10

Additional context First case from what i know is completely valid example for json schema. Second case is stupid, but still :)

Also it would be nice if macros would print some errors into console during compilation stage.

IlyaHalsky avatar Oct 20 '22 09:10 IlyaHalsky

What are use cases for empty case classes and objects that are not part of sum types?

andyglow avatar Oct 22 '22 18:10 andyglow

To be honest with you - never :) Just found randomly and wanted to share. But some compilation errors would be nice.

IlyaHalsky avatar Nov 02 '22 19:11 IlyaHalsky

gotcha. thank you

andyglow avatar Nov 02 '22 21:11 andyglow

closing it now in favor of #291

andyglow avatar Nov 02 '22 21:11 andyglow