1717package org.openapitools.generator.gradle.plugin.extensions
1818
1919import org.gradle.api.Project
20- import org.gradle.api.tasks.Input
21- import org.gradle.api.tasks.Optional
20+ import org.gradle.api.file.DirectoryProperty
21+ import org.gradle.api.file.RegularFileProperty
2222import org.gradle.kotlin.dsl.listProperty
2323import org.gradle.kotlin.dsl.mapProperty
2424import org.gradle.kotlin.dsl.property
@@ -28,7 +28,7 @@ import org.gradle.kotlin.dsl.property
2828 *
2929 * @author Jim Schubert
3030 */
31- open class OpenApiGeneratorGenerateExtension (project : Project ) {
31+ open class OpenApiGeneratorGenerateExtension (private val project : Project ) {
3232 /* *
3333 * The verbosity of generation
3434 */
@@ -47,7 +47,7 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
4747 /* *
4848 * The output target directory into which code will be generated.
4949 */
50- val outputDir = project.objects.property< String > ()
50+ val outputDir: DirectoryProperty = project.objects.directoryProperty ()
5151
5252 /* *
5353 * The Open API 2.0/3.x specification location.
@@ -56,15 +56,15 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
5656 * changes to any $ref referenced files. Use the `inputSpecRootDirectory` property to have Gradle track changes to
5757 * an entire directory of spec files.
5858 */
59- val inputSpec = project.objects.property< String > ()
59+ val inputSpec: RegularFileProperty = project.objects.fileProperty ()
6060
6161 /* *
6262 * Local root folder with spec files.
6363 *
6464 * By default, a merged spec file will be generated based on the contents of the directory. To disable this, set the
6565 * `inputSpecRootDirectorySkipMerge` property.
6666 */
67- val inputSpecRootDirectory = project.objects.property< String > ()
67+ val inputSpecRootDirectory: DirectoryProperty = project.objects.directoryProperty ()
6868
6969 /* *
7070 * Skip bundling all spec files into a merged spec file, if true.
@@ -81,7 +81,7 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
8181 /* *
8282 * The template directory holding a custom template.
8383 */
84- val templateDir = project.objects.property< String > ()
84+ val templateDir: DirectoryProperty = project.objects.directoryProperty ()
8585
8686 /* *
8787 * The template location (which may be a directory or a classpath location) holding custom templates.
@@ -104,7 +104,7 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
104104 * File content should be in a json format { "optionKey":"optionValue", "optionKey1":"optionValue1"...}
105105 * Supported options can be different for each language. Run config-help -g {generator name} command for language specific config options.
106106 */
107- val configFile = project.objects.property< String > ()
107+ val configFile: RegularFileProperty = project.objects.fileProperty ()
108108
109109 /* *
110110 * Specifies if the existing files should be overwritten during the generation.
@@ -167,7 +167,7 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
167167 val languageSpecificPrimitives = project.objects.listProperty<String >()
168168
169169 /* *
170- * Specifies .openapi-generator-ignore list in the form of relative/path/to/file1,relative/path/to/file2. For example: README.md,pom.xml.
170+ * Specifies .openapi-generator-ignore list in the form of relative/path/to/file1,relative/path/to/file2. For example: README.md,pom.xml.
171171 */
172172 val openapiGeneratorIgnoreList = project.objects.listProperty<String >()
173173
@@ -279,7 +279,7 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
279279 /* *
280280 * Specifies an override location for the .openapi-generator-ignore file. Most useful on initial generation.
281281 */
282- val ignoreFileOverride = project.objects.property< String > ()
282+ val ignoreFileOverride: RegularFileProperty = project.objects.fileProperty ()
283283
284284 /* *
285285 * Remove prefix of operationId, e.g. config_getId => getId
@@ -413,22 +413,58 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
413413
414414 @Suppress(" MemberVisibilityCanBePrivate" )
415415 fun applyDefaults () {
416- releaseNote.set (" Minor update" )
417- inputSpecRootDirectorySkipMerge.set (false )
418- modelNamePrefix.set (" " )
419- modelNameSuffix.set (" " )
420- apiNameSuffix.set (" " )
421- generateModelTests.set (true )
422- generateModelDocumentation.set (true )
423- generateApiTests.set (true )
424- generateApiDocumentation.set (true )
425- configOptions.set (mapOf ())
426- validateSpec.set (true )
427- logToStderr.set (false )
428- enablePostProcessFile.set (false )
429- skipValidateSpec.set (false )
430- generateAliasAsModel.set (false )
431- cleanupOutput.set (false )
432- dryRun.set (false )
416+ releaseNote.convention (" Minor update" )
417+ inputSpecRootDirectorySkipMerge.convention (false )
418+ modelNamePrefix.convention (" " )
419+ modelNameSuffix.convention (" " )
420+ apiNameSuffix.convention (" " )
421+ generateModelTests.convention (true )
422+ generateModelDocumentation.convention (true )
423+ generateApiTests.convention (true )
424+ generateApiDocumentation.convention (true )
425+ configOptions.convention (mapOf ())
426+ validateSpec.convention (true )
427+ logToStderr.convention (false )
428+ enablePostProcessFile.convention (false )
429+ skipValidateSpec.convention (false )
430+ generateAliasAsModel.convention (false )
431+ cleanupOutput.convention (false )
432+ dryRun.convention (false )
433433 }
434- }
434+
435+ // ========================================================================
436+ // Backwards-compatibility bridge setters for Groovy/Kotlin DSL
437+ // These allow users to continue assigning paths as standard strings.
438+ // ========================================================================
439+
440+ /* * Backwards-compatibility bridge for outputDir */
441+ fun setOutputDir (path : String ) {
442+ outputDir.set(project.layout.projectDirectory.dir(path))
443+ }
444+
445+ /* * Backwards-compatibility bridge for inputSpec */
446+ fun setInputSpec (path : String ) {
447+ inputSpec.set(project.layout.projectDirectory.file(path))
448+ }
449+
450+ /* * Backwards-compatibility bridge for inputSpecRootDirectory */
451+ fun setInputSpecRootDirectory (path : String ) {
452+ inputSpecRootDirectory.set(project.layout.projectDirectory.dir(path))
453+ }
454+
455+ /* * Backwards-compatibility bridge for templateDir */
456+ fun setTemplateDir (path : String ) {
457+ templateDir.set(project.layout.projectDirectory.dir(path))
458+ }
459+
460+ /* * Backwards-compatibility bridge for configFile */
461+ fun setConfigFile (path : String ) {
462+ configFile.set(project.layout.projectDirectory.file(path))
463+ }
464+
465+ /* * Backwards-compatibility bridge for ignoreFileOverride */
466+ fun setIgnoreFileOverride (path : String ) {
467+ ignoreFileOverride.set(project.layout.projectDirectory.file(path))
468+ }
469+
470+ }
0 commit comments