Skip to content
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

feat: Add x-enum-descriptions to generated Swagger documentation for Enum #1878

Merged
merged 1 commit into from
Oct 20, 2024

Conversation

wakamenod
Copy link
Contributor

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 and x-enum-varnames are now matched in order, and their descriptions are output in the x-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!

…Enums

This commit adds support for the x-enum-descriptions extension in the
generated Swagger documentation.

It aligns the order of enum comments with enum variable names and
outputs them as a new x-enum-descriptions array.
This change ensures that enum descriptions are clearly defined and ordered alongside the enum values and variable names.
Copy link
Contributor

@ubogdan ubogdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ubogdan ubogdan merged commit d649b90 into swaggo:master Oct 20, 2024
2 checks passed
@ubogdan
Copy link
Contributor

ubogdan commented Oct 20, 2024

@wakamenod Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants