Skip to content

Commit b392529

Browse files
authored
Merge pull request #133 from Yelp/language-formatters-pre-commit-hooks-to-1.4.1
2 parents 44ebe35 + 1286f48 commit b392529

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+959
-654
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repos:
1212
exclude: ^samples/[^/]+/src/main/java/swagger.json$
1313
- id: check-yaml
1414
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
15-
rev: v1.3.2
15+
rev: v1.4.2
1616
hooks:
1717
- id: pretty-format-java
1818
args: [--autofix]

config/detekt/detekt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ complexity:
7777
threshold: 600
7878
LongMethod:
7979
active: true
80-
threshold: 60
80+
threshold: 70
8181
LongParameterList:
8282
active: true
8383
threshold: 6

gradle-plugin/plugin/src/main/java/com/yelp/codegen/KotlinGenerator.kt

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ open class KotlinGenerator : SharedCodegen() {
3939
internal var basePath: String? = null
4040

4141
private val retrofitImport = mapOf(
42-
"GET" to "retrofit2.http.GET",
43-
"DELETE" to "retrofit2.http.DELETE",
44-
"PATCH" to "retrofit2.http.PATCH",
45-
"POST" to "retrofit2.http.POST",
46-
"PUT" to "retrofit2.http.PUT"
42+
"GET" to "retrofit2.http.GET",
43+
"DELETE" to "retrofit2.http.DELETE",
44+
"PATCH" to "retrofit2.http.PATCH",
45+
"POST" to "retrofit2.http.POST",
46+
"PUT" to "retrofit2.http.PUT"
4747
)
4848

4949
/**
@@ -97,38 +97,38 @@ open class KotlinGenerator : SharedCodegen() {
9797
override fun apiDocFileFolder() = "$outputFolder${File.separator}$apiDocPath"
9898

9999
override fun apiFileFolder() =
100-
"$outputFolder${File.separator}" + apiPackage()
101-
.replace('.', File.separatorChar)
100+
"$outputFolder${File.separator}" + apiPackage()
101+
.replace('.', File.separatorChar)
102102

103103
/*
104104
* SHARED CODEGEN SETUP
105105
==================================================== */
106106

107107
override val mustacheTags
108108
get() = hashMapOf(
109-
CodegenConstants.GROUP_ID to groupId,
110-
CodegenConstants.ARTIFACT_ID to artifactId,
111-
CodegenConstants.PACKAGE_NAME to packageName,
112-
CodegenConstants.API_PACKAGE to apiPackage(),
113-
CodegenConstants.MODEL_PACKAGE to modelPackage(),
114-
"apiDocPath" to apiDocPath,
115-
"modelDocPath" to modelDocPath,
116-
"service" to serviceName,
117-
"newline" to "\n"
109+
CodegenConstants.GROUP_ID to groupId,
110+
CodegenConstants.ARTIFACT_ID to artifactId,
111+
CodegenConstants.PACKAGE_NAME to packageName,
112+
CodegenConstants.API_PACKAGE to apiPackage(),
113+
CodegenConstants.MODEL_PACKAGE to modelPackage(),
114+
"apiDocPath" to apiDocPath,
115+
"modelDocPath" to modelDocPath,
116+
"service" to serviceName,
117+
"newline" to "\n"
118118
)
119119

120120
override val supportFiles: Collection<SupportingFile>
121121
get() {
122122
val toolsFolder = toolsPackage.replace(".", File.separator).plus(File.separator)
123123
val toolsFiles = listOf(
124-
"CollectionFormatConverterFactory.kt",
125-
"CollectionFormats.kt",
126-
"EnumToValueConverterFactory.kt",
127-
"GeneratedCodeConverters.kt",
128-
"TypesAdapters.kt",
129-
"WrapperConverterFactory.kt",
130-
"XNullable.kt",
131-
"XNullableAdapterFactory.kt"
124+
"CollectionFormatConverterFactory.kt",
125+
"CollectionFormats.kt",
126+
"EnumToValueConverterFactory.kt",
127+
"GeneratedCodeConverters.kt",
128+
"TypesAdapters.kt",
129+
"WrapperConverterFactory.kt",
130+
"XNullable.kt",
131+
"XNullableAdapterFactory.kt"
132132
)
133133
supportingFiles.addAll(toolsFiles.map { SupportingFile("tools/$it.mustache", toolsFolder, it) })
134134
return supportingFiles
@@ -139,31 +139,31 @@ open class KotlinGenerator : SharedCodegen() {
139139

140140
@VisibleForTesting
141141
public override fun listTypeWrapper(listType: String, innerType: String) =
142-
"$listType<$innerType>"
142+
"$listType<$innerType>"
143143

144144
public override fun listTypeUnwrapper(baseType: String) = baseType
145-
.replace(" ", "")
146-
.removeSuffix(">")
147-
.removePrefix("${typeMapping["list"]}<")
145+
.replace(" ", "")
146+
.removeSuffix(">")
147+
.removePrefix("${typeMapping["list"]}<")
148148

149149
public override fun isListTypeWrapped(baseType: String) =
150-
baseType.endsWith('>') && baseType.startsWith("${typeMapping["list"]}<")
150+
baseType.endsWith('>') && baseType.startsWith("${typeMapping["list"]}<")
151151

152152
@VisibleForTesting
153153
public override fun mapTypeWrapper(mapType: String, innerType: String) =
154-
"$mapType<${typeMapping["string"]}, $innerType>"
154+
"$mapType<${typeMapping["string"]}, $innerType>"
155155

156156
public override fun mapTypeUnwrapper(baseType: String) = baseType
157-
.replace(" ", "")
158-
.removeSuffix(">")
159-
.removePrefix("${typeMapping["map"]}<${typeMapping["string"]},")
157+
.replace(" ", "")
158+
.removeSuffix(">")
159+
.removePrefix("${typeMapping["map"]}<${typeMapping["string"]},")
160160

161161
public override fun isMapTypeWrapped(baseType: String) =
162-
baseType.endsWith('>') && baseType.startsWith("${typeMapping["map"]}<${typeMapping["string"]},")
162+
baseType.endsWith('>') && baseType.startsWith("${typeMapping["map"]}<${typeMapping["string"]},")
163163

164164
@VisibleForTesting
165165
public override fun nullableTypeWrapper(baseType: String) =
166-
baseType.safeSuffix("?")
166+
baseType.safeSuffix("?")
167167

168168
/*
169169
* ESCAPING
@@ -183,14 +183,14 @@ open class KotlinGenerator : SharedCodegen() {
183183
override fun escapeQuotationMark(input: String) = input.replace("\"", "")
184184

185185
override fun escapeReservedWord(name: String) =
186-
if (name in reservedWords) {
187-
"`$name`"
188-
} else {
189-
name
190-
}
186+
if (name in reservedWords) {
187+
"`$name`"
188+
} else {
189+
name
190+
}
191191

192192
override fun escapeUnsafeCharacters(input: String) =
193-
input.replace("*/", "*_/").replace("/*", "/_*")
193+
input.replace("*/", "*_/").replace("/*", "/_*")
194194

195195
/*
196196
* CODEGEN FUNCTIONS
@@ -307,11 +307,11 @@ open class KotlinGenerator : SharedCodegen() {
307307
*/
308308
override fun toEnumVarName(value: String, datatype: String): String {
309309
(if (value.isEmpty()) "EMPTY" else value)
310-
.sanitizeKotlinSpecificNames(specialCharReplacements)
311-
.toUpperCase()
312-
.let {
313-
return escapeReservedWord(it)
314-
}
310+
.sanitizeKotlinSpecificNames(specialCharReplacements)
311+
.toUpperCase()
312+
.let {
313+
return escapeReservedWord(it)
314+
}
315315
}
316316

317317
override fun toVarName(name: String): String {
@@ -353,10 +353,10 @@ open class KotlinGenerator : SharedCodegen() {
353353
name
354354
} else {
355355
matchXModel(name)
356-
.replace(Regex("(\\.|\\s)"), "_")
357-
.toPascalCase()
358-
.sanitizeKotlinSpecificNames(specialCharReplacements)
359-
.apply { escapeReservedWord(this) }
356+
.replace(Regex("(\\.|\\s)"), "_")
357+
.toPascalCase()
358+
.sanitizeKotlinSpecificNames(specialCharReplacements)
359+
.apply { escapeReservedWord(this) }
360360
}
361361
}
362362

gradle-plugin/plugin/src/main/java/com/yelp/codegen/Main.kt

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,62 @@ import io.swagger.codegen.DefaultGenerator
77
import io.swagger.codegen.config.CodegenConfigurator
88
import io.swagger.parser.SwaggerParser
99
import io.swagger.util.Json
10-
import java.io.File
1110
import org.apache.commons.cli.CommandLine
1211
import org.apache.commons.cli.CommandLineParser
1312
import org.apache.commons.cli.DefaultParser
1413
import org.apache.commons.cli.Option
1514
import org.apache.commons.cli.Options
15+
import java.io.File
1616

1717
fun main(args: Array<String>) {
1818
val options = Options()
1919
options.addRequiredOption(
20-
"p",
21-
"platform",
22-
true,
23-
"The platform to generate")
20+
"p",
21+
"platform",
22+
true,
23+
"The platform to generate"
24+
)
2425
options.addRequiredOption(
25-
"i",
26-
"input",
27-
true,
28-
"Path to the input spec")
26+
"i",
27+
"input",
28+
true,
29+
"Path to the input spec"
30+
)
2931
options.addRequiredOption(
30-
"o",
31-
"output",
32-
true,
33-
"Path to the output directory")
32+
"o",
33+
"output",
34+
true,
35+
"Path to the output directory"
36+
)
3437
options.addRequiredOption(
35-
"s",
36-
"service",
37-
true,
38-
"Name of the service to build")
38+
"s",
39+
"service",
40+
true,
41+
"Name of the service to build"
42+
)
3943
options.addRequiredOption(
40-
"v",
41-
"version",
42-
true,
43-
"Version to use when generating the code.")
44+
"v",
45+
"version",
46+
true,
47+
"Version to use when generating the code."
48+
)
4449
options.addRequiredOption(
45-
"g",
46-
"groupid",
47-
true,
48-
"The fully qualified domain name of company/organization.")
50+
"g",
51+
"groupid",
52+
true,
53+
"The fully qualified domain name of company/organization."
54+
)
4955
options.addRequiredOption(
50-
"a",
51-
"artifactid",
52-
true,
53-
"The artifact id to be used when generating the code.")
56+
"a",
57+
"artifactid",
58+
true,
59+
"The artifact id to be used when generating the code."
60+
)
5461
options.addOption(
55-
Option.builder("ignoreheaders")
56-
.hasArg().argName("Comma separated list of headers to ingore")
57-
.desc("A comma separated list of headers that will be ignored by the generator")
58-
.build()
62+
Option.builder("ignoreheaders")
63+
.hasArg().argName("Comma separated list of headers to ingore")
64+
.desc("A comma separated list of headers that will be ignored by the generator")
65+
.build()
5966
)
6067

