feat: Add x-enum-descriptions to generated Swagger documentation for Enum #1878
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces the
x-enum-descriptions
extension to the generated Swagger documentation when working with enums. The new extension provides a list of descriptions for enum values, aligned with the x-enum-varnames.Details of the changes:
A new constant enumDescriptionsExtension has been added to support the x-enum-descriptions extension.
The ParseDefinition function has been updated to create a x-enum-descriptions list based on the order of x-enum-varnames and corresponding enum comments.
The
x-enum-comments
andx-enum-varnames
are now matched in order, and their descriptions are output in thex-enum-descriptionfs
array.Test cases have been updated to reflect the addition of x-enum-descriptions, demonstrating the new output in the expected JSON.
Why this change is necessary:
The addition of x-enum-descriptions enhances the clarity and usability of Swagger documentation by ensuring that descriptions for enum values are explicitly defined and correctly ordered. This can be particularly useful for clients and developers who rely on clear enum definitions and descriptions in API documentation.
Testing:
Updated relevant test cases in testdata/enums/expected.json to include x-enum-descriptions.
Verified that the descriptions are correctly aligned with x-enum-varnames and appear in the expected order.
Impact:
This change does not affect existing functionality but adds a new optional extension to the generated documentation.
No breaking changes are introduced, and the update is backward compatible.
Please review the changes and let me know if there are any adjustments or additional tests needed. Your feedback is appreciated!