springdoc-openapi
springdoc-openapi copied to clipboard
Ensure default media type order is preserved using LinkedHashSet in mergeArrays. Fixes #2671
#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 useLinkedHashSet
instead ofHashSet
to preserve the order of media types.
- Modified
-
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.
- Added unit tests to verify that the
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 handlesnull
as the first array correctly. -
testDefaultProducesMediaType
: Verifies that the defaultproduces
media type is correctly set. -
testDefaultConsumesMediaType
: Verifies that the defaultconsumes
media type is correctly set.
Please review the changes and let me know if any further adjustments are needed.
Thank you!