6168
val parser: CommandLineParser = DefaultParser()

gradle-plugin/plugin/src/main/java/com/yelp/codegen/SharedCodegen.kt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
9999
// So we're triggering the process early on as the process is not super slow and more importantly is idempotent
100100
InlineModelResolver().flatten(swagger)
101101

102-
unsafeOperations.addAll(when (val it = swagger.info.vendorExtensions["x-operation-ids-unsafe-to-use"]) {
103-
is List<*> -> it.filterIsInstance<String>()
104-
else -> listOf()
105-
})
102+
unsafeOperations.addAll(
103+
when (val it = swagger.info.vendorExtensions["x-operation-ids-unsafe-to-use"]) {
104+
is List<*> -> it.filterIsInstance<String>()
105+
else -> listOf()
106+
}
107+
)
106108

107109
mapXModel(swagger)
108110

@@ -153,8 +155,8 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
153155
*/
154156
fun matchXModel(name: String): String {
155157
return xModelMatches[name] ?: (
156-
this.swagger?.definitions?.get(name)?.title ?: name
157-
)
158+
this.swagger?.definitions?.get(name)?.title ?: name
159+
)
158160
}
159161

160162
/**
@@ -202,7 +204,8 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
202204
model.type
203205
} else {
204206
if (false == model.properties?.isEmpty() ||
205-
model.additionalProperties != null) {
207+
model.additionalProperties != null
208+
) {
206209
"object"
207210
} else {
208211
null
@@ -286,9 +289,9 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
286289
*/
287290
private fun propagateXNullableToProperties(model: Model, allDefinitions: MutableMap<String, Model>) {
288291
model.properties
289-
.values
290-
.filterIsInstance(RefProperty::class.java)
291-
.forEach { propagateXNullableVendorExtension(it, allDefinitions) }
292+
.values
293+
.filterIsInstance(RefProperty::class.java)
294+
.forEach { propagateXNullableVendorExtension(it, allDefinitions) }
292295
}
293296

