Merge branch 'master' into ft/3052-extensions

This commit is contained in:
Greg Thompson
2017-11-06 09:18:51 -06:00
15 changed files with 102 additions and 49 deletions

View File

@@ -1,12 +1,16 @@
language: node_js language: node_js
node_js: node_js:
- '6.9' - '6.9'
cache:
directories:
- node_modules
services: services:
- docker - docker
branches: branches:
only: only:
- master - master
- /^v\d+\.\d+(\.\d+)?(-\S*)?$/ - /^v\d+\.\d+(\.\d+)?(-\S*)?$/
install: "npm i && npm update"
before_deploy: before_deploy:
- npm run build - npm run build
env: env:

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.4.2 | 2017-10-30 | 2.0, 3.0 | [tag v3.4.2](https://github.com/swagger-api/swagger-ui/tree/v3.4.2) 3.4.3 | 2017-11-03 | 2.0, 3.0 | [tag v3.4.3](https://github.com/swagger-api/swagger-ui/tree/v3.4.3)
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

2
dist/swagger-ui.css vendored

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.4.2", "version": "3.4.3",
"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": [
@@ -79,7 +79,7 @@
"scroll-to-element": "^2.0.0", "scroll-to-element": "^2.0.0",
"serialize-error": "2.0.0", "serialize-error": "2.0.0",
"shallowequal": "0.2.2", "shallowequal": "0.2.2",
"swagger-client": "^3.3.1", "swagger-client": "^3.3.2",
"url-parse": "^1.1.8", "url-parse": "^1.1.8",
"whatwg-fetch": "0.11.1", "whatwg-fetch": "0.11.1",
"worker-loader": "^0.7.1", "worker-loader": "^0.7.1",

View File

@@ -32,7 +32,8 @@ export default class ResponseBody extends React.Component {
// XML // XML
} else if (/xml/i.test(contentType)) { } else if (/xml/i.test(contentType)) {
body = formatXml(content, { body = formatXml(content, {
textNodesOnSameLine: true textNodesOnSameLine: true,
indentor: " "
}) })
bodyEl = <HighlightCode value={ body } /> bodyEl = <HighlightCode value={ body } />

View File

@@ -48,6 +48,10 @@ export const definitions = onlyOAS3(createSelector(
spec => spec.getIn(["components", "schemas"]) || Map() spec => spec.getIn(["components", "schemas"]) || Map()
)) ))
export const hasHost = onlyOAS3((state) => {
return spec(state).hasIn(["servers", 0])
})
export const securityDefinitions = onlyOAS3(createSelector( export const securityDefinitions = onlyOAS3(createSelector(
spec, spec,
spec => spec.getIn(["components", "securitySchemes"]) || null spec => spec.getIn(["components", "securitySchemes"]) || null

View File

@@ -459,6 +459,13 @@ export const validateMinLength = (val, min) => {
} }
} }
export const validatePattern = (val, rxPattern) => {
var patt = new RegExp(rxPattern)
if (!patt.test(val)) {
return "Value must follow pattern " + rxPattern
}
}
// validation of parameters before execute // validation of parameters before execute
export const validateParam = (param, isXml, isOAS3 = false) => { export const validateParam = (param, isXml, isOAS3 = false) => {
let errors = [] let errors = []
@@ -472,6 +479,8 @@ export const validateParam = (param, isXml, isOAS3 = false) => {
let format = paramDetails.get("format") let format = paramDetails.get("format")
let maxLength = paramDetails.get("maxLength") let maxLength = paramDetails.get("maxLength")
let minLength = paramDetails.get("minLength") let minLength = paramDetails.get("minLength")
let pattern = paramDetails.get("pattern")
/* /*
If the parameter is required OR the parameter has a value (meaning optional, but filled in) If the parameter is required OR the parameter has a value (meaning optional, but filled in)
@@ -479,15 +488,25 @@ export const validateParam = (param, isXml, isOAS3 = false) => {
Only bother validating the parameter if the type was specified. Only bother validating the parameter if the type was specified.
*/ */
if ( type && (required || value) ) { if ( type && (required || value) ) {
// These checks should evaluate to true if the parameter's value is valid // These checks should evaluate to true if there is a parameter
let stringCheck = type === "string" && value && !validateString(value) let stringCheck = type === "string" && value
let arrayCheck = type === "array" && Array.isArray(value) && value.length let arrayCheck = type === "array" && Array.isArray(value) && value.length
let listCheck = type === "array" && Im.List.isList(value) && value.count() let listCheck = type === "array" && Im.List.isList(value) && value.count()
let fileCheck = type === "file" && value instanceof win.File let fileCheck = type === "file" && value instanceof win.File
let booleanCheck = type === "boolean" && !validateBoolean(value) let booleanCheck = type === "boolean" && (value || value === false)
let numberCheck = type === "number" && !validateNumber(value) // validateNumber returns undefined if the value is a number let numberCheck = type === "number" && value
let integerCheck = type === "integer" && !validateInteger(value) // validateInteger returns undefined if the value is an integer let integerCheck = type === "integer" && value
if ( required && !(stringCheck || arrayCheck || listCheck || fileCheck || booleanCheck || numberCheck || integerCheck) ) {
errors.push("Required field is not provided")
return errors
}
if (pattern) {
let err = validatePattern(value, pattern)
if (err) errors.push(err)
}
if (maxLength || maxLength === 0) { if (maxLength || maxLength === 0) {
let err = validateMaxLength(value, maxLength) let err = validateMaxLength(value, maxLength)
if (err) errors.push(err) if (err) errors.push(err)
@@ -498,11 +517,6 @@ export const validateParam = (param, isXml, isOAS3 = false) => {
if (err) errors.push(err) if (err) errors.push(err)
} }
if ( required && !(stringCheck || arrayCheck || listCheck || fileCheck || booleanCheck || numberCheck || integerCheck) ) {
errors.push("Required field is not provided")
return errors
}
if (maximum || maximum === 0) { if (maximum || maximum === 0) {
let err = validateMaximum(value, maximum) let err = validateMaximum(value, maximum)
if (err) errors.push(err) if (err) errors.push(err)

View File

@@ -65,6 +65,7 @@
&.execute &.execute
{ {
animation: swagger-ui-pulse 2s infinite; animation: swagger-ui-pulse 2s infinite;
will-change: transform;
background-color: $btn-execute-background-color; background-color: $btn-execute-background-color;
color: $btn-execute-font-color; color: $btn-execute-font-color;
border-color: $btn-execute-border-color; border-color: $btn-execute-border-color;

View File

@@ -3,6 +3,7 @@ import expect from "expect"
import { fromJS, OrderedMap } from "immutable" import { fromJS, OrderedMap } from "immutable"
import { import {
mapToList, mapToList,
validatePattern,
validateMinLength, validateMinLength,
validateMaxLength, validateMaxLength,
validateDateTime, validateDateTime,
@@ -216,9 +217,9 @@ describe("utils", function() {
expect(validateFile(1)).toEqual(errorMessage) expect(validateFile(1)).toEqual(errorMessage)
expect(validateFile("string")).toEqual(errorMessage) expect(validateFile("string")).toEqual(errorMessage)
}) })
}) })
describe("validateDateTime", function() { describe("validateDateTime", function() {
let errorMessage = "Value must be a DateTime" let errorMessage = "Value must be a DateTime"
it("doesn't return for valid dates", function() { it("doesn't return for valid dates", function() {
@@ -229,7 +230,7 @@ describe("utils", function() {
expect(validateDateTime(null)).toEqual(errorMessage) expect(validateDateTime(null)).toEqual(errorMessage)
expect(validateDateTime("string")).toEqual(errorMessage) expect(validateDateTime("string")).toEqual(errorMessage)
}) })
}) })
describe("validateGuid", function() { describe("validateGuid", function() {
let errorMessage = "Value must be a Guid" let errorMessage = "Value must be a Guid"
@@ -243,9 +244,9 @@ describe("utils", function() {
expect(validateGuid(1)).toEqual(errorMessage) expect(validateGuid(1)).toEqual(errorMessage)
expect(validateGuid("string")).toEqual(errorMessage) expect(validateGuid("string")).toEqual(errorMessage)
}) })
}) })
describe("validateMaxLength", function() { describe("validateMaxLength", function() {
let errorMessage = "Value must be less than MaxLength" let errorMessage = "Value must be less than MaxLength"
it("doesn't return for valid guid", function() { it("doesn't return for valid guid", function() {
@@ -258,9 +259,9 @@ describe("utils", function() {
expect(validateMaxLength("abc", 1)).toEqual(errorMessage) expect(validateMaxLength("abc", 1)).toEqual(errorMessage)
expect(validateMaxLength("abc", 2)).toEqual(errorMessage) expect(validateMaxLength("abc", 2)).toEqual(errorMessage)
}) })
}) })
describe("validateMinLength", function() { describe("validateMinLength", function() {
let errorMessage = "Value must be greater than MinLength" let errorMessage = "Value must be greater than MinLength"
it("doesn't return for valid guid", function() { it("doesn't return for valid guid", function() {
@@ -272,7 +273,29 @@ describe("utils", function() {
expect(validateMinLength("abc", 5)).toEqual(errorMessage) expect(validateMinLength("abc", 5)).toEqual(errorMessage)
expect(validateMinLength("abc", 8)).toEqual(errorMessage) expect(validateMinLength("abc", 8)).toEqual(errorMessage)
}) })
}) })
describe("validatePattern", function() {
let rxPattern = "^(red|blue)"
let errorMessage = "Value must follow pattern " + rxPattern
it("doesn't return for a match", function() {
expect(validatePattern("red", rxPattern)).toBeFalsy()
expect(validatePattern("blue", rxPattern)).toBeFalsy()
})
it("returns a message for invalid pattern", function() {
expect(validatePattern("pink", rxPattern)).toEqual(errorMessage)
expect(validatePattern("123", rxPattern)).toEqual(errorMessage)
})
it("fails gracefully when an invalid regex value is passed", function() {
expect(() => validatePattern("aValue", "---")).toNotThrow()
expect(() => validatePattern("aValue", 1234)).toNotThrow()
expect(() => validatePattern("aValue", null)).toNotThrow()
expect(() => validatePattern("aValue", [])).toNotThrow()
})
})
describe("validateParam", function() { describe("validateParam", function() {
let param = null let param = null
@@ -525,7 +548,7 @@ describe("utils", function() {
type: "boolean", type: "boolean",
value: "test string" value: "test string"
} }
assertValidateParam(param, ["Required field is not provided"]) assertValidateParam(param, ["Value must be a boolean"])
// valid boolean value // valid boolean value
param = { param = {
@@ -585,7 +608,7 @@ describe("utils", function() {
type: "number", type: "number",
value: "test" value: "test"
} }
assertValidateParam(param, ["Required field is not provided"]) assertValidateParam(param, ["Value must be a number"])
// invalid number, undefined value // invalid number, undefined value
param = { param = {
@@ -667,7 +690,7 @@ describe("utils", function() {
type: "integer", type: "integer",
value: "test" value: "test"
} }
assertValidateParam(param, ["Required field is not provided"]) assertValidateParam(param, ["Value must be an integer"])
// invalid integer, undefined value // invalid integer, undefined value
param = { param = {