Class GenerateTask

  • All Implemented Interfaces:
    kotlin.Comparable , org.gradle.api.Named , org.gradle.api.Task , org.gradle.api.internal.DynamicObjectAware , org.gradle.api.internal.TaskInternal , org.gradle.api.plugins.ExtensionAware , org.gradle.util.Configurable

    @CacheableTask() 
    public abstract class GenerateTask
    extends DefaultTask
                        

    A task which generates the desired code.

    Example (CLI):

    ./gradlew -q openApiGenerate --input=/path/to/file

    Author:

    Jim Schubert

    • Constructor Detail

      • GenerateTask

        GenerateTask()
    • Method Detail

      • getFs

        @Inject() abstract FileSystemOperations getFs()
      • getLayout

        @Inject() abstract ProjectLayout getLayout()
      • getWorkerIsolation

        @Optional()@Input() abstract Property<String> getWorkerIsolation()

        Controls how the code generation worker is isolated from the Gradle daemon.

        • "process" (default): runs in a separate JVM process. Metaspace is fully isolated from the daemon and freed after the process exits. Gradle reuses the worker process across tasks that share the same classpath, so the JVM startup cost is paid at most once per parallel slot — not once per task. Best for projects with many generation tasks.

        • "classloader": runs inside the Gradle daemon JVM using a separate ClassLoader. No process startup overhead, but each task loads generator classes into the daemon's Metaspace. With many tasks this can exhaust Metaspace. Suitable for projects with very few tasks where the daemon memory budget is not a concern.

      • getMaxWorkerHeapSize

        @Optional()@Input() abstract Property<String> getMaxWorkerHeapSize()

        Maximum heap size for the worker process when workerIsolation is "process" (e.g. "512m", "1g"). Has no effect when workerIsolation is "classloader". When not set, the JVM uses ergonomic defaults (typically based on available system memory). Only set this if you hit OutOfMemoryError during generation of unusually large specs.

      • getVerbose

        @Optional()@Input() abstract Property<Boolean> getVerbose()

        The verbosity of generation

      • getQuiet

        @Optional()@Input() abstract Property<Boolean> getQuiet()

        Whether generation should run in quiet mode.

      • getValidateSpec

        @Optional()@Input() abstract Property<Boolean> getValidateSpec()

        Whether an input specification should be validated upon generation.

      • getGeneratorName

        @Optional()@Input() abstract Property<String> getGeneratorName()

        The name of the generator which will handle codegen. (see "openApiGenerators" task)

      • getSchemaLocation

        @Optional()@InputDirectory()@PathSensitive(value = PathSensitivity.ABSOLUTE) abstract DirectoryProperty getSchemaLocation()

        Optional directory containing additional schema files referenced via $ref in the input specification.

        Declaring this directory tells Gradle to track all files inside it for up-to-date checks. Without it, changes to $ref-referenced schemas will not trigger re-generation because Gradle only watches inputSpec by default.

      • getOutputDir

        @Optional()@OutputDirectory() abstract DirectoryProperty getOutputDir()

        The output target directory into which code will be generated.

      • getInputSpec

        @Optional()@InputFile()@PathSensitive(value = PathSensitivity.RELATIVE) abstract RegularFileProperty getInputSpec()

        The Open API 2.0/3.x specification location.

        Be default, Gradle will treat the openApiGenerate task as up-to-date based only on this file, regardless of changes to any $ref referenced files. Use the inputSpecRootDirectory property to have Gradle track changes to an entire directory of spec files.

      • getInputSpecRootDirectory

        @Optional()@InputDirectory()@PathSensitive(value = PathSensitivity.RELATIVE) abstract DirectoryProperty getInputSpecRootDirectory()

        Local root folder with spec files.

        By default, a merged spec file will be generated based on the contents of the directory. To disable this, set the inputSpecRootDirectorySkipMerge property.

      • getInputSpecFiles

        @InputFiles()@Optional()@PathSensitive(value = PathSensitivity.RELATIVE) final ConfigurableFileCollection getInputSpecFiles()

        An explicit collection of spec files to merge, in the order they are declared.

        When set, the generator merges exactly these files rather than scanning a directory. Use with mergeMode and mergeConflictStrategy. The merged output is written to mergedFileOutputDir.

        Takes precedence over inputSpecRootDirectory if both are set.

      • getInputSpecFilesOrder

        @Input()@Optional() final List<String> getInputSpecFilesOrder()

        The declared order of inputSpecFiles, tracked as an explicit task input.

        inputSpecFiles is an InputFiles collection, whose up-to-date checks are order-insensitive. Because the merge honors a first-wins/conflict contract that depends on file ordering, this derived ordered list is exposed as an Input so that reordering the declared files invalidates the task and forces a fresh merge instead of reusing a stale merged spec.

      • getMergedFileName

        @Input()@Optional() abstract Property<String> getMergedFileName()

        Name of the file that will contain all merged specs. Defaults to "merged".

      • getMergeMode

        @Input()@Optional() abstract Property<String> getMergeMode()

        How multiple spec files are merged. Accepted values: "REF" (default, original $ref-based shallow merge, backward-compatible) or "DEEP" (full inline merge with component deduplication and conflict detection).

      • getMergeConflictStrategy

        @Input()@Optional() abstract Property<String> getMergeConflictStrategy()

        Strategy when two specs define the same component name or path+method with conflicting definitions. Accepted values: "WARN" (default) or "FAIL". Only applies when mergeMode is "DEEP".

      • getRemoteInputSpec

        @Input()@Optional() abstract Property<String> getRemoteInputSpec()

        The remote Open API 2.0/3.x specification URL location.

      • getTemplateDir

        @Optional()@InputDirectory()@PathSensitive(value = PathSensitivity.RELATIVE) abstract DirectoryProperty getTemplateDir()

        The template directory holding a custom template.

      • getTemplateResourcePath

        @Optional()@Input() abstract Property<String> getTemplateResourcePath()

        A classpath resource path (or file-system directory path) holding custom Mustache templates.

        Takes precedence over templateDir when both are configured. Use this when templates are packaged inside a JAR on the classpath rather than as loose files on disk.

      • getAuth

        @Optional()@Input() abstract Property<String> getAuth()

        Adds authorization headers when fetching the OpenAPI definitions remotely. Pass in a URL-encoded string of name:header with a comma separating multiple values

      • getConfigFile

        @Optional()@InputFile()@PathSensitive(value = PathSensitivity.RELATIVE) abstract RegularFileProperty getConfigFile()

        Path to json configuration file. File content should be in a json format { "optionKey":"optionValue", "optionKey1":"optionValue1"...} Supported options can be different for each language. Run config-help -g {generator name} command for language specific config options.

      • getSkipOverwrite

        @Optional()@Input() abstract Property<Boolean> getSkipOverwrite()

        Specifies if the existing files should be overwritten during the generation.

      • getPackageName

        @Optional()@Input() abstract Property<String> getPackageName()

        Package for generated classes (where supported)

      • getApiPackage

        @Optional()@Input() abstract Property<String> getApiPackage()

        Package for generated api classes

      • getModelPackage

        @Optional()@Input() abstract Property<String> getModelPackage()

        Package for generated models

      • getModelNamePrefix

        @Optional()@Input() abstract Property<String> getModelNamePrefix()

        Prefix that will be prepended to all model names. Default is the empty string.

      • getModelNameSuffix

        @Optional()@Input() abstract Property<String> getModelNameSuffix()

        Suffix that will be appended to all model names. Default is the empty string.

      • getApiNameSuffix

        @Optional()@Input() abstract Property<String> getApiNameSuffix()

        Suffix that will be appended to all api names. Default is the empty string.

      • getTypeMappings

        @Optional()@Input() abstract MapProperty<String, String> getTypeMappings()

        Sets mappings between OpenAPI spec types and generated code types.

      • getAdditionalProperties

        @Optional()@Input() abstract MapProperty<String, Object> getAdditionalProperties()

        Sets additional properties that can be referenced by the mustache templates in the format of name=value,name=value. You can also have multiple occurrences of this option.

      • getServerVariables

        @Optional()@Input() abstract MapProperty<String, String> getServerVariables()

        Sets server variable for server URL template substitution, in the format of name=value,name=value. You can also have multiple occurrences of this option.

      • getLanguageSpecificPrimitives

        @Optional()@Input() abstract ListProperty<String> getLanguageSpecificPrimitives()

        Specifies additional language specific primitive types in the format of type1,type2,type3,type3. For example: String,boolean,Boolean,Double.

      • getOpenapiGeneratorIgnoreList

        @Optional()@Input() abstract ListProperty<String> getOpenapiGeneratorIgnoreList()

        Specifies .openapi-generator-ignore list in the form of relative/path/to/file1,relative/path/to/file2. For example: README.md,pom.xml.

      • getImportMappings

        @Optional()@Input() abstract MapProperty<String, String> getImportMappings()

        Specifies mappings between a given class and the import that should be used for that class.

      • getSchemaMappings

        @Optional()@Input() abstract MapProperty<String, String> getSchemaMappings()

        Specifies mappings between a given schema and the new one.

      • getForcedGenerateSchemas

        @Optional()@Input() abstract ListProperty<String> getForcedGenerateSchemas()

        Specifies schema names that must be generated even when listed in schemaMappings or importMappings.

      • getInlineSchemaOptions

        @Optional()@Input() abstract MapProperty<String, String> getInlineSchemaOptions()

        Key/value options controlling how inline schemas are handled during generation.

        Common keys: RESOLVE_INLINE_ENUMS (promote inline enums to top-level models), ARRAY_ITEMS_SUFFIX, MAP_ITEMS_SUFFIX. Run config-help -g {generatorName} for the full list of supported options.

      • getNameMappings

        @Optional()@Input() abstract MapProperty<String, String> getNameMappings()

        Specifies mappings between the property name and the new name

      • getModelNameMappings

        @Optional()@Input() abstract MapProperty<String, String> getModelNameMappings()

        Specifies mappings between the model name and the new name

      • getEnumNameMappings

        @Optional()@Input() abstract MapProperty<String, String> getEnumNameMappings()

        Specifies mappings between the enum name and the new name

      • getOpenapiNormalizer

        @Optional()@Input() abstract MapProperty<String, String> getOpenapiNormalizer()

        Key/value rules passed to the OpenAPI normalizer, which pre-processes the parsed spec before code generation begins.

        Example rules: REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true, REMOVE_ANYOF_ONEOF_AND_KEEP_PROPERTIES_ONLY=true. See the OpenAPI Generator docs for the full list of normalizer rules.

      • getInvokerPackage

        @Optional()@Input() abstract Property<String> getInvokerPackage()

        Root package for generated code.

      • getGroupId

        @Optional()@Input() abstract Property<String> getGroupId()

        GroupId in generated pom.xml/build.gradle.kts or other build script. Language-specific conversions occur in non-jvm generators.

      • getId

        @Optional()@Input() abstract Property<String> getId()

        ArtifactId in generated pom.xml/build.gradle.kts or other build script. Language-specific conversions occur in non-jvm generators.

      • getVersion

        @Optional()@Input() abstract Property<String> getVersion()

        Artifact version in generated pom.xml/build.gradle.kts or other build script. Language-specific conversions occur in non-jvm generators.

      • getLibrary

        @Optional()@Input() abstract Property<String> getLibrary()

        Reference the library template (sub-template) of a generator.

      • getGitHost

        @Optional()@Input() abstract Property<String> getGitHost()

        Git host, e.g. gitlab.com.

      • getGitUserId

        @Optional()@Input() abstract Property<String> getGitUserId()

        Git user ID, e.g. openapitools.

      • getGitRepoId

        @Optional()@Input() abstract Property<String> getGitRepoId()

        Git repo ID, e.g. openapi-generator.

      • getReleaseNote

        @Optional()@Input() abstract Property<String> getReleaseNote()

        Release note, default to 'Minor update'.

      • getHttpUserAgent

        @Optional()@Input() abstract Property<String> getHttpUserAgent()

        HTTP user agent, e.g. codegen_csharp_api_client, default to 'OpenAPI-Generator/{packageVersion}/{language}'

      • getIgnoreFileOverride

        @Optional()@InputFile()@PathSensitive(value = PathSensitivity.RELATIVE) abstract RegularFileProperty getIgnoreFileOverride()

        Specifies an override location for the .openapi-generator-ignore file. Most useful on initial generation.

      • getApiFilesConstrainedTo

        @Optional()@Input() abstract ListProperty<String> getApiFilesConstrainedTo()

        Defines which API-related files should be generated. This allows you to create a subset of generated files (or none at all).

        This option enables/disables generation of ALL api-related files.

        NOTE: Configuring any one of apiFilesConstrainedTo, modelFilesConstrainedTo, or supportingFilesConstrainedTo results in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation. For more control over generation of individual files, configure an ignore file and refer to it via ignoreFileOverride.

      • getSupportingFilesConstrainedTo

        @Optional()@Input() abstract ListProperty<String> getSupportingFilesConstrainedTo()

        Defines which supporting files should be generated. This allows you to create a subset of generated files (or none at all).

        Supporting files are those related to projects/frameworks which may be modified by consumers.

        NOTE: Configuring any one of apiFilesConstrainedTo, modelFilesConstrainedTo, or supportingFilesConstrainedTo results in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation. For more control over generation of individual files, configure an ignore file and refer to it via ignoreFileOverride.

      • getGenerateModelTests

        @Optional()@Input() abstract Property<Boolean> getGenerateModelTests()

        Defines whether model-related test files should be generated.

        This option enables/disables generation of ALL model-related test files.

        For more control over generation of individual files, configure an ignore file and refer to it via ignoreFileOverride.

      • getGenerateModelDocumentation

        @Optional()@Input() abstract Property<Boolean> getGenerateModelDocumentation()

        Defines whether model-related documentation files should be generated.

        This option enables/disables generation of ALL model-related documentation files.

        For more control over generation of individual files, configure an ignore file and refer to it via ignoreFileOverride.

      • getGenerateApiTests

        @Optional()@Input() abstract Property<Boolean> getGenerateApiTests()

        Defines whether api-related test files should be generated.

        This option enables/disables generation of ALL api-related test files.

        For more control over generation of individual files, configure an ignore file and refer to it via ignoreFileOverride.

      • getGenerateApiDocumentation

        @Optional()@Input() abstract Property<Boolean> getGenerateApiDocumentation()

        Defines whether api-related documentation files should be generated.

        This option enables/disables generation of ALL api-related documentation files.

        For more control over generation of individual files, configure an ignore file and refer to it via ignoreFileOverride.

      • getLogToStderr

        @Optional()@Input() abstract Property<Boolean> getLogToStderr()

        To write all log messages (not just errors) to STDERR

      • getEnablePostProcessFile

        @Optional()@Input() abstract Property<Boolean> getEnablePostProcessFile()

        To enable the file post-processing hook. This enables executing an external post-processor (usually a linter program). This only enables the post-processor. To define the post-processing command, define an environment variable such as LANG_POST_PROCESS_FILE (e.g. GO_POST_PROCESS_FILE, SCALA_POST_PROCESS_FILE). Please open an issue if your target generator does not support this functionality.

      • getSkipValidateSpec

        @Optional()@Input() abstract Property<Boolean> getSkipValidateSpec()

        To skip spec validation. When true, we will skip the default behavior of validating a spec before generation.

      • getGenerateAliasAsModel

        @Optional()@Input() abstract Property<Boolean> getGenerateAliasAsModel()

        To generate alias (array, list, map) as model. When false, top-level objects defined as array, list, or map will result in those definitions generated as top-level Array-of-items, List-of-items, Map-of-items definitions. When true, A model representation either containing or extending the array,list,map (depending on specific generator implementation) will be generated.

      • getConfigOptions

        @Optional()@Input() abstract MapProperty<String, String> getConfigOptions()

        A dynamic map of options specific to a generator.

      • getEngine

        @Optional()@Input() abstract Property<String> getEngine()

        Templating engine: "mustache" (default) or "handlebars" (beta)

      • getCleanupOutput

        @Optional()@Input() abstract Property<Boolean> getCleanupOutput()

        Defines whether the output dir should be cleaned up before generating the output.

      • getDryRun

        @Optional()@Input() abstract Property<Boolean> getDryRun()

        Defines whether the generator should run in dry-run mode.

      • getStrictSpec

        @Optional()@Input() abstract Property<Boolean> getStrictSpec()

        When true, applies strict validation against the OpenAPI specification, failing on any deviation. When not set, any value from configFile is used; the generator's own default is false.

      • getMinimalUpdate

        @Optional()@Input() abstract Property<Boolean> getMinimalUpdate()

        When true, only writes output files that have changed relative to an existing generated output. Reduces unnecessary file churn in version control. When not set, any value from configFile is used; the generator's own default is false.

      • getGenerateRecursiveDependentModels

        @Optional()@Input() abstract Property<Boolean> getGenerateRecursiveDependentModels()

        When true, recursively generates all models that the selected models depend on, even if those dependent models were not explicitly listed for generation. Only relevant when modelFilesConstrainedTo is configured. When not set, any value from configFile is used; the generator's own default is false.

      • set

         final Unit set(RegularFileProperty $self, String path)

        Extension function to allow setting file properties with a String path in Kotlin DSL. Example: inputSpec.set("$rootDir/api.yaml")

      • set

         final Unit set(DirectoryProperty $self, String path)

        Extension function to allow setting directory properties with a String path in Kotlin DSL. Example: outputDir.set("$buildDir/generated")

      • setInputSpecAsString

         final Unit setInputSpecAsString(String path)

        Groovy-compatible setter for inputSpec property. Accepts a String and automatically routes to remote or local file based on URI detection. Clears the opposite property to prevent stale values from taking precedence.