Skip to content

codegen: handle recursive schema defns in scala 3 #4671

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

Merged
merged 1 commit into from
Jun 26, 2025

Conversation

hughsimpson
Copy link
Contributor

@hughsimpson hughsimpson commented Jun 25, 2025

Supports deriving schemas for recursive schema definitions in scala 3.

Without this change, the code will hang eternally at runtime. This appears to be because, when declared as a lazy val, the tapir schema for a recursive struct enters some infinite loop. def declarations have no such issues; however lazy val is, probably, preferable for most cases becase the schema only needs to be evaluated once, even if used in multiple locations - so there's a little extra complexity in the generation now, so that we only declare the schemas as defs when they're recursive (or part of a mutually-recursive set of defns, which had the same issue).

I guess it'd be nicer to fix the 'root issue' with lazy val schema declarations, but that's probably some magnolia issue that I have not the wit to fix, and this approach does well enough.


"schemas generated for recursive types are ok" in {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a sense, this test is redundant, since the scripted tests will just timeout on the run stage without the fix. But tests are still nice, aren't they?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are :)

@hughsimpson
Copy link
Contributor Author

Test failure is unrelated (HTTP/1.1 header parser received no bytes in Http4sServerTest, untouched by these changes)

@adamw
Copy link
Member

adamw commented Jun 26, 2025

Yeah that's a known limitation (https://tapir.softwaremill.com/en/latest/endpoint/schemas.html#derivation-for-recursive-types). Keeping compatibility between Scala 2 & Scala 3 isn't always that easy ;)

@adamw adamw merged commit 0459f70 into softwaremill:master Jun 26, 2025
26 of 27 checks passed
@hughsimpson hughsimpson deleted the recursive_schema_defns branch June 26, 2025 17:32
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

Successfully merging this pull request may close these issues.

2 participants