OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.23k stars 6.43k forks source link

[REQ] Option to automatically delete all files/folders in outputDir for openapi gradle plugin #5869

Open s101d1 opened 4 years ago

s101d1 commented 4 years ago

For openapi-generator-gradle-plugin, could you add option to automatically delete all files and folders in outputDir before generating the code files?

The option can be called "cleanOputputDir" (boolean) or such.

openApiGenerate {
    generatorName = "kotlin"
    inputSpec = "$rootDir/specs/petstore-v3.0.yaml".toString()
    outputDir = "$buildDir/generated".toString()
    apiPackage = "org.openapi.example.api"
    invokerPackage = "org.openapi.example.invoker"
    modelPackage = "org.openapi.example.model"
    modelFilesConstrainedTo = [
            "Error"
    ]
    configOptions = [
        dateLibrary: "java8"
    ]
    cleanOutputDir = true
}
julienb-delia commented 2 years ago

Ideally, we would also need a 2nd parameter (say outputDirPreserveFiles) to provide a list of files to not delete (e.g. Jenkinsfile)

alexeyerm commented 1 year ago

Looks like a good option for any plugin.

mtrakal commented 6 months ago

just use:

tasks.register("openApiClean", Delete::class) {
    delete("${projectDir.path}/src/main/kotlin/org/example/models/dto")
    delete("${projectDir.path}/src/main/kotlin/org/example/api")
}

openApiGenerate {
  dependsOn("openApiClean")
...
}