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

[Kotlin] Correct isInherited flag for Kotlin generators #4254

Merged
merged 2 commits into from
Jan 5, 2020
Merged

[Kotlin] Correct isInherited flag for Kotlin generators #4254

merged 2 commits into from
Jan 5, 2020

Conversation

mtraynham
Copy link
Contributor

@mtraynham mtraynham commented Oct 24, 2019

Most of the Kotlin generator templates loop requiredVars and optionalVars (1, 2) . Unfortunately, it looks like during the CodegenModel.removeAllDuplicatedProperty, the CodegenProperty's are all cloned and therefore the current implementation of only updating the allVars list isn't sufficient to reflect that in requiredVars or optionalVars.

All 3 lists (allVars, requiredVars, optionalVars) should be updated with the isInherited property.

Also, the KotlinSpringServerCodegen was doing the same thing as AbstractKotlinCodegen so I removed it.

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@jimschubert @dr4ke616 @karismann @Zomzog

@mtraynham
Copy link
Contributor Author

@jimschubert @dr4ke616 @karismann @Zomzog @wing328 any feedback on this would be appreciated!

@jimschubert
Copy link
Member

@mtraynham sorry. I've been super busy. I'm trying to get caught up on some issues over the next couple of days.

Good catch on the clone call in CodegenModel.removeAllDuplicatedProperty... that seems a little suspect to me and I can't tell if it was an intentional side effect there or not.

Looking over your code, it looks good and the comments are helpful. I was wondering if it would be possible to check the properties on the "final" model in the test, to avoid regressions? For example, if pm.requiredVars and pm.optionalVars were ever inadvertently truncated or didn't hold exactly the intended properties, it seems this test would still pass.

@mtraynham
Copy link
Contributor Author

mtraynham commented Nov 11, 2019

Hey @jimschubert, I'll rebase so there aren't conflicts and add a check to verify that all the names of the properties in requiredVars and optionalVars. Sound good?

@jimschubert
Copy link
Member

@mtraynham Thanks! I checked the latest commit and it looks good. We'll merge once CI checks have completed.

@mtraynham
Copy link
Contributor Author

mtraynham commented Nov 11, 2019

Awesome, thanks @jimschubert!

I wanted to point out one thing, my test case change also coincides with a separate bug I found, #4253, where the optionalVars would have actually also contained a (requiredVars: a, c; optionalVars: a, b, d). This occurs when adding the requiredItems to the outer model of an allOf composed object and it duplicates parent required items into the optional vars list. If I instead move the required items to child of an allOf it works as you expect. Swagger-jaxrs is generating the former, where requiredItems is a combination of both the child and parent properties that lives on the outer properties of a composed model.

@mtraynham
Copy link
Contributor Author

@jimschubert @wing328 any chance you guys can take a look at this again?

@mtraynham
Copy link
Contributor Author

@jimschubert jimschubert added this to the 4.2.3 milestone Jan 5, 2020
@jimschubert
Copy link
Member

@mtraynham Thanks for pinging again. The holidays were super hectic for me, sorry for the long delay.

I appreciate that you merged with latest :)

@jimschubert jimschubert merged commit 38185d8 into OpenAPITools:master Jan 5, 2020
@mtraynham mtraynham deleted the correct_kotlin_inheritance branch January 5, 2020 16:47
jimschubert added a commit to jimschubert/openapi-generator that referenced this pull request Jan 11, 2020
* master: (187 commits)
  [core] Initial FeatureSet structures and definitions (OpenAPITools#3614)
  Add Cisco to the user list (OpenAPITools#4971)
  comment out php slim4 in ensure-up-to-date
  update samples
  [Python] Allow models to have properties of type self (OpenAPITools#4888)
  Add npmRepository option to javascript generators (OpenAPITools#4956)
  [Slim4] Add ref support to Data Mocker (OpenAPITools#4932)
  Fix auto-labeler for jax-rs (OpenAPITools#4943)
  [doc] full generator details (OpenAPITools#4941)
  comment out python flask 2 test (OpenAPITools#4949)
  [jaxrs-spec][quarkus] update to version 1.1.1.Final (OpenAPITools#4935)
  [cli] Full config help details (OpenAPITools#4928)
  Add RequestFile to typescript-node model template (OpenAPITools#4903)
  [csharp] enum suffix changes enumValueNameSuffix to enumValueSuffix (OpenAPITools#4927)
  [C#] allow customization of generated enum suffixes (OpenAPITools#4301)
  [Kotlin] Correct isInherited flag for Kotlin generators (OpenAPITools#4254)
  [Rust Server] Fix panic handling headers (OpenAPITools#4877)
  Initial CODEOWNERS (OpenAPITools#4924)
  [scala] Support for Set when array has uniqueItems=true (OpenAPITools#4926)
  remove nodejs server samples, scripts (OpenAPITools#4919)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants