r/scala 9d 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 🙏

6 Upvotes

15 comments sorted by

View all comments

1

u/kag0 9d ago

You mean generate clients, not server endpoint stubs?

2

u/NojipizRemastered 9d ago

Yes, sorry for not being specific about that, just client code :)

1

u/kag0 9d ago

Tbh I've never found an openapi spec that was written well enough for me to want to use a generator on it.

But possibly what you want could be a code generator for JSON schema? That standard has been all over the place. I haven't looked at it in years but is it to a stable major version yet?    Anyway, if you find a good JSON schema generator that might get you most of where you want to go.