-
Notifications
You must be signed in to change notification settings - Fork 86
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
Don't automatically sort object fields #87
Comments
This is a reasonable suggestion, for sure. Thanks for the report. |
I created an issue over at Jandex: smallrye/jandex#58 |
Agreed. |
This one is really bugging me so much that I today tried to work around it via reflection, but without success. |
https://github.com/wildfly/jandex is most definitely still developed and worked on. If you need something fixed there, just raise an issue and it will be looked at |
I did on April 8th (see comment above) and asked for a quick update on May 17th, but without an answer and the repo did not receive commits for three months now. That's why I thought it's temporarily/no longer maintained. |
Apologies, missed that link the first time. I know Jason has been traveling a lot of late, but can reach out about it |
If you're able to propose a solution a PR it's likely to get evaluated quicker |
Thought about that, but since the PR section looked similar in that regard I shied away from it. |
As you proposed, I created a PR over at Jandex: smallrye/jandex#61 If that gets merged and you don't want to add annotation driven control for sorting, this issue could be solved by changing one or two lines:
Otherwise implementation could become a bit messy, because we'd need to read annotations before the indexer reads the class stream. |
I think there's a good chance the PR will be merged, and we can update open-api to use it |
A few ideas on how to address this without only relying on the order from Jandex. These should all put the developer in control and not rely on an implementation detail.
If this seems like an OK approach, I am of course happy to look at implementing it. For number 3, I am thinking about using a convention similar to what was mentioned in #147. |
These are all great suggestions. My opinion is that (2) is the best in the short term. We can discuss (1) in the MPOAI community. I'm less enthusiastic about (3) only because I suspect it wouldn't be used often. But it would solve the problem where the target code cannot be modified. We can, of course, support all of these options eventually - we just need to decide on order of preference. For that, I would probably vote for (3), (1), (2), (default/current behavior). |
I do also think we should continue to try to get the change merged in jandex. I'm guessing no one disagrees with that. :) |
Bringing this one up at the spec level seems the ideal solution to me. We should figure out the specific morphology over there (perhaps you can join us @MikeEdgar ?), but this isn't a bad suggestion. Side node: I'm generally against adding options unless we figure we really need them; it's just going to become a maintenance and documentation pain in the long term (and eventual fun of conflicting options, and such). (2) also seems a great idea to me, and that could be done regardless. |
Normally I agree with you @msavy about config options. But what do you think about my comment regarding code that cannot be easily modified to include another annotation? Valid use-case? |
I'm all for pushing ideas up to the MP spec level to resolve, but let's not wait on that ceremony to include changes into the implementation |
@kenfinnigan Yes, I think option (2) can be done immediately. @EricWittmann You make a good point on the unmodifiable source/transitive dependencies. Although, I do wonder how wise it is for users to go down that track; it could get fragile very quickly, as there would be the propensity for the config to drift from the source and there would be no easy way to spot that (especially for those libraries out of their realm of control, so to speak). But, that does seem a valid use-case. One suggestion might just be that we speak in the next MP OAI meeting about what the option name should be, so we can 'pre-align' that for any future addition to the spec? (Given that field order is not guaranteed to be deterministic according to the spec, I think this area is always going to be a bit messy, even with 'natural' order). |
If I might add one thing regarding unmodifiable sources. Since we are (hopefully always) talking about interfaces over which the developer has full control, it should be questioned why they would directly read or write 3rd party entities over which they may not have control (de-/serializing wise). In my opinion endpoints and their input/output should be well-defined. |
I'm happy to join in or open an issue at the spec level.
I've been thinking more about this one and think there needs to be a good definition around the behavior. Also, as you said @msavy , it should pre-align with any potential standard. The situation gets a little messy when inheritance is involved, in particular. I haven't done any experimentation to see how Jackson or Yasson output looks, but the order below seems like the most intuitive at the moment.
Additionally, I think that if a field of the same name is defined in both a parent class and a child, the one in the child should be preferred. Something else I haven't experimented with, but I think the current implementation may be using the parent class's field. |
This issue is pending a Jandex change [smallrye/jandex#61] to support "remembering" the original order of field and method declaration in the class files used to generate the index. It may become a bigger issue at some point depending on the direction of eclipse/microprofile-open-api#359. |
Bumps [jakarta.servlet-api](https://github.com/eclipse-ee4j/servlet-api) from 4.0.3 to 4.0.4. - [Release notes](https://github.com/eclipse-ee4j/servlet-api/releases) - [Commits](https://github.com/eclipse-ee4j/servlet-api/commits) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Roberto Cortez <radcortez@yahoo.com>
I wondered why my OpenAPI file under Thorntail didn't look like I expected it to.
Classes under
components.schemas
always have sorted fields instead of their original order in the Java class.I think it's because you are using ClassInfo from Jandex internally to get the field info. Unfortunately ClassInfo does automatic field sorting: https://github.com/wildfly/jandex/blob/61d1115e0a0f15dcfb2b0bbd082100f847963529/src/main/java/org/jboss/jandex/ClassInfo.java#L557
There seems to be no option to disable this behavior. Neither in this implementation, nor in Jandex ClassInfo.
I suggest not to alter the property order or at least make it optional (default: false).
Thanks :)
The text was updated successfully, but these errors were encountered: