-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
add support to generate subschemas as static nested classes #1380
base: master
Are you sure you want to change the base?
Conversation
885c6ae
to
1b83b04
Compare
1b83b04
to
c99c8d7
Compare
0a10483
to
39636fc
Compare
Not sure I fully understand the question. I have added this PR in order to add the support for the feature in question.
|
jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ObjectRule.java
Outdated
Show resolved
Hide resolved
fqn = fqn.substring(0, index) + ruleFactory.getGenerationConfig().getClassNamePrefix() + fqn.substring(index) + ruleFactory.getGenerationConfig().getClassNameSuffix(); | ||
} | ||
|
||
if (usePolymorphicDeserialization) { |
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.
It seems as usePolymorphicDeserialization
branch had no difference in outcome from the other one, hence it could be removed. Left it in so as not to pollute the PR with unrelated stuff.
Hello, and thanks for your fast answer!
Well, there already was an active PR for supporting that feature. Therefore I am asking. There is not much reason to create a PR that does exactly the same thing again. So there must be some differences.
I can't decide whether that's the case. Elegance is quite subjective. So that is something that the repository owner must decide.
Well, that's nice. I am not happy with the fact that a static map is used in the other PR. I found the following other differences between this PR and #1160:
I don't care much about which PR gets approved and integrated into jsonschema2pojo as long as both provide the same functionality. At the moment I see a small advantage of yours (not needing a static map) and a bigger disadvantage (generating top-level classes where nested classes should be generated and not respecting schema URI boundaries). Unfortunately both PRs are ignored by the repository owner up until now (ignored in that there was no reaction to them; not even a negative one). So we do not know what needs to be changed to get approved (apart from the comments on #1008 which was abandoned by the author). |
@hupfdule wow, many thanks for such a thorough review and your comments! I will address all of them individually soon, but the main priority is of course the functionality deficiency you have pointed out. Not sure how it got slipped through, I thought I had all corner cases covered. Again, thank you for pointing it out. |
@hupfdule, I have tried to reproduce the issue with the generation you have described, but I was unable to. I have added more explicit integration tests now, specifically canGenerateTheWholeDirectory() which generates all schemas in a given directory. The directory contains the following two files, each defining It passes fine and does not result in schemas defined inline being generated as top-level classes. Not sure if I am missing something? |
@wigbam Sorry for the late reply. I didn't notice have answered. Sorry, I have tried again. And I may be false. I have to try again. |
Yes, it seems I was wrong. I didn't test it thoroughly, but it seems to be working. But you should definitely not introduce changes unrelated to the actual Code. For example https://github.com/joelittlejohn/jsonschema2pojo/pull/1380/files#diff-e8700089f1b3fd621a3f5dc397def9056c689291769b3aa00222bdde3c8ff846L240. Is it necessary to remove an unused branch to fulfil the purpose of your PR? If not, then don't change it. Also your changes to the pom should be reverted. They have nothing to do with the actual functionality you want to introduce it should not be part of this PR (you can file a second PR for that purpose if you want). Now you should raise awareness on this PR. @joelittlejohn Can you give us some hints on whether you would accept either this PR or #1160? Would you consider to merge one of them (and which one) and what changes are necessary to get approved? |
Great! Thanks for confirming!
I don't agree and the reasoning is as follows:
I can agree here, those were not related to the PR. I will revert. |
2b82ee0
to
6615997
Compare
jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java
Show resolved
Hide resolved
I am going to keep this up-to-date in case it might get another look one day. |
I just noticed that your PR does not generate the nested class as |
Oh boy 🤦♂️ somehow it slipped through the cracks. I have it working locally. Will update today/tomorrow. Many thanks for the good spot! |
Hi guys :) Anything new with this PR? This would be a super useful addition. |
Hi, any update on it? I’d like to use your patch for a current project. |
007b9de
to
83edb0a
Compare
83edb0a
to
12b54ad
Compare
Things been quite hectic over the past month, but all is fixed and updated now. Please give it a try. |
12b54ad
to
6060219
Compare
Sorry that it took such a long time to answer, but I didn’t find the time to check earlier. Basically it looks good. The generated files seem to correct. Only one small remark. In https://github.com/wigbam/jsonschema2pojo/blob/6060219f977ead894f25b6d6b2c098ef7195074d/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java#L143 the annotation @Parameter(property = "jsonschema2pojo.useNestedClasses", defaultValue = "false") should be added to let maven generate the help information for it. I don’t know why this in not generated automatically, but apparently the annotation is necessary. |
Thanks for spotting. I have added the annotation as per above now. |
We are very interested in this feature. Is there an update on it? |
Even though initially this feature seemed like something that was of interest, @joelittlejohn 's latest comment doesn't seem to suggest that it will ever be merged, although I believe neither a code review nor a final decision has been made yet. So all I can do is keep this PR updated in the meantime Alternatively, I guess forking the project and having a separate release cycle and artifact might be a more practical option. If we get a NO then that will be the way to go. |
Looks like it can be moved to custom |
See issue #125
In regards to naming (inner vs nested), I believe 'nested' is a more correct term here (static nested class, to be precise):
https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html
I have added integration tests for both trivial and not-so-trivial use cases, but perhaps there are more edge cases.