1
1
package com.yelp.codegen.plugin
2
2
3
3
import com.yelp.codegen.main
4
- import io.swagger.parser.SwaggerParser
5
- import java.io.File
6
4
import org.gradle.api.DefaultTask
7
5
import org.gradle.api.file.DirectoryProperty
8
6
import org.gradle.api.file.RegularFileProperty
@@ -31,22 +29,18 @@ abstract class GenerateTask : DefaultTask() {
31
29
}
32
30
33
31
@get:Input
34
- @get:Optional
35
32
@get:Option(option = " platform" , description = " Configures the platform that is used for generating the code." )
36
33
abstract val platform: Property <String >
37
34
38
35
@get:Input
39
- @get:Optional
40
36
@get:Option(option = " packageName" , description = " Configures the package name of the resulting code." )
41
37
abstract val packageName: Property <String >
42
38
43
39
@get:Input
44
- @get:Optional
45
40
@get:Option(option = " specName" , description = " Configures the name of the service for the Swagger Spec." )
46
41
abstract val specName: Property <String >
47
42
48
43
@get:Input
49
- @get:Optional
50
44
@get:Option(option = " specVersion" , description = " Configures the version of the Swagger Spec." )
51
45
abstract val specVersion: Property <String >
52
46
@@ -55,7 +49,6 @@ abstract class GenerateTask : DefaultTask() {
55
49
abstract val inputFile: RegularFileProperty
56
50
57
51
@get:OutputDirectory
58
- @get:Optional
59
52
@get:Option(option = " outputDir" , description = " Configures path of the Generated code directory." )
60
53
abstract val outputDir: DirectoryProperty
61
54
@@ -71,12 +64,12 @@ abstract class GenerateTask : DefaultTask() {
71
64
72
65
@TaskAction
73
66
fun swaggerGenerate () {
74
- val platform = platform.getOrElse( DEFAULT_PLATFORM )
75
- val specName = specName.getOrElse( DEFAULT_NAME )
76
- val packageName = packageName.getOrElse( DEFAULT_PACKAGE )
77
- val outputDir = outputDir.getOrElse(project.layout.buildDirectory.dir( DEFAULT_OUTPUT_DIR ). get() ).asFile
67
+ val platform = platform.get( )
68
+ val specName = specName.get( )
69
+ val packageName = packageName.get( )
70
+ val outputDir = outputDir.get().asFile
78
71
val inputFile = inputFile.get().asFile
79
- val specVersion = specVersion.getOrElse(readVersionFromSpecfile(inputFile) )
72
+ val specVersion = specVersion.get( )
80
73
81
74
val headersToRemove = features?.headersToRemove?.get() ? : emptyList()
82
75
@@ -123,19 +116,4 @@ abstract class GenerateTask : DefaultTask() {
123
116
val source = extraFiles.orNull?.asFile
124
117
source?.copyRecursively(outputDir, overwrite = true )
125
118
}
126
-
127
- private fun readVersionFromSpecfile (specFile : File ): String {
128
- val swaggerSpec = SwaggerParser ().readWithInfo(specFile.absolutePath, listOf (), false ).swagger
129
-
130
- return when (val version = swaggerSpec.info.version) {
131
- is String -> {
132
- println (" Successfully read version from Swagger Spec file: $version " )
133
- version
134
- }
135
- else -> {
136
- println (" Issue in reading version from Swagger Spec file. Falling back to $DEFAULT_VERSION " )
137
- DEFAULT_VERSION
138
- }
139
- }
140
- }
141
119
}
0 commit comments