-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Support models with multi-level hierarchy #4454
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
Support models with multi-level hierarchy #4454
Conversation
a48b0d6 to
b6a9b8f
Compare
725bfb0 to
1db0d6d
Compare
1db0d6d to
2009cc4
Compare
This is highly frustrating. What am I supposed to do to nurse this change through? |
|
@roxspring I've looked over the recent CircleCI builds for your PR, and I'll provide analysis of these to help clarify for you:
I'm unable to repro verification issues with scalaz (see below), but I'd recommend commenting it out of pom.xml (~ lines 1101, 1193) if it occurs again and we'll look into it further. Regarding your change, I'm confused a bit by this block: String parentName = getSimpleRef(schema.get$ref());
Schema s = allSchemas.get(parentName);
if (s != null) {
return hasOrInheritsDiscriminator(s, allSchemas);
}
else {
LOGGER.error("Failed to obtain schema from {}", parentName);
}I generated samples against your branch and opened #4503 to see how CI fares. Here are the steps I follow before pushing to a branch (and running that The last line will run the same batch command I provided you previously. |
|
Commented too soon :) |
Thanks @jimschubert - really appreciate you taking a look!
Yes, this makes sense. I'd run
Admittedly I'd never used scala before but I installed it this evening and attempted to compile master via
Yes, after the partial set of samples, I resubmitted with a full
I'll rebuild the samples and push those too shortly.
Assuming all is still broken then I'll retry with that - thanks again for the pointers!
At some point since
|
To clarify our process a bit... We have historically only regenerated the more active generators, but verified all (with some exclusions commented on the pom) that can be built via Maven. This allows us to track breaking changes in the most popular generators regularly, but less used generators would get updated only when those generators change. This was done because our script previously took 9 minutes or more to iterate only the popular generators. I'd tried once for all generators and it took over 30 minutes. This is a main reason I've introduced the When we see a version file with 3.0.0, that does indicate this hasn't been generated, but also that we've had no major contributions to that specific generator since then. |
That makes some sense. From what I can see though, regenerating scalaz against master (or my branch) results in the errors #4072. I'm seeing this under both Java 8 & 11, and not seeing My speculation is some changes inherited from |
ffa7493 to
20d1f9d
Compare
cb2ae72 to
547c401
Compare
|
Rebased on master and making more progress through CI but not quite there yet. The latest CI failure appears to be due to <groupId>com.prokarma</groupId>
<artifactId>pkmst-microservice</artifactId>
<version></version>The relevant |
|
@roxspring please feel free to revert the change to this file. I'm not sure, but it seems like it's leftover from when you ran all shell scripts under @OpenAPITools/generator-core-team please review and provide feedback. I'd be happy to help normalize CI through my eval PR. I suspect something is corrupted in this PR's CircleCI cache, since my PR is the same code with regenerated samples and it's green as expected. |
|
Opened #4520 to address the issue from java-pkmst. The issue would have affected all java clients and servers which don't explicitly pass an artifact version at generation time and don't have an API version specified in the OpenAPI Document. @roxspring I really appreciate your diligence, as you're both directly and indirectly resolving multiple issues via this one contribution. |
f8c88a4 to
4470630
Compare
I've rebased again to pick up this change but CircleCI is failing with yet more failures I don't understand. At this stage I'm choosing to believe that you're right about the CircleCI cache. Hopefully we can discuss the code change itself as I think it's relatively straight forward and resolves a series of (near) duplicate issues raised over the past year or more.
Thanks @jimschubert for all the help you've provided! Let me know if there's anything further to be done with this PR, happy to switch to your eval PR if it gets the job done. |
|
@roxspring no problem. I've pinged the core team for review, mainly because of the change to the shared yaml and to have multiple eyes for any edge cases. If everything is cool, we can merge the PR I've opened and you'll still be associated as an author. |
|
I have executed the code generator from the multi-level-model-hierarchy branch. I confirm it generates the Java code as expected when there are multiple levels of inheritance hierarchy. I have tried with my own test model. One caveat is that in the following scenario, the generated Java code will fail compilation:
In that case the Java compiler fails with "objectType has private access" because the generated code attempts to access the private member from the parent Java class. |
If I've understood correctly then you're saying:
I guess that also naturally leaves the question (4) about "Redefine discriminator property but not attribute in intermediate level". Scenarios (3) and (4) seem pretty non-sensical to me. Is it absolutely clear what code should be generated in these cases? I think I can get my head around it making sense in a SQL schema but I'm struggling for a Java model. For me they don't seem worth holding up the merge request but I'm aware that I'm biased! If folks really think it is worth holding up the merge then please let me know - ideally with some reasoned example of what should be produced in those cases. (I'm ignoring conflicts in the generated samples until the code needs rebasing and/or I'm recommended otherwise) |
IMO, your PR makes the code better, and the small caveat I pointed out should not block the merge. I was trying these combinations not because I think they are practical, but rather because I was trying to understand why the code was not generated as I expected (and also because the "discriminator" specification in OAS is not very clear). That's how I found the same bug that you addressed in this PR. I also empathize with the PR having a lot of file changes. |
|
Hi folks, is there anything I can do to drive this (or alternatively #4503) further forward towards review and integration? |
If there is anything I can do to test or validate, I would also be very interested to get this feature available. |
|
@roxspring should we also add these ancestor models to the: |
|
@roxspring, I tried to apply your change in my local clone in order to test with my inheritance models, but I received many conflicting errors... |
At this stage I'm still unclear how these are actually used so I'm really not sure. If somebody with a better understanding can explain the requirement clearly to me then I'll be happy to work on a solution. I'd prefer to get this MR in and open a subsequent one for any such improvements though as this addresses a painful regression against earlier behaviour and I don't want to delay it any further than it has been already.
What conflicts? Conflicts with the samples are inevitable and I've already stated I'm not going to regenerate those again until that becomes a blocking issue - you can use |
|
@roxspring, when I said conflict, I was referring about git merge conflicts that I had when I tried to apply your fixes. That happen because master branch had many commit after you have sent this PR. (Take a look in the ending of this page: There is a "This branch has conflicts that must be resolved" message.) Anyway I was able to apply the fixes manually in the important classes and seems to be working well with my java model. |
|
I've pinged the core team again and asked for a review of #4503, since it builds cleanly. My biggest question would be the impact of the change to the shared yaml which generates most samples. |
|
Given the headaches it caused, I'd have preferred not to modify the shared swagger and all the samples too... but I'm curious if that would have been acceptable? I got the impression that those samples were supposed to be exercising all supported features and therefore any successful merge request to add these features would have to modify them? |
|
@roxspring I believe we can close this with #4503 (merged). Thanks for the contribution 👍 |

BigCatextendingCat(which extendsAnimal) to the petstore-with-fake-endpoints spec.ModelUtils.getAllParentsName()gains optional ability to include ancestor names, not just immediate parents.ModelUtilsconsiders composed interface a parent if it has a discriminator OR inherits one.Fixes #4423, #1685, #2928, #3058
Primarily for the attention of core team: @wing328 @jimschubert @cbornet @ackintosh @jmini @etherealjoy
Generator teams may also be interested - I've focused on checking the Java code myself.
PR checklist
./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.shif updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).(actually ran
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar batch --includes-base-dirpwd--fail-fast -- bin/ci/*as recommended by @jimschubert)master,4.3.x,5.0.x. Default:master.