Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip generation of support and metadata files with openAPI Generator and Maven?

I'm converting a swagger file into an open API v3 one using the openapi-yaml generator with Maven.

What I would like to do is to put the new file directly into some directory.

However some additional files are generated which I don't need e.g. README.md, .openapi-generator/VERSION, .openapi-generator-ignore

Is it possible to disable this behaviour and generate only the .yaml file?

like image 546
Admit Avatar asked Aug 12 '19 16:08

Admit


2 Answers

It still doesn't look possible directly through the openApiGenerate config. As other suggest it can be done through a script though. As there's no example, here's what I put together by extending the gradle task

openApiGenerate {
    generatorName = "java"
    inputSpec = (String) "$buildDir/openapi.json"
    outputDir =  (String) "$rootDir/generated-client"
    apiPackage = "com.example.client.api"
    modelPackage = "com.example.client.model"
    invokerPackage = "com.example.client.invoker"
}

tasks.openApiGenerate {
    doLast {
        delete (
                "$rootDir/generated-client/.openapi-generator",
                "$rootDir/generated-client/api",
                "$rootDir/generated-client/gradle",
                "$rootDir/generated-client/docs"
        )
    }
}
like image 135
Dan Thomas Avatar answered Nov 19 '22 03:11

Dan Thomas


Yes this is possible using a .openapi-generator-ignore file as documented at:

https://github.com/OpenAPITools/openapi-generator/blob/master/docs/customization.md#ignore-file-format

For example, to skip git_push.sh, one can create a file named .openapi-generator-ignore in the root of the output directory with the contents:

# Prevent generator from creating these files:
git_push.sh

Some good documentation can also be found at:

https://openapi-generator.tech/docs/faq-extending/#how-do-i-skip-files-during-code-generation

like image 1
Troup Avatar answered Nov 19 '22 02:11

Troup