can anyone recommend something to generate code fr...
# getting-started
b
can anyone recommend something to generate code from openapi definitions? using the official openapi generator generates code that won't compile
1
r
I'm using official openapi generator gradle plugin just to generate models. I think other things are fairly easy to write manually.
This is my configuration:
Copy code
openApiGenerate {
    generatorName.set("kotlin")
    inputSpec.set("$rootDir/src/main/resources/api.yaml")
    outputDir.set("$rootDir")
    modelPackage.set("my.package.model")
    configOptions.set(
        mapOf(
            "library" to "jvm-ktor",
            "dateLibrary" to "kotlinx-datetime",
            "serializationLibrary" to "kotlinx_serialization",
        )
    )
    globalProperties.set(
        mapOf(
            "models" to "",
            "modelDocs" to "false",
            "modelTests" to "false",
        )
    )
}
b
thank you
I went for multiplatform
ok, jvm ktor also does not compile
image.png
those are models btw
r
It probably depends on the features used in the api description.
b
probably need to fall back on java, but that would mean losing nullability
r
Have you tried validating the api definition?
b
java -jar openapi-generator-cli.jar validate -i api-descriptions/productservice.yml Validating spec (api-descriptions/productservice.yml) Warnings: - Unused model: productTemplateAttributes - Unused model: salePricesData - Unused model: productVariantAttributes - Unused model: productCustomAttributes [info] Spec has 4 recommendation(s).
productservice.yml
r
I think it's just a bug of the kotlin generator 😞
s
We use the
org.openapi.generator
gradle plugin to generate models from our openAPI spec. It's not perfect and I don't trust its generated Client classes, but the Models are good.
h
I've also found the official generator to be too buggy. For us, Fabrikt seems to work better.
👀 1
👍 1
h
I also don’t like the official generator so I wrote my own generator: https://github.com/hfhbd/kfx
1
b
thank you