Skip to content

Commit 398dc23

Browse files
committed
Define helper to iterate over all the var attributes of a CodegenModel instance
1 parent 2ffc7d6 commit 398dc23

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import io.swagger.codegen.CodegenModel
2+
import io.swagger.codegen.CodegenProperty
3+
4+
internal enum class CodegenModelVar {
5+
ALL_VARS,
6+
OPTIONAL_VARS,
7+
PARENT_VARS,
8+
READ_ONLY_VARS,
9+
READ_WRITE_VARS,
10+
REQUIRED_VARS,
11+
VARS;
12+
13+
companion object {
14+
/**
15+
* Allow the execution of an action on all the var attributes
16+
*/
17+
fun forEachVarAttribute(
18+
codegenModel: CodegenModel,
19+
action: (CodegenModelVar, MutableList<CodegenProperty>) -> Unit
20+
) {
21+
values().forEach {
22+
action(it, it.value(codegenModel))
23+
}
24+
}
25+
}
26+
27+
internal fun value(codegenModel: CodegenModel): MutableList<CodegenProperty> {
28+
return when (this) {
29+
ALL_VARS -> codegenModel.allVars
30+
OPTIONAL_VARS -> codegenModel.optionalVars
31+
PARENT_VARS -> codegenModel.parentVars
32+
READ_ONLY_VARS -> codegenModel.readOnlyVars
33+
READ_WRITE_VARS -> codegenModel.readWriteVars
34+
REQUIRED_VARS -> codegenModel.requiredVars
35+
VARS -> codegenModel.vars
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)