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 option to sort list of endpoints (#288) #289

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PhlipTIP
Copy link

@PhlipTIP PhlipTIP commented Oct 16, 2023

Describe the PR
The content featured in the PR adds the OperationsSorter field to the configuration. This field let's the user customize how the API endpoints are displayed in the UI based on the input.

  • The input can be "alpha" to sort endpoints alphabetically (A-Z)
  • Input "method" to sort the endpoints by their methods (GET,POST,DELETE, PUT etc..)
  • Or a custom sort function of any kind such as: (a, b) => { var methodsOrder = ["get", "post", "put", "delete", "patch", "options", "trace"]; var result = methodsOrder.indexOf( a.get("method") ) - methodsOrder.indexOf( b.get("method") ); // Or if you want to sort the methods alphabetically (delete, get, head, options, ...): // var result = a.get("method").localeCompare(b.get("method")); if (result === 0) { result = a.get("path").localeCompare(b.get("path")); } return result; }

The default in the current version of gin-swagger is "alpha" and this is is still the default, but with this feature other options are available through adding custom config to the wrapHandler method.

Link to Swagger-ui doc referencing operationsSorter

Relation issue
Issue #288

Additional context
As the operationsSorter field in the window.onload function of the swaggerUI can be either a string ("method", "alpha") or a function itself we need to conditionally wrap the value in backticks with fmt.sprintf to denote whether the window.onload function should interpret the {{.operationsSorter}} value as either a string or js function.

All new features have been tested locally to ensure all three options are working correctly

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