javaopenapi-generator

How to remove ApiUtil.java from openApi geneate task with openapi-generator-gradle-plugin:4.3.0


I have am using openapi-generator-gradle-plugin:4.3.0 to generate the api and models from a openApi-generate.yaml file. I have set skipDefaultInterface: "true" in configOptions, the default implementation of interfaces is not generated and ApiUtil.java is not used anywhere. (The default implementations used ApiUtil.java)

What I want is to remove (disable the generation of) ApiUtil.java from generated_sources, as it is not used in code, and its default code is creating security-issues in pipeline as well.

What I have tried: I have tried adding different options::

  1. supportingFilesConstrainedTo = []
  2. supportingFiles = ""
  3. supportingFilesToGenerate = ""
  4. apiFilesConstrainedTo = []

But I haven't been able to remove this file from being generated. I went through this: OpenApi generation Customization, but looks like it is not applicable for the given version.

Current gradle buildscript looks as:

task generateTask(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
    generatorName = "spring"
    inputSpec = "$projectDir/src/main/resources/specs/openApi-generate.yaml"
    outputDir = "$buildDir/generated-sources"
    apiPackage = "com.example.openapi.api"
    modelPackage = "com.example.openapi.model"
    generateModelDocumentation = false
    generateApiDocumentation = false
    generateModelTests = false
    generateApiTests = false
    configOptions = [
        dateLibrary: "java8",
        interfaceOnly: "true",
        serializableModel: "true",
        skipDefaultInterface: "true"
    ]
}

Solution

  • Answering my own question. I had to do following things:

    1. Increase Open Api version in build.gradle. This is important becuase it was not supported in older versions:

    id "org.openapi.generator" version 5.3.1

    1. Inside build script provide following options
    globalProperties = [
                apis      : ""
    ]