Merge pull request #3303 from Adrael/feature/apisSorter
Adding apisSorter options
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@ node_modules
|
|||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
.eslintcache
|
.eslintcache
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
*.iml
|
||||||
|
|||||||
23
README.md
23
README.md
@@ -82,17 +82,17 @@ To use swagger-ui's bundles, you should take a look at the [source of swagger-ui
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const ui = SwaggerUIBundle({
|
const ui = SwaggerUIBundle({
|
||||||
url: "http://petstore.swagger.io/v2/swagger.json",
|
url: "http://petstore.swagger.io/v2/swagger.json",
|
||||||
dom_id: '#swagger-ui',
|
dom_id: '#swagger-ui',
|
||||||
presets: [
|
presets: [
|
||||||
SwaggerUIBundle.presets.apis,
|
SwaggerUIBundle.presets.apis,
|
||||||
SwaggerUIStandalonePreset
|
SwaggerUIStandalonePreset
|
||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
SwaggerUIBundle.plugins.DownloadUrl
|
SwaggerUIBundle.plugins.DownloadUrl
|
||||||
],
|
],
|
||||||
layout: "StandaloneLayout"
|
layout: "StandaloneLayout"
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
#### OAuth2 configuration
|
#### OAuth2 configuration
|
||||||
@@ -137,6 +137,7 @@ spec | A JSON object describing the OpenAPI Specification. When used, the `url`
|
|||||||
validatorUrl | By default, Swagger-UI attempts to validate specs against swagger.io's online validator. You can use this parameter to set a different validator URL, for example for locally deployed validators ([Validator Badge](https://github.com/swagger-api/validator-badge)). Setting it to `null` will disable validation.
|
validatorUrl | By default, Swagger-UI attempts to validate specs against swagger.io's online validator. You can use this parameter to set a different validator URL, for example for locally deployed validators ([Validator Badge](https://github.com/swagger-api/validator-badge)). Setting it to `null` will disable validation.
|
||||||
dom_id | The id of a dom element inside which SwaggerUi will put the user interface for swagger.
|
dom_id | The id of a dom element inside which SwaggerUi will put the user interface for swagger.
|
||||||
oauth2RedirectUrl | OAuth redirect URL
|
oauth2RedirectUrl | OAuth redirect URL
|
||||||
|
tagsSorter | Apply a sort to the tag list of each API. It can be 'alpha' (sort by paths alphanumerically) or a function (see [Array.prototype.sort()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) to learn how to write a sort function). Two tag name strings are passed to the sorter for each pass. Default is the order determined by Swagger-UI.
|
||||||
operationsSorter | Apply a sort to the operation list of each API. It can be 'alpha' (sort by paths alphanumerically), 'method' (sort by HTTP method) or a function (see Array.prototype.sort() to know how sort function works). Default is the order returned by the server unchanged.
|
operationsSorter | Apply a sort to the operation list of each API. It can be 'alpha' (sort by paths alphanumerically), 'method' (sort by HTTP method) or a function (see Array.prototype.sort() to know how sort function works). Default is the order returned by the server unchanged.
|
||||||
configUrl | Configs URL
|
configUrl | Configs URL
|
||||||
parameterMacro | MUST be a function. Function to set default value to parameters. Accepts two arguments parameterMacro(operation, parameter). Operation and parameter are objects passed for context, both remain immutable
|
parameterMacro | MUST be a function. Function to set default value to parameters. Accepts two arguments parameterMacro(operation, parameter). Operation and parameter are objects passed for context, both remain immutable
|
||||||
|
|||||||
@@ -11,15 +11,15 @@
|
|||||||
<style>
|
<style>
|
||||||
html
|
html
|
||||||
{
|
{
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
overflow: -moz-scrollbars-vertical;
|
overflow: -moz-scrollbars-vertical;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
*,
|
*,
|
||||||
*:before,
|
*:before,
|
||||||
*:after
|
*:after
|
||||||
{
|
{
|
||||||
box-sizing: inherit;
|
box-sizing: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
|
||||||
<defs>
|
<defs>
|
||||||
<symbol viewBox="0 0 20 20" id="unlocked">
|
<symbol viewBox="0 0 20 20" id="unlocked">
|
||||||
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
|
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
|
||||||
</symbol>
|
</symbol>
|
||||||
|
|
||||||
<symbol viewBox="0 0 20 20" id="locked">
|
<symbol viewBox="0 0 20 20" id="locked">
|
||||||
@@ -70,34 +70,34 @@
|
|||||||
<script src="./swagger-ui-bundle.js"> </script>
|
<script src="./swagger-ui-bundle.js"> </script>
|
||||||
<script src="./swagger-ui-standalone-preset.js"> </script>
|
<script src="./swagger-ui-standalone-preset.js"> </script>
|
||||||
<script>
|
<script>
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
window["SwaggerUIBundle"] = window["swagger-ui-bundle"]
|
window["SwaggerUIBundle"] = window["swagger-ui-bundle"]
|
||||||
window["SwaggerUIStandalonePreset"] = window["swagger-ui-standalone-preset"]
|
window["SwaggerUIStandalonePreset"] = window["swagger-ui-standalone-preset"]
|
||||||
// Build a system
|
// Build a system
|
||||||
const ui = SwaggerUIBundle({
|
const ui = SwaggerUIBundle({
|
||||||
url: "http://petstore.swagger.io/v2/swagger.json",
|
url: "http://petstore.swagger.io/v2/swagger.json",
|
||||||
dom_id: '#swagger-ui',
|
dom_id: '#swagger-ui',
|
||||||
presets: [
|
presets: [
|
||||||
SwaggerUIBundle.presets.apis,
|
SwaggerUIBundle.presets.apis,
|
||||||
SwaggerUIStandalonePreset
|
SwaggerUIStandalonePreset
|
||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
SwaggerUIBundle.plugins.DownloadUrl
|
SwaggerUIBundle.plugins.DownloadUrl
|
||||||
],
|
],
|
||||||
layout: "StandaloneLayout"
|
layout: "StandaloneLayout"
|
||||||
})
|
})
|
||||||
|
|
||||||
window.ui = ui
|
window.ui = ui
|
||||||
|
|
||||||
ui.initOAuth({
|
ui.initOAuth({
|
||||||
clientId: "your-client-id",
|
clientId: "your-client-id",
|
||||||
clientSecret: "your-client-secret-if-required",
|
clientSecret: "your-client-secret-if-required",
|
||||||
realm: "your-realms",
|
realm: "your-realms",
|
||||||
appName: "your-app-name",
|
appName: "your-app-name",
|
||||||
scopeSeparator: " ",
|
scopeSeparator: " ",
|
||||||
additionalQueryStringParams: {}
|
additionalQueryStringParams: {}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,31 @@ import ApisPreset from "core/presets/apis"
|
|||||||
import * as AllPlugins from "core/plugins/all"
|
import * as AllPlugins from "core/plugins/all"
|
||||||
import { parseSeach, filterConfigs } from "core/utils"
|
import { parseSeach, filterConfigs } from "core/utils"
|
||||||
|
|
||||||
const CONFIGS = [ "url", "urls", "urls.primaryName", "spec", "validatorUrl", "onComplete", "onFailure", "authorizations", "docExpansion", "maxDisplayedTags", "filter",
|
const CONFIGS = [
|
||||||
"apisSorter", "operationsSorter", "supportedSubmitMethods", "dom_id", "defaultModelRendering", "oauth2RedirectUrl",
|
"url",
|
||||||
"showRequestHeaders", "custom", "modelPropertyMacro", "parameterMacro", "displayOperationId" , "displayRequestDuration"]
|
"urls",
|
||||||
|
"urls.primaryName",
|
||||||
|
"spec",
|
||||||
|
"validatorUrl",
|
||||||
|
"onComplete",
|
||||||
|
"onFailure",
|
||||||
|
"authorizations",
|
||||||
|
"docExpansion",
|
||||||
|
"tagsSorter",
|
||||||
|
"maxDisplayedTags",
|
||||||
|
"filter",
|
||||||
|
"operationsSorter",
|
||||||
|
"supportedSubmitMethods",
|
||||||
|
"dom_id",
|
||||||
|
"defaultModelRendering",
|
||||||
|
"oauth2RedirectUrl",
|
||||||
|
"showRequestHeaders",
|
||||||
|
"custom",
|
||||||
|
"modelPropertyMacro",
|
||||||
|
"parameterMacro",
|
||||||
|
"displayOperationId",
|
||||||
|
"displayRequestDuration",
|
||||||
|
]
|
||||||
|
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
const { GIT_DIRTY, GIT_COMMIT, PACKAGE_VERSION, HOSTNAME, BUILD_TIME } = buildInfo
|
const { GIT_DIRTY, GIT_COMMIT, PACKAGE_VERSION, HOSTNAME, BUILD_TIME } = buildInfo
|
||||||
|
|||||||
@@ -200,15 +200,22 @@ export const operationsWithTags = createSelector(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
export const taggedOperations = ( state ) =>( { getConfigs } ) => {
|
export const taggedOperations = (state) => ({ getConfigs }) => {
|
||||||
let { operationsSorter }= getConfigs()
|
let { tagsSorter, operationsSorter } = getConfigs()
|
||||||
|
return operationsWithTags(state)
|
||||||
|
.sortBy(
|
||||||
|
(val, key) => key, // get the name of the tag to be passed to the sorter
|
||||||
|
(tagA, tagB) => {
|
||||||
|
let sortFn = (typeof tagsSorter === "function" ? tagsSorter : sorters.tagsSorter[ tagsSorter ])
|
||||||
|
return (!sortFn ? null : sortFn(tagA, tagB))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.map((ops, tag) => {
|
||||||
|
let sortFn = (typeof operationsSorter === "function" ? operationsSorter : sorters.operationsSorter[ operationsSorter ])
|
||||||
|
let operations = (!sortFn ? ops : ops.sort(sortFn))
|
||||||
|
|
||||||
return operationsWithTags(state).map((ops, tag) => {
|
return Map({ tagDetails: tagDetails(state, tag), operations: operations })
|
||||||
let sortFn = typeof operationsSorter === "function" ? operationsSorter
|
})
|
||||||
: sorters.operationsSorter[operationsSorter]
|
|
||||||
let operations = !sortFn ? ops : ops.sort(sortFn)
|
|
||||||
|
|
||||||
return Map({tagDetails: tagDetails(state, tag), operations: operations})})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const responses = createSelector(
|
export const responses = createSelector(
|
||||||
|
|||||||
@@ -574,6 +574,9 @@ export const sorters = {
|
|||||||
operationsSorter: {
|
operationsSorter: {
|
||||||
alpha: (a, b) => a.get("path").localeCompare(b.get("path")),
|
alpha: (a, b) => a.get("path").localeCompare(b.get("path")),
|
||||||
method: (a, b) => a.get("method").localeCompare(b.get("method"))
|
method: (a, b) => a.get("method").localeCompare(b.get("method"))
|
||||||
|
},
|
||||||
|
tagsSorter: {
|
||||||
|
alpha: (a, b) => a.localeCompare(b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user