From 63ee0a874cd4cf4f1442cb703832f3e42ce7b807 Mon Sep 17 00:00:00 2001 From: Joshua Whatley Date: Fri, 8 Sep 2017 16:53:43 -0700 Subject: [PATCH 1/9] break path if it would otherwise overflow --- src/style/_layout.scss | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/style/_layout.scss b/src/style/_layout.scss index 427c7dc5..407e8f1c 100644 --- a/src/style/_layout.scss +++ b/src/style/_layout.scss @@ -251,9 +251,11 @@ { font-size: 16px; - display: flex; + flex: 0 3 auto; align-items: center; + word-break: break-word; + padding: 0 10px; @include text_code(); From 82b9341a06483e66ff6f2a3c226b542e68b4616c Mon Sep 17 00:00:00 2001 From: Joshua Whatley Date: Wed, 13 Sep 2017 21:23:49 -0700 Subject: [PATCH 2/9] Changing word-break to follow standard Changed "break-word" to "break-all" as this is standard across all browsers and results with consistent behavior. --- src/style/_layout.scss | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/style/_layout.scss b/src/style/_layout.scss index 407e8f1c..50f7a59d 100644 --- a/src/style/_layout.scss +++ b/src/style/_layout.scss @@ -251,10 +251,11 @@ { font-size: 16px; + display: flex; flex: 0 3 auto; align-items: center; - word-break: break-word; + word-break: break-all; padding: 0 10px; From a5c7083726e2f630617c59388b3443e71f1d7dfe Mon Sep 17 00:00:00 2001 From: HelderSepu Date: Sat, 23 Sep 2017 14:14:58 -0400 Subject: [PATCH 3/9] Add validation for min and max length --- src/core/utils.js | 24 +++++++++++++++++ test/core/utils.js | 65 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/src/core/utils.js b/src/core/utils.js index ac633c34..1e2a95b1 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -512,6 +512,18 @@ 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 export const validateParam = (param, isXml) => { let errors = [] @@ -519,6 +531,8 @@ export const validateParam = (param, isXml) => { let required = param.get("required") let type = param.get("type") 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) @@ -535,6 +549,16 @@ export const validateParam = (param, isXml) => { 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 + if (maxLength) { + 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) ) { errors.push("Required field is not provided") return errors diff --git a/test/core/utils.js b/test/core/utils.js index dfe5c1ee..2e21ae3c 100644 --- a/test/core/utils.js +++ b/test/core/utils.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import expect from "expect" 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, fromJSOrdered, getAcceptControllingResponse, createDeepLinkPath, escapeDeepLinkPath } from "core/utils" import win from "core/window" describe("utils", function() { @@ -198,6 +198,34 @@ 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", 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() { let param = null let result = null @@ -223,7 +251,7 @@ describe("utils", function() { result = validateParam( param, false ) expect( result ).toEqual( ["Required field is not provided"] ) - // valid string + // valid string param = fromJS({ required: true, type: "string", @@ -231,6 +259,39 @@ describe("utils", function() { }) result = validateParam( param, false ) 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 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() { From 7d40d7228117af9d2f0b81fac37fd86798ea0579 Mon Sep 17 00:00:00 2001 From: HelderSepu Date: Sun, 24 Sep 2017 11:43:47 -0400 Subject: [PATCH 4/9] Add validateMaximum & validateMinimum This address some of the validation requested on Issue #993 --- src/core/utils.js | 24 ++++++++++++++++++++++++ test/core/utils.js | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/core/utils.js b/src/core/utils.js index ac633c34..305a5f69 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -470,6 +470,18 @@ export const propChecker = (props, nextProps, objectList=[], ignoreList=[]) => { || 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 ) => { if (!/^-?\d+(\.?\d+)?$/.test(val)) { return "Value must be a number" @@ -517,6 +529,8 @@ export const validateParam = (param, isXml) => { let errors = [] let value = isXml && param.get("in") === "body" ? param.get("value_xml") : param.get("value") let required = param.get("required") + let maximum = param.get("maximum") + let minimum = param.get("minimum") let type = param.get("type") let format = param.get("format") @@ -539,6 +553,16 @@ export const validateParam = (param, isXml) => { errors.push("Required field is not provided") return errors } + + if (maximum) { + let err = validateMaximum(value, maximum) + if (err) errors.push(err) + } + + if (minimum) { + let err = validateMinimum(value, minimum) + if (err) errors.push(err) + } if ( type === "string" ) { let err diff --git a/test/core/utils.js b/test/core/utils.js index dfe5c1ee..4740e35d 100644 --- a/test/core/utils.js +++ b/test/core/utils.js @@ -2,6 +2,7 @@ import expect from "expect" import { fromJS, OrderedMap } from "immutable" import { mapToList, validateDateTime, validateGuid, validateNumber, validateInteger, validateParam, validateFile, fromJSOrdered, getAcceptControllingResponse, createDeepLinkPath, escapeDeepLinkPath } from "core/utils" +import { validateMaximum, validateMinimum } from "core/utils" import win from "core/window" describe("utils", function() { @@ -72,6 +73,34 @@ 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(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, 2)).toEqual(errorMessage) + expect(validateMinimum(10, 20)).toEqual(errorMessage) + }) + }) + describe("validateNumber", function() { let errorMessage = "Value must be a number" @@ -485,11 +514,13 @@ describe("utils", function() { result = validateParam( param, false ) expect( result ).toEqual( ["Required field is not provided"] ) - // valid number + // valid number with min and max param = fromJS({ required: true, type: "number", - value: 10 + value: 10, + minimum: 5, + maximum: 99 }) result = validateParam( param, false ) expect( result ).toEqual( [] ) From 515726b3865aa8574d3950b7e4b80a8cc937a69f Mon Sep 17 00:00:00 2001 From: HelderSepu Date: Sun, 24 Sep 2017 15:45:42 -0400 Subject: [PATCH 5/9] Add test for negative num Testing valid negative number with min and max --- test/core/utils.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/core/utils.js b/test/core/utils.js index 4740e35d..2056fb29 100644 --- a/test/core/utils.js +++ b/test/core/utils.js @@ -524,6 +524,17 @@ describe("utils", function() { }) result = validateParam( param, false ) 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( [] ) }) it("validates optional numbers", function() { From 31e7ce0c5e7811eaffee7620473efc8ae5b54d11 Mon Sep 17 00:00:00 2001 From: Owen Conti Date: Mon, 25 Sep 2017 21:26:44 -0600 Subject: [PATCH 6/9] Fixes #3706 Add missing "in" argument to `getParameter` --- src/core/components/operation.jsx | 2 +- src/core/components/parameter-row.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/components/operation.jsx b/src/core/components/operation.jsx index fbf8ca60..194565da 100644 --- a/src/core/components/operation.jsx +++ b/src/core/components/operation.jsx @@ -149,7 +149,7 @@ export default class Operation extends PureComponent { const isDeepLinkingEnabled = deepLinking && deepLinking !== "false" // Merge in Live Response - if(response && response.size > 0) { + if(responses && response && response.size > 0) { let notDocumented = !responses.get(String(response.get("status"))) response = response.set("notDocumented", notDocumented) } diff --git a/src/core/components/parameter-row.jsx b/src/core/components/parameter-row.jsx index 2c4e0c9a..3fbf5843 100644 --- a/src/core/components/parameter-row.jsx +++ b/src/core/components/parameter-row.jsx @@ -30,7 +30,7 @@ export default class ParameterRow extends Component { let { specSelectors, pathMethod, param } = props let example = param.get("example") 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 enumValue = parameter ? parameter.get("enum") : undefined let value From ca1a0fa544b16661ff01ac4478ff6a90aebd5db1 Mon Sep 17 00:00:00 2001 From: Elvin Lemmens Date: Wed, 27 Sep 2017 12:34:46 +0200 Subject: [PATCH 7/9] Apply conditions for generating download link correctly Invalid application of AND/OR statements prevented file downloads of other types than application/octet-stream from generating a download link --- src/core/components/response-body.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/components/response-body.jsx b/src/core/components/response-body.jsx index 0829512e..265ff679 100644 --- a/src/core/components/response-body.jsx +++ b/src/core/components/response-body.jsx @@ -49,10 +49,10 @@ export default class ResponseBody extends React.Component { // Download } else if ( /^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-Description"] && (/File Transfer/i).test(headers["Content-Description"]) || - headers["content-description"] && (/File Transfer/i).test(headers["content-description"])) { + (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"]))) { let contentLength = headers["content-length"] || headers["Content-Length"] if ( !(+contentLength) ) return null From a408fb1f237fdfd347ca58546e35b94d8c6ec866 Mon Sep 17 00:00:00 2001 From: HelderSepu Date: Thu, 28 Sep 2017 20:40:16 -0400 Subject: [PATCH 8/9] Correction from @shockey --- src/core/utils.js | 2 +- test/core/utils.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/utils.js b/src/core/utils.js index 1e2a95b1..5e8ac79e 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -549,7 +549,7 @@ export const validateParam = (param, isXml) => { 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 - if (maxLength) { + if (maxLength || maxLength === 0) { let err = validateMaxLength(value, maxLength) if (err) errors.push(err) } diff --git a/test/core/utils.js b/test/core/utils.js index 2e21ae3c..40d7fc41 100644 --- a/test/core/utils.js +++ b/test/core/utils.js @@ -207,6 +207,7 @@ describe("utils", function() { }) 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) }) @@ -272,7 +273,7 @@ describe("utils", function() { expect( result ).toEqual( [] ) }) - it("validates required strings with min and max length", function() { + it("validates required strings with min and max length", function() { // invalid string with max length param = fromJS({ required: true, @@ -283,6 +284,17 @@ describe("utils", function() { 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, From 012313e236e4f35254ed297cf50d8137119b8a28 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Thu, 28 Sep 2017 17:59:07 -0700 Subject: [PATCH 9/9] Handle cases where maximum and minimum are 0 --- src/core/utils.js | 6 +++--- test/core/utils.js | 34 ++++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/core/utils.js b/src/core/utils.js index edd7bc81..8cd8eff6 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -577,13 +577,13 @@ export const validateParam = (param, isXml) => { errors.push("Required field is not provided") return errors } - - if (maximum) { + + if (maximum || maximum === 0) { let err = validateMaximum(value, maximum) if (err) errors.push(err) } - if (minimum) { + if (minimum || minimum === 0) { let err = validateMinimum(value, minimum) if (err) errors.push(err) } diff --git a/test/core/utils.js b/test/core/utils.js index 65aeb9f6..e506ef29 100644 --- a/test/core/utils.js +++ b/test/core/utils.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import expect from "expect" import { fromJS, OrderedMap } from "immutable" -import { +import { mapToList, validateMinLength, validateMaxLength, @@ -11,7 +11,7 @@ import { validateInteger, validateParam, validateFile, - validateMaximum, + validateMaximum, validateMinimum, fromJSOrdered, getAcceptControllingResponse, @@ -97,11 +97,12 @@ describe("utils", function() { }) 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" @@ -111,6 +112,7 @@ describe("utils", function() { }) 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) }) @@ -316,7 +318,7 @@ describe("utils", function() { result = validateParam( param, false ) expect( result ).toEqual( [] ) }) - + it("validates required strings with min and max length", function() { // invalid string with max length param = fromJS({ @@ -606,7 +608,7 @@ describe("utils", function() { param = fromJS({ required: true, type: "number", - value: 10, + value: 10, minimum: 5, maximum: 99 }) @@ -617,12 +619,32 @@ describe("utils", function() { param = fromJS({ required: true, type: "number", - value: -10, + 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() {