Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

macisamuele
Copy link
Collaborator

This PR does some preparatory work for #103 .
In order to achieve polymorphism support we need to extract few functionalities from KotlinGenerator to SharedCodegen.

I totally understand that this PR seems disconnected and doesn't really explain why certain features are moved back to SharedCodegen or why we do even need to iterate over all CodegenModel.*vars.
In order to provide a better visibility I would suggest to check the potential draft of polymorphism on macisamuele/swagger-gradle-codegen@maci-polymmorphism

@macisamuele macisamuele self-assigned this Feb 7, 2020
@macisamuele macisamuele linked an issue Feb 7, 2020 that may be closed by this pull request
@macisamuele macisamuele changed the title Maci polymorphism prep [Polymorphism Prep] Expose private KotlinGenerator methods in SharedCodegen Feb 9, 2020
@cortinico cortinico added this to the 2.0.0 milestone Feb 13, 2020
@macisamuele
Copy link
Collaborator Author

I've rebased this branch on top of the laster master to remove the merge conflicts.

@cortinico could you please have a look to this CR?

This provides a starting point for for #103 and by itself does not provide any change that deserve a major release, so it could be merged even if we're not yet planning on having the 2.0.0 release

Copy link
Collaborator

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left several comments.
Maybe having also the second part will help understand some of the changes?
Generally looks good, but having some tests will be beneficial 👍

*/
fun forEachVarAttribute(
codegenModel: CodegenModel,
action: (CodegenModelVar, MutableList<CodegenProperty>) -> Unit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the CodegenModelVar here is unused. Can you please remove it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 :)

Comment on lines +1 to +5
import io.swagger.codegen.CodegenModel
import io.swagger.codegen.CodegenProperty

Copy link
Collaborator

Choose a reason for hiding this comment

The 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) }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.
This is something needed in the usages that will be proposed on the subsequent PR

@@ -256,6 +257,16 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
}

handleXNullable(codegenModel)

// Update all enum properties datatypeWithEnum to use "BaseClass.InnerEnumClass" to reduce ambiguity
Copy link
Collaborator

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.

@macisamuele
Copy link
Collaborator Author

@cortinico it will take me some time (maybe a few weeks) to provide changes on this PR.
Currently my laptop is not powerful enough to run all the tasks ;)

Maybe having also the second part will help understand some of the changes

The current branch that fully targets #103 is avaiblable on https://github.com/macisamuele/swagger-gradle-codegen/tree/maci-polymorphism .

@cortinico
Copy link
Collaborator

@cortinico it will take me some time (maybe a few weeks) to provide changes on this PR.
Currently my laptop is not powerful enough to run all the tasks ;)

No problem, let's keep this opened for now.

@codecov
Copy link

codecov bot commented Oct 24, 2020

Codecov Report

Merging #104 (249f4d2) into master (5318347) will increase coverage by 1.81%.
The diff coverage is 82.92%.

❗ Current head 249f4d2 differs from pull request most recent head cdd09a3. Consider uploading reports for the commit cdd09a3 to get more accurate results
Impacted file tree graph

@@             Coverage Diff              @@
##             master     #104      +/-   ##
============================================
+ Coverage     70.83%   72.65%   +1.81%     
- Complexity      138      147       +9     
============================================
  Files            11       12       +1     
  Lines           576      607      +31     
  Branches         87       80       -7     
============================================
+ Hits            408      441      +33     
- Misses          118      122       +4     
+ Partials         50       44       -6     
Impacted Files Coverage Δ
.../src/main/java/com/yelp/codegen/KotlinGenerator.kt 83.62% <ø> (+0.83%) ⬆️
...in/src/main/java/com/yelp/codegen/SharedCodegen.kt 63.93% <77.41%> (+6.14%) ⬆️
...ain/java/com/yelp/codegen/utils/CodegenModelVar.kt 100.00% <100.00%> (ø)
...ugin/plugin/src/main/java/com/yelp/codegen/Main.kt 98.33% <0.00%> (-0.06%) ⬇️
...rc/main/java/com/yelp/codegen/utils/StringUtils.kt 100.00% <0.00%> (+11.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5318347...cdd09a3. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support polymorphism
2 participants