|
1 | 1 | package com.yelp.codegen |
2 | 2 |
|
| 3 | +import com.google.common.annotations.VisibleForTesting |
| 4 | +import com.yelp.codegen.utils.CodegenModelVar |
3 | 5 | import com.yelp.codegen.utils.safeSuffix |
4 | 6 | import io.swagger.codegen.CodegenConfig |
5 | 7 | import io.swagger.codegen.CodegenModel |
@@ -81,8 +83,8 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig { |
81 | 83 | /** |
82 | 84 | * Returns the /main/resources directory to access the .mustache files |
83 | 85 | */ |
84 | | - protected val resourcesDirectory: File |
85 | | - get() = File(this.javaClass.classLoader.getResource(templateDir)!!.path.safeSuffix(File.separator)) |
| 86 | + protected val resourcesDirectory: File? |
| 87 | + get() = javaClass.classLoader.getResource(templateDir)?.path?.safeSuffix(File.separator)?.let { File(it) } |
86 | 88 |
|
87 | 89 | override fun processOpts() { |
88 | 90 | super.processOpts() |
@@ -263,11 +265,8 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig { |
263 | 265 |
|
264 | 266 | // Update all enum properties datatypeWithEnum to use "BaseClass.InnerEnumClass" to reduce ambiguity |
265 | 267 | CodegenModelVar.forEachVarAttribute(codegenModel) { _, properties -> |
266 | | - properties.forEach { |
267 | | - if (it.isEnum) { |
268 | | - it.datatypeWithEnum = this.postProcessDataTypeWithEnum(codegenModel, it) |
269 | | - } |
270 | | - } |
| 268 | + properties.filter { it.isEnum } |
| 269 | + .onEach { it.datatypeWithEnum = postProcessDataTypeWithEnum(codegenModel, it) } |
271 | 270 | } |
272 | 271 |
|
273 | 272 | return codegenModel |
@@ -608,6 +607,7 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig { |
608 | 607 | * Hook that allows to add the needed imports for a given [CodegenModel] |
609 | 608 | * This is needed as we might be modifying models in [postProcessAllModels] |
610 | 609 | */ |
| 610 | + @VisibleForTesting |
611 | 611 | internal abstract fun addRequiredImports(codegenModel: CodegenModel) |
612 | 612 |
|
613 | 613 | private fun defaultListType() = typeMapping["list"] ?: "" |
|
0 commit comments