* v3.14.0

* fix: simplify config fetch interceptor implementation

* add `loadRemoteConfig` flag to requests

* v3.14.0
This commit is contained in:
kyle
2018-04-27 23:20:13 -07:00
committed by GitHub
parent 8cef3adfe6
commit 7049de6201
11 changed files with 43 additions and 104 deletions

View File

@@ -22,7 +22,7 @@ The OpenAPI Specification has undergone 5 revisions since initial creation in 20
Swagger UI Version | Release Date | OpenAPI Spec compatibility | Notes Swagger UI Version | Release Date | OpenAPI Spec compatibility | Notes
------------------ | ------------ | -------------------------- | ----- ------------------ | ------------ | -------------------------- | -----
3.13.5 | 2018-04-20 | 2.0, 3.0 | [tag v3.13.5](https://github.com/swagger-api/swagger-ui/tree/v3.13.5) 3.14.0 | 2018-04-27 | 2.0, 3.0 | [tag v3.14.0](https://github.com/swagger-api/swagger-ui/tree/v3.14.0)
3.0.21 | 2017-07-26 | 2.0 | [tag v3.0.21](https://github.com/swagger-api/swagger-ui/tree/v3.0.21) 3.0.21 | 2017-07-26 | 2.0 | [tag v3.0.21](https://github.com/swagger-api/swagger-ui/tree/v3.0.21)
2.2.10 | 2017-01-04 | 1.1, 1.2, 2.0 | [tag v2.2.10](https://github.com/swagger-api/swagger-ui/tree/v2.2.10) 2.2.10 | 2017-01-04 | 1.1, 1.2, 2.0 | [tag v2.2.10](https://github.com/swagger-api/swagger-ui/tree/v2.2.10)
2.1.5 | 2016-07-20 | 1.1, 1.2, 2.0 | [tag v2.1.5](https://github.com/swagger-api/swagger-ui/tree/v2.1.5) 2.1.5 | 2016-07-20 | 1.1, 1.2, 2.0 | [tag v2.1.5](https://github.com/swagger-api/swagger-ui/tree/v2.1.5)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
dist/swagger-ui.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
{ {
"name": "swagger-ui", "name": "swagger-ui",
"version": "3.13.6", "version": "3.14.0",
"main": "dist/swagger-ui.js", "main": "dist/swagger-ui.js",
"repository": "git@github.com:swagger-api/swagger-ui.git", "repository": "git@github.com:swagger-api/swagger-ui.git",
"contributors": [ "contributors": [

View File

@@ -173,7 +173,12 @@ module.exports = function SwaggerUI(opts) {
let configUrl = queryConfig.config || constructorConfig.configUrl let configUrl = queryConfig.config || constructorConfig.configUrl
if (!configUrl || !system.specActions.getConfigByUrl || system.specActions.getConfigByUrl && !system.specActions.getConfigByUrl(configUrl, downloadSpec)) { if (!configUrl || !system.specActions.getConfigByUrl || system.specActions.getConfigByUrl && !system.specActions.getConfigByUrl({
url: configUrl,
loadRemoteConfig: true,
requestInterceptor: constructorConfig.requestInterceptor,
responseInterceptor: constructorConfig.responseInterceptor,
}, downloadSpec)) {
return downloadSpec() return downloadSpec()
} }

View File

@@ -1,23 +1,14 @@
import { parseYamlConfig } from "./helpers" import { parseYamlConfig } from "./helpers"
export const downloadConfig = (url) => ({fn: { fetch }, getConfigs}) => { export const downloadConfig = (req) => (system) => {
const { requestInterceptor, responseInterceptor } = getConfigs() const {fn: { fetch }} = system
let req = { url }
if(requestInterceptor) {
req = requestInterceptor(req)
}
return fetch(req) return fetch(req)
.then(res => {
if(res) {
return responseInterceptor(res)
}
return res
})
} }
export const getConfigByUrl = (configUrl, cb)=> ({ specActions }) => { export const getConfigByUrl = (req, cb)=> ({ specActions }) => {
if (configUrl) { if (req) {
return specActions.downloadConfig(configUrl).then(next, next) return specActions.downloadConfig(req).then(next, next)
} }
function next(res) { function next(res) {
@@ -25,7 +16,7 @@ export const getConfigByUrl = (configUrl, cb)=> ({ specActions }) => {
specActions.updateLoadingStatus("failedConfig") specActions.updateLoadingStatus("failedConfig")
specActions.updateLoadingStatus("failedConfig") specActions.updateLoadingStatus("failedConfig")
specActions.updateUrl("") specActions.updateUrl("")
console.error(res.statusText + " " + configUrl) console.error(res.statusText + " " + req.url)
cb(null) cb(null)
} else { } else {
cb(parseYamlConfig(res.text)) cb(parseYamlConfig(res.text))

View File

@@ -5,80 +5,23 @@ import { downloadConfig } from "corePlugins/configs/spec-actions"
describe("configs plugin - actions", () => { describe("configs plugin - actions", () => {
describe("downloadConfig", () => { describe("downloadConfig", () => {
it("should call the system fetch helper with a provided url", () => { it("should call the system fetch helper with a provided request", () => {
const fetchSpy = createSpy(async () => {}).andCallThrough() const fetchSpy = createSpy(async () => {}).andCallThrough()
const system = { const system = {
fn: { fn: {
fetch: fetchSpy fetch: fetchSpy
},
getConfigs() {
return {}
} }
} }
const url = "http://swagger.io/one" const req = {
url: "http://swagger.io/one",
downloadConfig(url)(system) requestInterceptor: a => a,
responseInterceptor: a => a,
expect(fetchSpy).toHaveBeenCalledWith({
url: url
})
})
it("should allow the globally configured requestInterceptor to modify the request", () => {
const fetchSpy = createSpy(async () => {}).andCallThrough()
const requestInterceptorSpy = createSpy((req) => {
req.url = "http://swagger.io/two"
return req
}).andCallThrough()
const system = {
fn: {
fetch: fetchSpy
},
getConfigs() {
return {
requestInterceptor: requestInterceptorSpy
}
}
} }
const url = "http://swagger.io/one" downloadConfig(req)(system)
downloadConfig(url)(system) expect(fetchSpy).toHaveBeenCalledWith(req)
expect(fetchSpy).toHaveBeenCalledWith({
url: "http://swagger.io/two"
})
})
it("should allow the globally configured responseInterceptor to modify the response", async () => {
const fetchSpy = createSpy(async (req) => {
return {
url: req.url,
ok: true
}
}).andCallThrough()
const responseInterceptorSpy = createSpy((res) => {
res.url = "http://swagger.io/two"
return res
}).andCallThrough()
const system = {
fn: {
fetch: fetchSpy
},
getConfigs() {
return {
responseInterceptor: responseInterceptorSpy
}
}
}
const url = "http://swagger.io/one"
const res = await downloadConfig(url)(system)
expect(res).toEqual({
url: "http://swagger.io/two",
ok: true
})
}) })
}) })
}) })