Skip to content

Commit

Permalink
fix: redocOptions is not recognized correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
wll8 committed Jun 26, 2020
1 parent b36b9be commit cb13ef8
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions try.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,24 @@ function cfgHandle(userCfg) {
if (typeof (userCfg) === `string`) {
userCfg = { openApi: userCfg }
}
const { redocOptions } = userCfg
const testOpenApi = `//httpbin.org/spec.json` // `//petstore.swagger.io/v2/swagger.json`
const [redoc_openApi, redoc_options, redoc_dom, redoc_callBack] = userCfg.redocOptions || []
const redocOptionsRes = dataType(redocOptions, `object`) ? [undefined, redocOptions] : (redocOptions || [])
const [redoc_openApi, redoc_options, redoc_dom, redoc_callBack] = redocOptionsRes
const cfg = {
openApi: testOpenApi,
onlySwagger: false, // Only render swagger, in some cases redoc will render openApi error
tryText: `try`, // try button text
trySwaggerInApi: true, // Is the swagger debugging window displayed under the api? true: yes, false: displayed after the request, when the request is relatively large, you may not see the debugging window
...userCfg,
swaggerOptions: {
url: userCfg.openApi || testOpenApi,
dom_id: `#swagger-ui`,
onComplete: () => {
trySwagger(cfg)
},
...userCfg.swaggerOptions
},
redocOptions: [
redoc_openApi || userCfg.openApi || testOpenApi,
redoc_options || {enableConsole: true},
Expand All @@ -35,15 +46,6 @@ function cfgHandle(userCfg) {
$(`.swaggerBox`).addClass(`hide`)
},
],
swaggerOptions: {
url: userCfg.openApi || testOpenApi,
dom_id: `#swagger-ui`,
onComplete: () => {
trySwagger(cfg)
},
...userCfg.swaggerOptions
},
...userCfg,
}
return cfg
}
Expand Down Expand Up @@ -300,3 +302,8 @@ function getAbsolutePosition(domObj) { // Get element position and size
// Returns the coordinate set of positioned elements
return { width, height, top, left, right, bottom }
}

function dataType(data, type) {
const dataType = Object.prototype.toString.call(data).match(/\s(.+)]/)[1].toLowerCase()
return type ? (dataType === type.toLowerCase()) : dataType
}

0 comments on commit cb13ef8

Please sign in to comment.