Gradle configuration for OpenAPI Generator
Asked Answered
C

1

6

When using OpenAPI generator with Gradle, I would expect to emit the gendered sources to the standard directory used by other source generator plugins. Something like the Maven generated-sources.

So far I haven't been able to do so, particularly to limit the generation to Java source classes instead of a whole “archetype project”.

It seems that the OpenAPI Gradle plugin workflow isn't thought out the same as the Maven one.

Is there a configuration flag to omit generation of all non-java code and to do so in an “generated sources” folder such as /out/production/generated/?

Candycecandystriped answered 13/8, 2019 at 12:21 Comment(2)
There is a ignorefile you an add openapi-generator.tech/docs/customization#ignore-file-formatNilgai
All generators support the outputDir property (equivalent to output in our Maven plugin). The gradle plugin is perhaps "more correct" than the Maven plugin because it uses OpenAPI Generator core's defaults rather than defining others. A common gradle workflow would be to generate to a path relative to the project root, rather than a generated-sources directory. Feel free to open an issue on the repo and the core team will work to align or document this a little better.Lachish
M
9

In case this is of help to anyone, I have built this skeleton of a Gradle and OpenAPI Generator project which generates API and model files directly into the project source file hierarchy.

It uses the following configuration:

openApiGenerate {
    generatorName = "spring"
    inputSpec = "..."
    outputDir = "$projectDir"
    apiPackage = "..."
    modelPackage = "..."
    configOptions = [
            interfaceOnly: "true",
            openApiNullable: "false",
            skipDefaultInterface: "true"
    ]
    globalProperties = [
            apis: "",
            models: ""
    ]
}

The example is here.

Marquet answered 19/8, 2021 at 23:12 Comment(1)
the best tip, this options in configOptions help to get rid from the junk generated by the frameworkScant

© 2022 - 2024 — McMap. All rights reserved.