smallrye-open-api: Don't automatically sort object fields

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 😃

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 21 (15 by maintainers)

Commits related to this issue

Most upvoted comments

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

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.

As you proposed, I created a PR over at Jandex: https://github.com/wildfly/jandex/pull/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:

  1. https://github.com/smallrye/smallrye-open-api/blob/cdfbdb688e2aa681f05f9b4f22463855a859b23b/implementation/src/main/java/io/smallrye/openapi/api/util/ArchiveUtil.java#L154 to indexer.index(contentStream, true, false);
  2. I don’t know what CollectionStandin and MapStandin are for, but in case these need to be consistent with the indexed archive, you’d need to also change this line in the same way: https://github.com/smallrye/smallrye-open-api/blob/cdfbdb688e2aa681f05f9b4f22463855a859b23b/implementation/src/main/java/io/smallrye/openapi/api/util/ArchiveUtil.java#L133

Otherwise implementation could become a bit messy, because we’d need to read annotations before the indexer reads the class stream.