softwaremill / softwaremill/tapir

[BUG] Schema derivation for parametrized data

Open
#1,303 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #1319 by @someone — closed without merging
Dominant language
Scala
Stars
1.5k
Forks
468
Avg merge
5h 37m
Merged PRs (30d)
34

Description

Tapir version: 0.18.0-M4

Scala version: 2.12.13

Describe the bug

Schema derived for parametrized case classes is always fixed to a random parameter

How to reproduce?

final case class Items[A](items: List[A], total: Int)
object Items {
  implicit def schema[A: Schema]: Schema[Items[A]]    = Schema.derived[Items[A]]
  implicit def validator[A: Schema]: Validator[Items[A]] = schema.validator
}

Results in the following openapi spec:

    Items_A:
      required:
      - total
      type: object
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/TransactionInfo'
        total:
          type: integer

And then Items_A is referenced not only where Items[TransactionInfo] is used but everywhere Items[X] appears.

Additional information

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the parametrized Items[A] reproduction and inspect how Schema.derived[Items[A]] produces the OpenAPI schema shown. Confirm the behavior across different type arguments, then ensure each Items[X] use receives a schema matching X rather than reusing the first derived parameter; verify the generated OpenAPI references.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.