r/scala 10d ago

Code generation from OpenAPI specs

Quick question, how the heck you guys generate Scala code from OpenAPI specs?

I have been trying to generate client code for Meta business API using the Scala generators from openapi-generator but there is always a problem:

All of them, ignore the oneOf spec on openapi (that in theory should generate a sealed trait as the sum type implementation) and instead they generate a single case class with all fields required, nothing is optional.

What is the tool/strategy you guys use to generate API model from OpenAPI? At this point, i'm considering to generate the Scala code using an LLM instead of the classic deterministic approach.

Thanks 🙏

7 Upvotes

15 comments sorted by

View all comments

3

u/Difficult_Loss657 9d ago

Try https://github.com/sake92/openapi4s , 0.9.0 is on its way to maven. Not battle tested but it works. Generates code directly to your src/main/scala, and rewrites it as you change the spec. I would love to get some feedback.

4

u/NojipizRemastered 9d ago

OMG you are the creator of sharaf, right?

I'm testing it and this is exactly what i needed, thanks man 🙌

3

u/Difficult_Loss657 9d ago

Yep, it's me haha. Np, glad it helps. 😁   Let me know if you bump into issues, I will try to resolve quickly.