@@ -4,6 +4,7 @@ import com.yelp.codegen.utils.safeSuffix
4
4
import io.swagger.codegen.CodegenConfig
5
5
import io.swagger.codegen.CodegenModel
6
6
import io.swagger.codegen.CodegenOperation
7
+ import io.swagger.codegen.CodegenParameter
7
8
import io.swagger.codegen.CodegenProperty
8
9
import io.swagger.codegen.CodegenType
9
10
import io.swagger.codegen.DefaultCodegen
@@ -293,6 +294,37 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
293
294
}
294
295
}
295
296
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
+
296
328
/* *
297
329
* Private method to investigate all the properties of a models, filter only the [RefProperty] and eventually
298
330
* propagate the `x-nullable` vendor extension.
@@ -378,7 +410,7 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
378
410
}
379
411
380
412
// 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()
382
414
}
383
415
384
416
/* *
@@ -630,3 +662,23 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
630
662
}
631
663
}
632
664
}
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