is there any gradle plugins to generate POKOs from...
# gradle
c
is there any gradle plugins to generate POKOs from a JSON Schema file? I found one, but the documentation is lacking a usable example to learn from and following the README has resulted in 0 classes being generated with no meaningful log messages
a
Have you been able to find any tool that can generate Kotlin from a JsonSchema? I ask because if it exists, then you could define a custom Gradle Exec task to run it on demand.
c
the gradle plugin wraps a library written by the same guy that does that
I think he might have a little bit of a monopoly on the situation as it stands
a
I think monopoly is an unfair word blob sweat smile
c
the reason I'm going down this route is because I'm using OpenAPI spec code generation currently but can't seem to configure it in a way i want (I only want the POKOs)
they're definitely a nomad in this space at least
first PR I'll be raising is a functional example project if I get it working 😂
👍 1
a
yeah, I remember looking into some sort of language-independent schema-based code generation a while ago, and coming up short. Which I found really surprising - it's such a common problem, and (in principle) an easy one to 'solve'
c
I'm hesitant to roll my sleeves up, but I'm getting there
a
related thread about OpenAPI generation from a few months ago: https://kotlinlang.slack.com/archives/C0B8RC352/p1681213282825509
are you in control of the OpenAPI schema? As in, could you use something (e.g. http4k) to generate the schema, in a Kotlin-first approach?
c
the service we're going to be integrating against has an OpenAPI schema I believe, I've been able to generate some model classes (woo!) but they come with an infrastructure package I don't want or need (boo!) Unfortunately I don't think I can weave any http4k into this, I'm making a client to the services, not the services themselves. Though I'm looking for a reason to use http4k in production!
a
an infrastructure package
as in the generator creates a HTTP server/client cruft, while you just want the data classes?
c
bingo
a
ahh okay, and which generator are you using?
c
id("org.openapi.generator") _version_ "5.1.1"
a
iirc that has an option to only generate the data classes
c
I feel like an idiot, but I can't find anything that seems to do that
a
I'm pretty sure this is it https://openapi-generator.tech/docs/customization/#selective-generation
Copy code
# generate only models
--global-property models
I only tried using OpenAPI Generator once as a demo, but never had a chance to use it in anger
c
well I'm very angry so let's go! 😄 I'll see if I can figure out how to use those global properties in the gradle plugin
😄 1
gnarly:
Copy code
openApiGenerate {
   ...
   globalProperties.put("models", "") // Generate only models
   ...
}
👏 1
c
This intellij plugin is pretty nice. I’ve used it for converting raw JSON responses into models, but it looks like it should support JSONSchema as well