-
Notifications
You must be signed in to change notification settings - Fork 82
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 definition of Schema property order #359
Comments
@MikeEdgar - would you consider joining the MP-OAI TC calls - they are normally held every other Monday at 10am your time (assuming GitHub isn't lying about your location). The next one is on the 15th. |
@EricWittmann , I'll add it to my calendar. |
We discussed this at the most recent TC meeting this week, so I am updating this based on that discussion. That said, @MikeEdgar has already documented the options pretty well. To summarize, we think there are three basic options here:
I think my preference is for (1) even though that further increases the That said, if (1) is the best option, then it might be best to come up with a solution that solves both this issue and issue #360 Perhaps the solution to #360 can be to introduce a new property called
With an example application that might be something like this: @Schema(properties={
@Schema(name="creditCard", required=true),
@Schema(name="departtureFlight", description="The departure flight information."),
@Schema(name="returningFlight")
})
public class Booking {
private Flight departtureFlight;
private Flight returningFlight;
private CreditCard creditCard; This approach would allow developers to indicate the order (in this case the order would be As mentioned in the TC call this week, the annotations could easily become out of sync with the actual java bean code (there is nothing but convention tying them together). However, I don't really see a solution to this problem that doesn't have that flaw. The implementation could output some sort of warning, perhaps, when the array of annotations in There's also the issue of data type hierarchies - if Thoughts? |
I do like this, but like we mentioned in #360, it might need to be adjusted a bit to account for the restrictions on annotation cycles in Java. Just to throw a few other options out there, these also popped into my head and I figured I would post here in case they have any value.
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.PACKAGE})
public @interface SchemaPropertyOrderStrategy {
Class<? extends PropertyOrderStrategy> value();
}
interface PropertyOrderStrategy {
List<String> order(List<String> properties);
} |
Thanks for the additional suggestions. And yes, anyone reading this should follow the conversation going on in #360 as well. Do you have a preferred solution to this? I'm on the fence, myself. |
I really do not at this point. I'm continuing to think it through. What are your top solutions? I like the idea of There may be a similar user response to using @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.PACKAGE})
public @interface SchemaPropertyOrder {
private PropertyOrderStrategy NATURAL = ...
private PropertyOrderStrategy ALPHA = ...
/* PropertyOrderStrategy defined in earlier comment. */
Class<? extends PropertyOrderStrategy> strategy() default NATURAL;
String[] value() default {};
}
public @interface Schema {
...
SchemaPropertyOrder propertyOrder() default ...; /* some reasonable default */
...
} |
I think your most recent proposal is a nice synthesis of the best options - combining the ability to specify the order of the properties and the ability to specify a strategy. So I'd be good with that. I don't like the option of adding |
I'm in agreement about not re-using the solution to #360. It might take some time to determine a good approach there and I think whatever solution we come up with will probably be too verbose for here. |
hey guys, joining the discussion late. Given the popularity / familiarity of Jackson within the Java community, my vote would be to use the As it was mentioned, there is a drawback of having this list out of sync with the actual properties, but perhaps we can put words in the spec such as: serialize properties that match the list in the specified order and then afterwards serialize in an undefined order any properties that did not match the list. |
What are your thoughts on having a |
hi @MikeEdgar - I was thinking that if user can specify the exact order of the properties, would they need to specify a strategy? |
I think the idea is that a strategy doesn't have the problem of going out of sync. |
That's right. Also, another scenario would be to define some built-in strategies like alphabetical order, i.e. like the values in |
My preference would be to add a new field to our existing |
Thinking about this some more, could we have a solution that is a bit of a hybrid of the proposals: a new field to |
That sounds reasonable to me. To be more specific, the solution would be to add both |
I was thinking about adding just the |
We agreed to take this to the architecture board to see what's the solution across other spec (for example, adopting JsonB's annotation to have index for each property) |
Hi all. Just to repeat here what I have said in the meeting. This will be similar to |
we discussed this item in today's hangout and decided to go with the |
What are the group's thoughts on placing the new |
sounds good to me. |
We'll wait on this one and (potentially) reconsider an approach that uses a common Jakarta annotation. |
There has been some discussion in smallrye/smallrye-open-api#87 around ways for a user of MP-OAI to define the order of properties read during annotation/class scanning. Although maybe not technically significant for formats like JSON and YAML, predicable order does help with readability and may be significant for formats like XML.
Several annotations are in common use today by the various serialization frameworks that could be looked at for an idea of how to implement the same option in MP-OAI
javax.json.bind.annotation.JsonbPropertyOrder
javax.xml.bind.annotation.XmlType#propOrder
com.fasterxml.jackson.annotation.JsonPropertyOrder
One possible option is to define a new
String[] propertyOrder
attribute in@Schema
that behaves similarly to the three format-specific annotations listed above.Other things to consider:
mp.openapi
configuration option to override orderingThe text was updated successfully, but these errors were encountered: