@@ -4,6 +4,7 @@ import com.yelp.codegen.utils.safeSuffix
44import io.swagger.codegen.CodegenConfig
55import io.swagger.codegen.CodegenModel
66import io.swagger.codegen.CodegenOperation
7+ import io.swagger.codegen.CodegenParameter
78import io.swagger.codegen.CodegenProperty
89import io.swagger.codegen.CodegenType
910import io.swagger.codegen.DefaultCodegen
@@ -293,6 +294,37 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
293294 }
294295 }
295296
297+ override fun postProcessAllModels (objs : Map <String , Any >): Map <String , Any > {
298+ val postProcessedModels = super .postProcessAllModels(objs)
299+
300+ // postProcessedModel does contain a map like Map<ModelName, ContentOfTheModelAsPassedToMustache>
301+ // ContentOfTheModelAsPassedToMustache would look like the following
302+ // {
303+ // <model_name>: {
304+ // <codegen constants>
305+ // "models": [
306+ // {
307+ // "importPath": <String instance>,
308+ // "model": <CodegenModel instance>
309+ // }
310+ // ]
311+ // }
312+ // }
313+ postProcessedModels.values
314+ .asSequence()
315+ .filterIsInstance<Map <String , Any >>()
316+ .mapNotNull { it[" models" ] }
317+ .filterIsInstance<List <Map <String , Any >>>()
318+ .mapNotNull { it[0 ][" model" ] }
319+ .filterIsInstance<CodegenModel >()
320+ .forEach { codegenModel ->
321+ // Ensure that after all the processing done on the CodegenModel.*Vars, hasMore does still make sense
322+ CodegenModelVar .forEachVarAttribute(codegenModel) { _, properties -> properties.fixHasMoreProperty() }
323+ }
324+
325+ return postProcessedModels
326+ }
327+
296328 /* *
297329 * Private method to investigate all the properties of a models, filter only the [RefProperty] and eventually
298330 * propagate the `x-nullable` vendor extension.
@@ -378,7 +410,7 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
378410 }
379411
380412 // If we removed the last parameter of the Operation, we should update the `hasMore` flag.
381- codegenOperation.allParams.lastOrNull()?.hasMore = false
413+ codegenOperation.allParams.fixHasMoreParameter()
382414 }
383415
384416 /* *
@@ -630,3 +662,23 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
630662 }
631663 }
632664}
665+
666+ /* *
667+ * Small helper to ensurer that the hasMore attribute is properly
668+ * defined within a list of [CodegenProperty]s
669+ */
670+ internal fun List<CodegenProperty>.fixHasMoreProperty () {
671+ this .forEachIndexed { index, item ->
672+ item.hasMore = index != (this .size - 1 )
673+ }
674+ }
675+
676+ /* *
677+ * Small helper to ensurer that the hasMore attribute is properly
678+ * defined within a list of [CodegenParameter]s
679+ */
680+ internal fun List<CodegenParameter>.fixHasMoreParameter () {
681+ this .forEachIndexed { index, item ->
682+ item.hasMore = index != (this .size - 1 )
683+ }
684+ }
0 commit comments