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

[go-experimental] Add oneOf support #5150

Merged

Conversation

bkabrda
Copy link
Contributor

@bkabrda bkabrda commented Jan 29, 2020

This PR adds oneOf support in the same way it was added for Java clients recently in #5120. It contains a lot of refactoring to be able to use the same mechanisms as were used to implement this feature for Java. Also see #4785 for discussion on semantics of oneOf and thoughts on why it was implemented that way for Java.

Note that this PR doesn't contain any tests right now. I do want to add tests, but would like to do that after the general direction of this PR and the related refactoring is approved.

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.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@antihax (2017/11) @bvwells (2017/12) @grokify (2018/07) @kemokemo (2018/09) @bkabrda (2019/07)

@bkabrda
Copy link
Contributor Author

bkabrda commented Jan 30, 2020

FTR, I don't think that the Shippable failure is related to this PR:

> Task :compileKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileKotlin'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not download jackson-coreutils.jar (com.github.fge:jackson-coreutils:1.8)
      > Could not get resource 'https://jcenter.bintray.com/com/github/fge/jackson-coreutils/1.8/jackson-coreutils-1.8.jar'.
         > Could not GET 'https://repo.jfrog.org/artifactory/libs-release-bintray/com/github/fge/jackson-coreutils/1.8/jackson-coreutils-1.8.jar?referrer'.
            > sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

@jimschubert jimschubert changed the base branch from 4.3.x to master February 5, 2020 02:25
Copy link
Member

@jimschubert jimschubert left a comment

Choose a reason for hiding this comment

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

This looks fantastic. I'm going to give it a few days or so to get feedback from anyone else on the core team or collaborator team if they'd like to review.

cc @OpenAPITools/openapi-generator-core-team

@jimschubert
Copy link
Member

I retargeted to master and fixe a merge conflict in model.mustache. Could you look at that merge resolution to see if it might interfere with your changes (map model/parent block right below the new vendor-extension addition).

@bkabrda
Copy link
Contributor Author

bkabrda commented Feb 5, 2020

@jimschubert thanks for the review! I'll try to address the points that you raised during today. I checked the conflict resolution and it LGTM.

Additionally, I recently submitted #5175 which will need to be extended to account for changes in this PR. I'd prefer if it was left until after this is merged, because rebasing this PR is harder. I'll leave a message on that PR as well to not add unnecessary work with rebasing.

@bkabrda
Copy link
Contributor Author

bkabrda commented Feb 5, 2020

So I fixed the review comments as best I could. I will work on adding tests until EOW.

@@ -377,8 +377,9 @@ private void registerMustacheLambdas() {
for (Object _implmo : models) {
Map<String, Object> implmo = (Map<String, Object>) _implmo;
CodegenModel implcm = (CodegenModel) implmo.get("model");
if (additionalDataMap.containsKey(implcm.name)) {
additionalDataMap.get(implcm.name).addToImplementor(this, implcm, imports, addOneOfInterfaceImports);
String modelName = toModelName(implcm.name);
Copy link
Contributor

@jirikuncar jirikuncar Feb 5, 2020

Choose a reason for hiding this comment

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

📛Thank you!

@bkabrda
Copy link
Contributor Author

bkabrda commented Feb 6, 2020

I added some basic tests for the OneOfImplementorAdditionalData and DefaultCodegen.preprocessOpenAPI. I didn't manage to find out an easy way to test the DefaultCodegen.postProcessAllModels method, since it looks like either I'd need to instantiate and run DefaultGenerator or I'd have to create the whole model structure by hand, none of which seem to be very straightforward. If anyone has recommendations on how to do this, I'd be glad to hear them.

@jimschubert
Copy link
Member

@bkabrda it's not easy to get at postProcessAllModels. I plan to do some pretty heavy refactoring for the 5.0 release. One of the remaining things I'm trying to complete in 4.x would be a dry-run generator option, which could probably be used for testing those harder accessible methods. I'm maybe a couple weeks away from having time to complete the dry-run generation.

@bkabrda
Copy link
Contributor Author

bkabrda commented Feb 10, 2020

@jimschubert that sounds great. I'm assuming it's ok to not have this part tested ATM? I'll be happy to add the tests once the refactored code is pushed.

LMK when this is ok to be merged, I'll do a rebase then (since this change now spans several files that tend to change quite often, I don't want to spend too much time rebasing it).

@jimschubert
Copy link
Member

Yeah, it's ok to leave out that test. I'm fine with a rebase and merge now.

tbh, you've added more tests than most people do!

@bkabrda
Copy link
Contributor Author

bkabrda commented Feb 10, 2020

Thanks :) let me do the rebase and let's get this merged!

@bkabrda bkabrda force-pushed the go-experimental-oneof-support branch from 01968ef to 347eaf7 Compare February 10, 2020 13:41
@bkabrda
Copy link
Contributor Author

bkabrda commented Feb 10, 2020

Rebased. I retested everything locally, but let's wait for CI anyway to make sure I did everything right.

@jimschubert jimschubert merged commit 0693a83 into OpenAPITools:master Feb 10, 2020
MikailBag pushed a commit to MikailBag/openapi-generator that referenced this pull request Mar 23, 2020
* [go-experimental] Add oneOf support

* Fix docs for the oneOf models

* isOneOfInterface => x-is-one-of-interface

* Add proper warnings when inline models are used in oneOf choices

* Add a convenience method to oneOf implementing structs to cast them as the oneOf interface

* Update modules/openapi-generator/src/main/resources/go-experimental/model.mustache

Co-Authored-By: Jiri Kuncar <[email protected]>

* Fix retrieving data from additionalDataMap

* Add basic tests

Co-authored-by: Jiri Kuncar <[email protected]>
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.

3 participants