未验证 提交 117dcc9b 编写于 作者: W Wesley Schwengle 提交者: GitHub

Disable the validation badge for those who do not want it (#5994)

* disabled on string values: "127.0.0.1", "localhost", "none"
上级 21f51494
......@@ -70,7 +70,7 @@ Parameter name | Docker variable | Description
<a name="responseInterceptor"></a>`responseInterceptor` | _Unavailable_ | `Function=(a => a)`. MUST be a function. Function to intercept remote definition, "Try it out", and OAuth 2.0 responses. Accepts one argument responseInterceptor(response) and must return the modified response, or a Promise that resolves to the modified response.
<a name="showMutatedRequest"></a>`showMutatedRequest` | `SHOW_MUTATED_REQUEST` | `Boolean=true`. If set to `true`, uses the mutated request returned from a requestInterceptor to produce the curl command in the UI, otherwise the request before the requestInterceptor was applied is used.
<a name="supportedSubmitMethods"></a>`supportedSubmitMethods` | `SUPPORTED_SUBMIT_METHODS` | `Array=["get", "put", "post", "delete", "options", "head", "patch", "trace"]`. List of HTTP methods that have the "Try it out" feature enabled. An empty array disables "Try it out" for all operations. This does not filter the operations from the display.
<a name="validatorUrl"></a>`validatorUrl` | `VALIDATOR_URL` | `String="https://validator.swagger.io/validator" OR null`. 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.
<a name="validatorUrl"></a>`validatorUrl` | `VALIDATOR_URL` | `String="https://validator.swagger.io/validator" OR null`. 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 either `none`, `127.0.0.1` or `localhost` will disable validation.
<a name="withCredentials"></a>`withCredentials` | `WITH_CREDENTIALS` | `Boolean=false` If set to `true`, enables passing credentials, [as defined in the Fetch standard](https://fetch.spec.whatwg.org/#credentials), in CORS requests that are sent by the browser. Note that Swagger UI cannot currently set cookies cross-domain (see [swagger-js#1163](https://github.com/swagger-api/swagger-js/issues/1163)) - as a result, you will have to rely on browser-supplied cookies (which this setting enables sending) that Swagger UI cannot control.
##### Macros
......
......@@ -2,7 +2,7 @@ import React from "react"
import URL from "url-parse"
import PropTypes from "prop-types"
import { sanitizeUrl } from "core/utils"
import { sanitizeUrl, requiresValidationURL } from "core/utils"
import win from "core/window"
export default class OnlineValidatorBadge extends React.Component {
......@@ -48,8 +48,8 @@ export default class OnlineValidatorBadge extends React.Component {
if ( typeof spec === "object" && Object.keys(spec).length) return null
if (!this.state.url || !this.state.validatorUrl || this.state.url.indexOf("localhost") >= 0
|| this.state.url.indexOf("127.0.0.1") >= 0) {
if (!this.state.url || !requiresValidationURL(this.state.validatorUrl)
|| !requiresValidationURL(this.state.url)) {
return null
}
......
......@@ -800,6 +800,15 @@ export function sanitizeUrl(url) {
return braintreeSanitizeUrl(url)
}
export function requiresValidationURL(uri) {
if (!uri || uri.indexOf("localhost") >= 0 || uri.indexOf("127.0.0.1") >= 0 || uri === "none") {
return false
}
return true
}
export function getAcceptControllingResponse(responses) {
if(!Im.OrderedMap.isOrderedMap(responses)) {
// wrong type!
......
......@@ -23,6 +23,7 @@ import {
getExtensions,
getCommonExtensions,
sanitizeUrl,
requiresValidationURL,
extractFileNameFromContentDispositionHeader,
deeplyStripKey,
getSampleSchema,
......@@ -1339,7 +1340,52 @@ describe("utils", function() {
expect(sanitizeUrl({})).toEqual("")
})
})
describe("requiresValidationURL", function() {
it("Should tell us if we require a ValidationURL", function() {
const res = requiresValidationURL("https://example.com")
expect(res).toBe(true)
})
it(".. and localhost is not", function() {
const res = requiresValidationURL("http://localhost")
expect(res).toBe(false)
})
it(".. and neither does 127.0.0.1", function() {
const res = requiresValidationURL("http://127.0.0.1")
expect(res).toBe(false)
})
it(".. even without the proto", function() {
const res = requiresValidationURL("127.0.0.1")
expect(res).toBe(false)
})
it(".. and also not with 'none'", function() {
const res = requiresValidationURL("none")
expect(res).toBe(false)
})
it(".. and also not with 'none'", function() {
const res = requiresValidationURL("none")
expect(res).toBe(false)
})
it(".. and also not with ''", function() {
const res = requiresValidationURL("")
expect(res).toBe(false)
})
})
describe("getSampleSchema", function() {
const oriDate = Date
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册