diff --git a/src/core/components/operation.jsx b/src/core/components/operation.jsx index d4a365b7f04..49868813b26 100644 --- a/src/core/components/operation.jsx +++ b/src/core/components/operation.jsx @@ -112,6 +112,8 @@ export default class Operation extends PureComponent { let onChangeKey = [ path, method ] // Used to add values to _this_ operation ( indexed by path and method ) + const validationErrors = specSelectors.validationErrors([path, method]) + return (
@@ -189,6 +191,14 @@ export default class Operation extends PureComponent {
: null } + { !tryItOutEnabled || !allowTryItOut || validationErrors.length <= 0 ? null :
+ Please correct the following validation errors and try again. + +
+ } +
{ !tryItOutEnabled || !allowTryItOut ? null : diff --git a/src/core/plugins/spec/selectors.js b/src/core/plugins/spec/selectors.js index 89ea09ed041..97a4788bc74 100644 --- a/src/core/plugins/spec/selectors.js +++ b/src/core/plugins/spec/selectors.js @@ -477,19 +477,23 @@ export const canExecuteScheme = ( state, path, method ) => { return ["http", "https"].indexOf(operationScheme(state, path, method)) > -1 } -export const validateBeforeExecute = ( state, pathMethod ) => { +export const validationErrors = (state, pathMethod) => { pathMethod = pathMethod || [] let paramValues = state.getIn(["meta", "paths", ...pathMethod, "parameters"], fromJS([])) - let isValid = true + const result = [] paramValues.forEach( (p) => { let errors = p.get("errors") if ( errors && errors.count() ) { - isValid = false + errors.forEach( e => result.push(e)) } }) - return isValid + return result +} + +export const validateBeforeExecute = (state, pathMethod) => { + return validationErrors(state, pathMethod).length === 0 } export const getOAS3RequiredRequestBodyContentType = (state, pathMethod) => { diff --git a/test/e2e-cypress/tests/features/multiple-examples-core.js b/test/e2e-cypress/tests/features/multiple-examples-core.js index 8dad7b6f769..15b4ebeb607 100644 --- a/test/e2e-cypress/tests/features/multiple-examples-core.js +++ b/test/e2e-cypress/tests/features/multiple-examples-core.js @@ -606,6 +606,24 @@ describe("OpenAPI 3.0 Multiple Examples - core features", () => { summary: "A wonderful kitten's info", }, }) + it("should display an error message when input validation fails", () => { + cy.visit("/?url=/documents/features/multiple-examples-core.openapi.yaml") + // Expand the operation + .get("#operations-default-post_Object") + .click() + // Switch to Try-It-Out + .get(".try-out__btn") + .click() + // Set an invalid value + .get(".parameters-container > div > table > tbody > tr > td.parameters-col_description > div:nth-child(2) > textarea") + .type("{{{{ [[[[ <<<< invalid JSON here.") + // Execute the operation + .get(".execute") + .click() + // Verify that an error is shown + .get(".validation-errors") + .contains("Parameter string value must be valid JSON") + }) }) describe("in a Response", () => { ResponsePrimitiveTestCases({