springdoc-openapi icon indicating copy to clipboard operation
springdoc-openapi copied to clipboard

Ensure default media type order is preserved using LinkedHashSet in mergeArrays. Fixes #2671

Open limehee opened this issue 6 months ago • 0 comments

#2671 - Ensure default media type order is preserved using LinkedHashSet in mergeArrays

Description

This PR addresses issue #2671 by ensuring that the order of media types is preserved in the mergeArrays method of the MethodAttributes class. Previously, HashSet was used, which did not guarantee the order of media types, causing the default media type not to be prioritized. This has been fixed by using LinkedHashSet to maintain the insertion order.

Changes

  • MethodAttributes.java:

    • Modified mergeArrays method to use LinkedHashSet instead of HashSet to preserve the order of media types.
  • MethodAttributesTest.java:

    • Added unit tests to verify that the mergeArrays method preserves the order of media types and that the default media type is prioritized.
    • Tests include scenarios with both non-null and null arrays.

Testing

Added the following tests to MethodAttributesTest to ensure the functionality:

  • testMergeArrays: Verifies that the order of media types is preserved when merging two arrays.
  • testMergeArraysWithNullArray1: Verifies that the method handles null as the first array correctly.
  • testDefaultProducesMediaType: Verifies that the default produces media type is correctly set.
  • testDefaultConsumesMediaType: Verifies that the default consumes media type is correctly set.

Please review the changes and let me know if any further adjustments are needed.

Thank you!

limehee avatar Aug 08 '24 03:08 limehee