Merge branch 'master' into bug/swagger-editor-1502
This commit is contained in:
@@ -149,7 +149,7 @@ export default class Operation extends PureComponent {
|
|||||||
const isDeepLinkingEnabled = deepLinking && deepLinking !== "false"
|
const isDeepLinkingEnabled = deepLinking && deepLinking !== "false"
|
||||||
|
|
||||||
// Merge in Live Response
|
// Merge in Live Response
|
||||||
if(response && response.size > 0) {
|
if(responses && response && response.size > 0) {
|
||||||
let notDocumented = !responses.get(String(response.get("status")))
|
let notDocumented = !responses.get(String(response.get("status")))
|
||||||
response = response.set("notDocumented", notDocumented)
|
response = response.set("notDocumented", notDocumented)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export default class ParameterRow extends Component {
|
|||||||
let { specSelectors, pathMethod, param } = props
|
let { specSelectors, pathMethod, param } = props
|
||||||
let example = param.get("example")
|
let example = param.get("example")
|
||||||
let defaultValue = param.get("default")
|
let defaultValue = param.get("default")
|
||||||
let parameter = specSelectors.getParameter(pathMethod, param.get("name"))
|
let parameter = specSelectors.getParameter(pathMethod, param.get("name"), param.get("in"))
|
||||||
let paramValue = parameter ? parameter.get("value") : undefined
|
let paramValue = parameter ? parameter.get("value") : undefined
|
||||||
let enumValue = parameter ? parameter.get("enum") : undefined
|
let enumValue = parameter ? parameter.get("enum") : undefined
|
||||||
let value
|
let value
|
||||||
|
|||||||
@@ -49,10 +49,10 @@ export default class ResponseBody extends React.Component {
|
|||||||
// Download
|
// Download
|
||||||
} else if (
|
} else if (
|
||||||
/^application\/octet-stream/i.test(contentType) ||
|
/^application\/octet-stream/i.test(contentType) ||
|
||||||
headers["Content-Disposition"] && (/attachment/i).test(headers["Content-Disposition"]) ||
|
(headers["Content-Disposition"] && (/attachment/i).test(headers["Content-Disposition"])) ||
|
||||||
headers["content-disposition"] && (/attachment/i).test(headers["content-disposition"]) ||
|
(headers["content-disposition"] && (/attachment/i).test(headers["content-disposition"])) ||
|
||||||
headers["Content-Description"] && (/File Transfer/i).test(headers["Content-Description"]) ||
|
(headers["Content-Description"] && (/File Transfer/i).test(headers["Content-Description"])) ||
|
||||||
headers["content-description"] && (/File Transfer/i).test(headers["content-description"])) {
|
(headers["content-description"] && (/File Transfer/i).test(headers["content-description"]))) {
|
||||||
|
|
||||||
let contentLength = headers["content-length"] || headers["Content-Length"]
|
let contentLength = headers["content-length"] || headers["Content-Length"]
|
||||||
if ( !(+contentLength) ) return null
|
if ( !(+contentLength) ) return null
|
||||||
|
|||||||
@@ -470,6 +470,18 @@ export const propChecker = (props, nextProps, objectList=[], ignoreList=[]) => {
|
|||||||
|| objectList.some( objectPropName => !eq(props[objectPropName], nextProps[objectPropName])))
|
|| objectList.some( objectPropName => !eq(props[objectPropName], nextProps[objectPropName])))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const validateMaximum = ( val, max ) => {
|
||||||
|
if (val > max) {
|
||||||
|
return "Value must be less than Maximum"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const validateMinimum = ( val, min ) => {
|
||||||
|
if (val < min) {
|
||||||
|
return "Value must be greater than Minimum"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const validateNumber = ( val ) => {
|
export const validateNumber = ( val ) => {
|
||||||
if (!/^-?\d+(\.?\d+)?$/.test(val)) {
|
if (!/^-?\d+(\.?\d+)?$/.test(val)) {
|
||||||
return "Value must be a number"
|
return "Value must be a number"
|
||||||
@@ -512,13 +524,29 @@ export const validateGuid = (val) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const validateMaxLength = (val, max) => {
|
||||||
|
if (val.length > max) {
|
||||||
|
return "Value must be less than MaxLength"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const validateMinLength = (val, min) => {
|
||||||
|
if (val.length < min) {
|
||||||
|
return "Value must be greater than MinLength"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// validation of parameters before execute
|
// validation of parameters before execute
|
||||||
export const validateParam = (param, isXml) => {
|
export const validateParam = (param, isXml) => {
|
||||||
let errors = []
|
let errors = []
|
||||||
let value = isXml && param.get("in") === "body" ? param.get("value_xml") : param.get("value")
|
let value = isXml && param.get("in") === "body" ? param.get("value_xml") : param.get("value")
|
||||||
let required = param.get("required")
|
let required = param.get("required")
|
||||||
|
let maximum = param.get("maximum")
|
||||||
|
let minimum = param.get("minimum")
|
||||||
let type = param.get("type")
|
let type = param.get("type")
|
||||||
let format = param.get("format")
|
let format = param.get("format")
|
||||||
|
let maxLength = param.get("maxLength")
|
||||||
|
let minLength = param.get("minLength")
|
||||||
|
|
||||||
/*
|
/*
|
||||||
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)
|
||||||
@@ -535,11 +563,31 @@ export const validateParam = (param, isXml) => {
|
|||||||
let numberCheck = type === "number" && !validateNumber(value) // validateNumber returns undefined if the value is a number
|
let numberCheck = type === "number" && !validateNumber(value) // validateNumber returns undefined if the value is a number
|
||||||
let integerCheck = type === "integer" && !validateInteger(value) // validateInteger returns undefined if the value is an integer
|
let integerCheck = type === "integer" && !validateInteger(value) // validateInteger returns undefined if the value is an integer
|
||||||
|
|
||||||
|
if (maxLength || maxLength === 0) {
|
||||||
|
let err = validateMaxLength(value, maxLength)
|
||||||
|
if (err) errors.push(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minLength) {
|
||||||
|
let err = validateMinLength(value, minLength)
|
||||||
|
if (err) errors.push(err)
|
||||||
|
}
|
||||||
|
|
||||||
if ( required && !(stringCheck || arrayCheck || listCheck || fileCheck || booleanCheck || numberCheck || integerCheck) ) {
|
if ( required && !(stringCheck || arrayCheck || listCheck || fileCheck || booleanCheck || numberCheck || integerCheck) ) {
|
||||||
errors.push("Required field is not provided")
|
errors.push("Required field is not provided")
|
||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (maximum || maximum === 0) {
|
||||||
|
let err = validateMaximum(value, maximum)
|
||||||
|
if (err) errors.push(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minimum || minimum === 0) {
|
||||||
|
let err = validateMinimum(value, minimum)
|
||||||
|
if (err) errors.push(err)
|
||||||
|
}
|
||||||
|
|
||||||
if ( type === "string" ) {
|
if ( type === "string" ) {
|
||||||
let err
|
let err
|
||||||
if (format === "date-time") {
|
if (format === "date-time") {
|
||||||
|
|||||||
@@ -252,8 +252,11 @@
|
|||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex: 0 3 auto;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
|
word-break: break-all;
|
||||||
|
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
|
|
||||||
@include text_code();
|
@include text_code();
|
||||||
|
|||||||
@@ -1,7 +1,23 @@
|
|||||||
/* eslint-env mocha */
|
/* eslint-env mocha */
|
||||||
import expect from "expect"
|
import expect from "expect"
|
||||||
import { fromJS, OrderedMap } from "immutable"
|
import { fromJS, OrderedMap } from "immutable"
|
||||||
import { mapToList, validateDateTime, validateGuid, validateNumber, validateInteger, validateParam, validateFile, fromJSOrdered, getAcceptControllingResponse, createDeepLinkPath, escapeDeepLinkPath } from "core/utils"
|
import {
|
||||||
|
mapToList,
|
||||||
|
validateMinLength,
|
||||||
|
validateMaxLength,
|
||||||
|
validateDateTime,
|
||||||
|
validateGuid,
|
||||||
|
validateNumber,
|
||||||
|
validateInteger,
|
||||||
|
validateParam,
|
||||||
|
validateFile,
|
||||||
|
validateMaximum,
|
||||||
|
validateMinimum,
|
||||||
|
fromJSOrdered,
|
||||||
|
getAcceptControllingResponse,
|
||||||
|
createDeepLinkPath,
|
||||||
|
escapeDeepLinkPath
|
||||||
|
} from "core/utils"
|
||||||
import win from "core/window"
|
import win from "core/window"
|
||||||
|
|
||||||
describe("utils", function() {
|
describe("utils", function() {
|
||||||
@@ -72,6 +88,36 @@ describe("utils", function() {
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("validateMaximum", function() {
|
||||||
|
let errorMessage = "Value must be less than Maximum"
|
||||||
|
|
||||||
|
it("doesn't return for valid input", function() {
|
||||||
|
expect(validateMaximum(9, 10)).toBeFalsy()
|
||||||
|
expect(validateMaximum(19, 20)).toBeFalsy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns a message for invalid input", function() {
|
||||||
|
expect(validateMaximum(1, 0)).toEqual(errorMessage)
|
||||||
|
expect(validateMaximum(10, 9)).toEqual(errorMessage)
|
||||||
|
expect(validateMaximum(20, 19)).toEqual(errorMessage)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("validateMinimum", function() {
|
||||||
|
let errorMessage = "Value must be greater than Minimum"
|
||||||
|
|
||||||
|
it("doesn't return for valid input", function() {
|
||||||
|
expect(validateMinimum(2, 1)).toBeFalsy()
|
||||||
|
expect(validateMinimum(20, 10)).toBeFalsy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns a message for invalid input", function() {
|
||||||
|
expect(validateMinimum(-1, 0)).toEqual(errorMessage)
|
||||||
|
expect(validateMinimum(1, 2)).toEqual(errorMessage)
|
||||||
|
expect(validateMinimum(10, 20)).toEqual(errorMessage)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("validateNumber", function() {
|
describe("validateNumber", function() {
|
||||||
let errorMessage = "Value must be a number"
|
let errorMessage = "Value must be a number"
|
||||||
|
|
||||||
@@ -198,6 +244,35 @@ describe("utils", function() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("validateMaxLength", function() {
|
||||||
|
let errorMessage = "Value must be less than MaxLength"
|
||||||
|
|
||||||
|
it("doesn't return for valid guid", function() {
|
||||||
|
expect(validateMaxLength("a", 1)).toBeFalsy()
|
||||||
|
expect(validateMaxLength("abc", 5)).toBeFalsy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns a message for invalid input'", function() {
|
||||||
|
expect(validateMaxLength("abc", 0)).toEqual(errorMessage)
|
||||||
|
expect(validateMaxLength("abc", 1)).toEqual(errorMessage)
|
||||||
|
expect(validateMaxLength("abc", 2)).toEqual(errorMessage)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("validateMinLength", function() {
|
||||||
|
let errorMessage = "Value must be greater than MinLength"
|
||||||
|
|
||||||
|
it("doesn't return for valid guid", function() {
|
||||||
|
expect(validateMinLength("a", 1)).toBeFalsy()
|
||||||
|
expect(validateMinLength("abc", 2)).toBeFalsy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns a message for invalid input'", function() {
|
||||||
|
expect(validateMinLength("abc", 5)).toEqual(errorMessage)
|
||||||
|
expect(validateMinLength("abc", 8)).toEqual(errorMessage)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("validateParam", function() {
|
describe("validateParam", function() {
|
||||||
let param = null
|
let param = null
|
||||||
let result = null
|
let result = null
|
||||||
@@ -223,7 +298,7 @@ describe("utils", function() {
|
|||||||
result = validateParam( param, false )
|
result = validateParam( param, false )
|
||||||
expect( result ).toEqual( ["Required field is not provided"] )
|
expect( result ).toEqual( ["Required field is not provided"] )
|
||||||
|
|
||||||
// valid string
|
// valid string
|
||||||
param = fromJS({
|
param = fromJS({
|
||||||
required: true,
|
required: true,
|
||||||
type: "string",
|
type: "string",
|
||||||
@@ -231,6 +306,50 @@ describe("utils", function() {
|
|||||||
})
|
})
|
||||||
result = validateParam( param, false )
|
result = validateParam( param, false )
|
||||||
expect( result ).toEqual( [] )
|
expect( result ).toEqual( [] )
|
||||||
|
|
||||||
|
// valid string with min and max length
|
||||||
|
param = fromJS({
|
||||||
|
required: true,
|
||||||
|
type: "string",
|
||||||
|
value: "test string",
|
||||||
|
maxLength: 50,
|
||||||
|
minLength: 1
|
||||||
|
})
|
||||||
|
result = validateParam( param, false )
|
||||||
|
expect( result ).toEqual( [] )
|
||||||
|
})
|
||||||
|
|
||||||
|
it("validates required strings with min and max length", function() {
|
||||||
|
// invalid string with max length
|
||||||
|
param = fromJS({
|
||||||
|
required: true,
|
||||||
|
type: "string",
|
||||||
|
value: "test string",
|
||||||
|
maxLength: 5
|
||||||
|
})
|
||||||
|
result = validateParam( param, false )
|
||||||
|
expect( result ).toEqual( ["Value must be less than MaxLength"] )
|
||||||
|
|
||||||
|
// invalid string with max length 0
|
||||||
|
param = fromJS({
|
||||||
|
required: true,
|
||||||
|
type: "string",
|
||||||
|
value: "test string",
|
||||||
|
maxLength: 0
|
||||||
|
})
|
||||||
|
result = validateParam( param, false )
|
||||||
|
expect( result ).toEqual( ["Value must be less than MaxLength"] )
|
||||||
|
|
||||||
|
|
||||||
|
// invalid string with min length
|
||||||
|
param = fromJS({
|
||||||
|
required: true,
|
||||||
|
type: "string",
|
||||||
|
value: "test string",
|
||||||
|
minLength: 50
|
||||||
|
})
|
||||||
|
result = validateParam( param, false )
|
||||||
|
expect( result ).toEqual( ["Value must be greater than MinLength"] )
|
||||||
})
|
})
|
||||||
|
|
||||||
it("validates optional strings", function() {
|
it("validates optional strings", function() {
|
||||||
@@ -485,14 +604,47 @@ describe("utils", function() {
|
|||||||
result = validateParam( param, false )
|
result = validateParam( param, false )
|
||||||
expect( result ).toEqual( ["Required field is not provided"] )
|
expect( result ).toEqual( ["Required field is not provided"] )
|
||||||
|
|
||||||
// valid number
|
// valid number with min and max
|
||||||
param = fromJS({
|
param = fromJS({
|
||||||
required: true,
|
required: true,
|
||||||
type: "number",
|
type: "number",
|
||||||
value: 10
|
value: 10,
|
||||||
|
minimum: 5,
|
||||||
|
maximum: 99
|
||||||
})
|
})
|
||||||
result = validateParam( param, false )
|
result = validateParam( param, false )
|
||||||
expect( result ).toEqual( [] )
|
expect( result ).toEqual( [] )
|
||||||
|
|
||||||
|
// valid negative number with min and max
|
||||||
|
param = fromJS({
|
||||||
|
required: true,
|
||||||
|
type: "number",
|
||||||
|
value: -10,
|
||||||
|
minimum: -50,
|
||||||
|
maximum: -5
|
||||||
|
})
|
||||||
|
result = validateParam( param, false )
|
||||||
|
expect( result ).toEqual( [] )
|
||||||
|
|
||||||
|
// invalid number with maximum:0
|
||||||
|
param = fromJS({
|
||||||
|
required: true,
|
||||||
|
type: "number",
|
||||||
|
value: 1,
|
||||||
|
maximum: 0
|
||||||
|
})
|
||||||
|
result = validateParam( param, false )
|
||||||
|
expect( result ).toEqual( ["Value must be less than Maximum"] )
|
||||||
|
|
||||||
|
// invalid number with minimum:0
|
||||||
|
param = fromJS({
|
||||||
|
required: true,
|
||||||
|
type: "number",
|
||||||
|
value: -10,
|
||||||
|
minimum: 0
|
||||||
|
})
|
||||||
|
result = validateParam( param, false )
|
||||||
|
expect( result ).toEqual( ["Value must be greater than Minimum"] )
|
||||||
})
|
})
|
||||||
|
|
||||||
it("validates optional numbers", function() {
|
it("validates optional numbers", function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user