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