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

[BUG] Incorrect schema name for aliased HKT param for map schema #3834

Closed
lgmyrek opened this issue Jun 11, 2024 · 4 comments · Fixed by #3865
Closed

[BUG] Incorrect schema name for aliased HKT param for map schema #3834

lgmyrek opened this issue Jun 11, 2024 · 4 comments · Fixed by #3865
Assignees
Labels
bug Something isn't working

Comments

@lgmyrek
Copy link

lgmyrek commented Jun 11, 2024

Tapir version: 1.10.8

Scala version: 2.13.13

What is the problem?

when aliasing type taking more than 1 parameter, schema for map looses type parameter info.
eg given:
type Tree[A] = A Either Node[A]
final case class Node[A](values: List[A])

endpoint with:
.in(jsonBody[Map[Int, Tree[String]]])

we get docs:

  schemas:
    Map_Int_Either_String:
      title: Map_Int_Either_String

where I would expect:
Map_Int_Either_String_Node_String OR Map_Int_Tree_String

Maybe you can provide code to reproduce the problem?

Additional information

package com.test

import com.test.Defs._
import io.circe.generic.auto._
import sttp.apispec.openapi.circe.yaml.RichOpenAPI
import sttp.tapir.Schema.SName
import sttp.tapir._
import sttp.tapir.docs.openapi.OpenAPIDocsInterpreter
import sttp.tapir.json.circe.jsonBody

import scala.reflect.runtime.universe.{WeakTypeTag, symbolOf}

object Test extends App {

  lazy implicit val mapIntTreeStringSchema: Schema[Map[Int, Tree[String]]] = Schema.schemaForMap(_.toString)

  val endpoint1 = endpoint
    .put
    .name("test1")
    .in("test" / "2")
    .in(jsonBody[Map[Int, Tree[String]]])

  val endpoints = List(endpoint1)

  val yamlString: String = OpenAPIDocsInterpreter()
    .toOpenAPI(endpoints, "test", "v1")
    .toYaml

  println(yamlString)

}

final case class Node[A](values: List[A])

object Defs {
  type Tree[A] = A Either Node[A]

  implicit def nodeSchema[A: Schema: WeakTypeTag]: Schema[Node[A]] = {
    lazy val symbolOfA = symbolOf[A]
    lazy val fullNameOfA = implicitly[Schema[A]].name.map(_.fullName).getOrElse(symbolOfA.fullName)

    Schema
      .derived[Node[A]]
      .name(SName(classOf[Node[A]].getName, List(fullNameOfA)))
  }
}
@lgmyrek
Copy link
Author

lgmyrek commented Jun 11, 2024

image

@kciesielski kciesielski self-assigned this Jun 12, 2024
@kciesielski
Copy link
Member

@lgmyrek This seems to be fixed by #3848, could you verify?

@kciesielski kciesielski added the bug Something isn't working label Jun 17, 2024
@lgmyrek
Copy link
Author

lgmyrek commented Jun 19, 2024

@kciesielski it doesn't, I think the underlying issue is that the method extractTypeArguments (see screenshot) extracts the type argument of the alias and adds it to concrete symbols name

@kciesielski
Copy link
Member

@lgmyrek right, I was checking under Scala 3 and there the derivation works well, but indeed it returns Map_Int_Either_String for Scala 2, working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants