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

NullPointerException on swagger creation #814

Open
kalirus opened this issue Dec 2, 2022 · 0 comments
Open

NullPointerException on swagger creation #814

kalirus opened this issue Dec 2, 2022 · 0 comments

Comments

@kalirus
Copy link

kalirus commented Dec 2, 2022

Swagger creation fails with NullPointerException if one class has reference to itself, for example:

  case class ClassA(name: String, parent: Option[ClassA])

Full test case:

import derevo.circe.{decoder, encoder}
import derevo.derive
import ru.tinkoff.tschema.swagger.{MkSwagger, Swagger}
import ru.tinkoff.tschema.syntax._

object definitions {

  @derive(encoder, decoder, Swagger)
  case class ClassA(name: String, parent: Option[ClassA])

  def api = tagPrefix("module") |> (operation("test") |> get |> complete[ClassA])
}

object TestModule {

  import definitions._

  trait ModuleApi {
    def test: ClassA
  }

  object ModuleApiImpl extends ModuleApi {
    override def test: ClassA = {
      ClassA(
        name = "John Doe",
        parent = Some(ClassA(
          name = "John Doe Sr.",
          parent = None)
        )
      )
    }
  }

  def swagger = MkSwagger(api)
}

object Test {

  def main(args: Array[String]): Unit = {
    TestModule.swagger // throw java.lang.NullPointerException: Cannot invoke "ru.tinkoff.tschema.swagger.SwaggerTypeable.typ()" because the return value of "shapeless.Lazy.value()" is null
  }
}

The problem occurred when moving from older version 0.10.6 to latest 0.15.2 (reproduces on 0.15.2, didn't reproduce on 0.10.6)

Java 17.0.1, Scala 2.13.10

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

No branches or pull requests

1 participant