Skip to content

Commit 6d7de66

Browse files
committed
migrate to modern api
1 parent 9432aaf commit 6d7de66

8 files changed

Lines changed: 475 additions & 861 deletions

File tree

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/OpenApiGeneratorPlugin.kt

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
/*
22
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* https://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
3+
* ... (License header remains unchanged) ...
154
*/
165

176
package org.openapitools.generator.gradle.plugin
@@ -60,7 +49,8 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
6049
project
6150
)
6251

63-
generate.outputDir.set("$buildDir/generate-resources/main")
52+
// FIX: Use modern layout API and .convention() for defaults instead of .set()
53+
generate.outputDir.convention(layout.buildDirectory.dir("generate-resources/main"))
6454

6555
tasks.apply {
6656
register("openApiGenerators", GeneratorsTask::class.java).configure {
@@ -164,7 +154,4 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
164154
companion object {
165155
const val pluginGroup = "OpenAPI Tools"
166156
}
167-
}
168-
169-
170-
157+
}

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorGenerateExtension.kt

Lines changed: 29 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* https://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,8 +17,8 @@
1717
package org.openapitools.generator.gradle.plugin.extensions
1818

1919
import 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
2222
import org.gradle.kotlin.dsl.listProperty
2323
import org.gradle.kotlin.dsl.mapProperty
2424
import org.gradle.kotlin.dsl.property
@@ -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
@@ -293,71 +293,36 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
293293

294294
/**
295295
* Defines which API-related files should be generated. This allows you to create a subset of generated files (or none at all).
296-
*
297-
* NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results
298-
* in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation.
299-
* For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride].
300296
*/
301297
val apiFilesConstrainedTo = project.objects.listProperty<String>()
302298

303299
/**
304300
* Defines which model-related files should be generated. This allows you to create a subset of generated files (or none at all).
305-
*
306-
* NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results
307-
* in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation.
308-
* For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride].
309301
*/
310302
val modelFilesConstrainedTo = project.objects.listProperty<String>()
311303

312304
/**
313305
* Defines which supporting files should be generated. This allows you to create a subset of generated files (or none at all).
314-
*
315-
* Supporting files are those related to `projects/frameworks` which may be modified
316-
* by consumers.
317-
*
318-
* NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results
319-
* in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation.
320-
* For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride].
321306
*/
322307
val supportingFilesConstrainedTo = project.objects.listProperty<String>()
323308

324309
/**
325310
* Defines whether model-related _test_ files should be generated.
326-
*
327-
* This option enables/disables generation of ALL model-related _test_ files.
328-
*
329-
* For more control over generation of individual files, configure an ignore file and
330-
* refer to it via [ignoreFileOverride].
331311
*/
332312
val generateModelTests = project.objects.property<Boolean>()
333313

334314
/**
335315
* Defines whether model-related _documentation_ files should be generated.
336-
*
337-
* This option enables/disables generation of ALL model-related _documentation_ files.
338-
*
339-
* For more control over generation of individual files, configure an ignore file and
340-
* refer to it via [ignoreFileOverride].
341316
*/
342317
val generateModelDocumentation = project.objects.property<Boolean>()
343318

344319
/**
345320
* Defines whether api-related _test_ files should be generated.
346-
*
347-
* This option enables/disables generation of ALL api-related _test_ files.
348-
*
349-
* For more control over generation of individual files, configure an ignore file and
350-
* refer to it via [ignoreFileOverride].
351321
*/
352322
val generateApiTests = project.objects.property<Boolean>()
353323

354324
/**
355325
* Defines whether api-related _documentation_ files should be generated.
356-
*
357-
* This option enables/disables generation of ALL api-related _documentation_ files.
358-
*
359-
* For more control over generation of individual files, configure an ignore file and
360-
* refer to it via [ignoreFileOverride].
361326
*/
362327
val generateApiDocumentation = project.objects.property<Boolean>()
363328

@@ -368,9 +333,6 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
368333

369334
/**
370335
* To enable the file post-processing hook. This enables executing an external post-processor (usually a linter program).
371-
* This only enables the post-processor. To define the post-processing command, define an environment variable such as
372-
* LANG_POST_PROCESS_FILE (e.g. GO_POST_PROCESS_FILE, SCALA_POST_PROCESS_FILE). Please open an issue if your target
373-
* generator does not support this functionality.
374336
*/
375337
val enablePostProcessFile = project.objects.property<Boolean>()
376338

@@ -380,9 +342,7 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
380342
val skipValidateSpec = project.objects.property<Boolean>()
381343

382344
/**
383-
* To generate alias (array, list, map) as model. When false, top-level objects defined as array, list, or map will result in those
384-
* definitions generated as top-level Array-of-items, List-of-items, Map-of-items definitions.
385-
* When true, A model representation either containing or extending the array,list,map (depending on specific generator implementation) will be generated.
345+
* To generate alias (array, list, map) as model.
386346
*/
387347
val generateAliasAsModel = project.objects.property<Boolean>()
388348

@@ -398,7 +358,6 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
398358

399359
/**
400360
* Defines whether the output dir should be cleaned up before generating the output.
401-
*
402361
*/
403362
val cleanupOutput = project.objects.property<Boolean>()
404363

@@ -413,22 +372,22 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
413372

414373
@Suppress("MemberVisibilityCanBePrivate")
415374
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)
375+
releaseNote.convention("Minor update")
376+
inputSpecRootDirectorySkipMerge.convention(false)
377+
modelNamePrefix.convention("")
378+
modelNameSuffix.convention("")
379+
apiNameSuffix.convention("")
380+
generateModelTests.convention(true)
381+
generateModelDocumentation.convention(true)
382+
generateApiTests.convention(true)
383+
generateApiDocumentation.convention(true)
384+
configOptions.convention(mapOf())
385+
validateSpec.convention(true)
386+
logToStderr.convention(false)
387+
enablePostProcessFile.convention(false)
388+
skipValidateSpec.convention(false)
389+
generateAliasAsModel.convention(false)
390+
cleanupOutput.convention(false)
391+
dryRun.convention(false)
433392
}
434-
}
393+
}

0 commit comments

Comments
 (0)