294297
/**
@@ -335,7 +338,7 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
335338
codegenModel.hasEnums = true
336339
codegenModel.vars.add(innerEnum)
337340
codegenModel.dataType =
338-
codegenModel.dataType.replace(defaultStringType(), innerEnum.datatypeWithEnum)
341+
codegenModel.dataType.replace(defaultStringType(), innerEnum.datatypeWithEnum)
339342
}
340343

341344
/**

gradle-plugin/plugin/src/main/java/com/yelp/codegen/plugin/GenerateTask.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ abstract class GenerateTask : DefaultTask() {
4848

4949
@get:InputFiles
5050
@get:Optional
51-
@get:Option(option = "extraFiles",
52-
description = "Configures path of the extra files directory to be added to the Generated code.")
51+
@get:Option(
52+
option = "extraFiles",
53+
description = "Configures path of the extra files directory to be added to the Generated code."
54+
)
5355
abstract val extraFiles: DirectoryProperty
5456

5557
@get:Nested
@@ -67,7 +69,8 @@ abstract class GenerateTask : DefaultTask() {
6769

6870
val headersToRemove = features?.headersToRemove?.get() ?: emptyList()
6971

70-
println("""
72+
println(
73+
"""
7174
####################
7275
Yelp Swagger Codegen
7376
####################
@@ -80,7 +83,8 @@ abstract class GenerateTask : DefaultTask() {
8083
groupId ${'\t'} $packageName
8184
artifactId ${'\t'} $packageName
8285
features ${'\t'} ${headersToRemove.joinToString(separator = ",", prefix = "[", postfix = "]")}
83-
""".trimIndent())
86+
""".trimIndent()
87+
)
8488

8589
val params = mutableListOf<String>()
8690
params.add("-p")

0 commit comments

Comments
 (0)