@@ -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
@@ -290,6 +291,37 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
290
291
}
291
292
}
292
293
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
+
293
325
/* *
294
326
* Private method to investigate all the properties of a models, filter only the [RefProperty] and eventually
295
327
* propagate the `x-nullable` vendor extension.
@@ -375,7 +407,7 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
375
407
}
376
408
377
409
// 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()
379
411
}
380
412
381
413
/* *
@@ -627,3 +659,23 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
627
659
}
628
660
}
629
661
}
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