@@ -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
@@ -290,6 +291,37 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
290291 }
291292 }
292293
294+ override fun postProcessAllModels (objs : Map <String , Any >): Map <String , Any > {
295+ val postProcessedModels = super .postProcessAllModels(objs)
296+
297+ // postProcessedModel does contain a map like Map<ModelName, ContentOfTheModelAsPassedToMustache>
298+ // ContentOfTheModelAsPassedToMustache would look like the following
299+ // {
300+ // <model_name>: {
301+ // <codegen constants>
302+ // "models": [
303+ // {
304+ // "importPath": <String instance>,
305+ // "model": <CodegenModel instance>
306+ // }
307+ // ]
308+ // }
309+ // }
310+ postProcessedModels.values
311+ .asSequence()
312+ .filterIsInstance<Map <String , Any >>()
313+ .mapNotNull { it[" models" ] }
314+ .filterIsInstance<List <Map <String , Any >>>()
315+ .mapNotNull { it[0 ][" model" ] }
316+ .filterIsInstance<CodegenModel >()
317+ .forEach { codegenModel ->
318+ // Ensure that after all the processing done on the CodegenModel.*Vars, hasMore does still make sense
319+ CodegenModelVar .forEachVarAttribute(codegenModel) { _, properties -> properties.fixHasMoreProperty() }
320+ }
321+
322+ return postProcessedModels
323+ }
324+
293325 /* *
294326 * Private method to investigate all the properties of a models, filter only the [RefProperty] and eventually
295327 * propagate the `x-nullable` vendor extension.
@@ -375,7 +407,7 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
375407 }
376408
377409 // If we removed the last parameter of the Operation, we should update the `hasMore` flag.
378- codegenOperation.allParams.lastOrNull()?.hasMore = false
410+ codegenOperation.allParams.fixHasMoreParameter()
379411 }
380412
381413 /* *
@@ -627,3 +659,23 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
627659 }
628660 }
629661}
662+
663+ /* *
664+ * Small helper to ensurer that the hasMore attribute is properly
665+ * defined within a list of [CodegenProperty]s
666+ */
667+ internal fun List<CodegenProperty>.fixHasMoreProperty () {
668+ this .forEachIndexed { index, item ->
669+ item.hasMore = index != (this .size - 1 )
670+ }
671+ }
672+
673+ /* *
674+ * Small helper to ensurer that the hasMore attribute is properly
675+ * defined within a list of [CodegenParameter]s
676+ */
677+ internal fun List<CodegenParameter>.fixHasMoreParameter () {
678+ this .forEachIndexed { index, item ->
679+ item.hasMore = index != (this .size - 1 )
680+ }
681+ }
0 commit comments