Compare commits

...
2 Commits
Author SHA1 Message Date
kyle 7049de6201 v3.14.0 (#4492)
* v3.14.0

* fix: simplify config fetch interceptor implementation

* add `loadRemoteConfig` flag to requests

* v3.14.0
2018-04-27 23:20:13 -07:00
kyle 8cef3adfe6 fix: path-item $ref operation metadata storage (#4489) 2018-04-27 10:29:33 -07:00
15 changed files with 99 additions and 105 deletions
+1 -1
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)
+14 -14
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
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
+2 -2
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
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": [
+6 -1
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()
} }
+7 -16
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))
+5 -1
View File
@@ -118,7 +118,11 @@ export default {
let operationPath = ["paths", ...path] let operationPath = ["paths", ...path]
let metaPath = ["meta", "paths", ...path] let metaPath = ["meta", "paths", ...path]
if(!state.getIn(["json", ...operationPath]) && !state.getIn(["resolved", ...operationPath])) { if(
!state.getIn(["json", ...operationPath])
&& !state.getIn(["resolved", ...operationPath])
&& !state.getIn(["resolvedSubtrees", ...operationPath])
) {
// do nothing if the operation does not exist // do nothing if the operation does not exist
return state return state
} }
+7 -64
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
})
}) })
}) })
}) })
+31
View File
@@ -0,0 +1,31 @@
describe("bug #4485: operation metadata storage when referenced via path item $ref", function () {
let mainPage
beforeEach(function (client, done) {
mainPage = client
.url("localhost:3230")
.page.main()
client.waitForElementVisible(".download-url-input", 5000)
.pause(2000)
.clearValue(".download-url-input")
.setValue(".download-url-input", "http://localhost:3230/test-specs/bugs/4485/main.yaml")
.click("button.download-url-button")
.pause(1000)
done()
})
afterEach(function (client, done) {
done()
})
it("sets a consumes value for a body parameter correctly", function (client) {
client.waitForElementVisible(".opblock-tag-section", 10000)
.click(".opblock")
.waitForElementVisible(".opblock-body", 5000)
.click("button.btn.try-out__btn")
.click("select.content-type [value=\"application/xml\"]")
.pause(500)
.assert.value("select.content-type", "application/xml")
client.end()
})
})
+15
View File
@@ -0,0 +1,15 @@
---
post:
description: Book
operationId: buy
summary: Buy a book
tags:
- Book
consumes:
- application/json
- application/xml
parameters:
- name: requestBody
in: body
description: Buy a Book
required: true
+5
View File
@@ -0,0 +1,5 @@
---
swagger: '2.0'
paths:
"/v1/book":
"$ref": "./book.yaml"