-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Polymorphism Prep] Expose private KotlinGenerator methods in SharedCodegen #104
base: master
Are you sure you want to change the base?
Changes from all commits
2ffc7d6
398dc23
7a2369f
4a7a427
bde67fb
cdd09a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.yelp.codegen.utils | ||
|
||
import io.swagger.codegen.CodegenModel | ||
import io.swagger.codegen.CodegenProperty | ||
|
||
Comment on lines
+3
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class is probably not needed at all and the same behavior can be achieved with an extension function: fun CodegenModel.forEachVarAttribute(
action: (MutableList<CodegenProperty>) -> Unit
) {
listOf<MutableList<CodegenProperty>>(
this.allVars,
this.optionalVars,
this.parentVars,
this.readOnlyVars,
this.readWriteVars,
this.requiredVars,
this.vars).forEach { action(it) }
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The enums and stuff are mostly needed to ensure that we can have information on which list of variables we're working on. |
||
internal enum class CodegenModelVar { | ||
macisamuele marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ALL_VARS, | ||
OPTIONAL_VARS, | ||
PARENT_VARS, | ||
READ_ONLY_VARS, | ||
READ_WRITE_VARS, | ||
REQUIRED_VARS, | ||
VARS; | ||
|
||
companion object { | ||
/** | ||
* Allow the execution of an action on all the var attributes | ||
*/ | ||
fun forEachVarAttribute( | ||
codegenModel: CodegenModel, | ||
action: (CodegenModelVar, MutableList<CodegenProperty>) -> Unit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather prefer having it as it will be used in the subsequent branch :) |
||
) { | ||
values().forEach { | ||
action(it, it.value(codegenModel)) | ||
} | ||
} | ||
} | ||
|
||
internal fun value(codegenModel: CodegenModel): MutableList<CodegenProperty> { | ||
return when (this) { | ||
ALL_VARS -> codegenModel.allVars | ||
OPTIONAL_VARS -> codegenModel.optionalVars | ||
PARENT_VARS -> codegenModel.parentVars | ||
READ_ONLY_VARS -> codegenModel.readOnlyVars | ||
READ_WRITE_VARS -> codegenModel.readWriteVars | ||
REQUIRED_VARS -> codegenModel.requiredVars | ||
VARS -> codegenModel.vars | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having a hard time understanding the use case of this.