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.
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
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