From 4794550a8a96155eeea24327cc8404acead924b1 Mon Sep 17 00:00:00 2001 From: Aviral Badola Date: Fri, 27 Oct 2023 22:44:25 +0530 Subject: [PATCH 1/9] Fix reset button in Try It Out form --- src/core/containers/OperationContainer.jsx | 4 ++-- src/core/plugins/oas3/reducers.js | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/containers/OperationContainer.jsx b/src/core/containers/OperationContainer.jsx index 89ce7f51ae1..65a2a74bbf6 100644 --- a/src/core/containers/OperationContainer.jsx +++ b/src/core/containers/OperationContainer.jsx @@ -2,7 +2,7 @@ import React, { PureComponent } from "react" import PropTypes from "prop-types" import ImPropTypes from "react-immutable-proptypes" import { opId } from "swagger-client/es/helpers" -import { Iterable, fromJS, Map } from "immutable" +import { Iterable, fromJS, Map, OrderedMap } from "immutable" export default class OperationContainer extends PureComponent { constructor(props, context) { @@ -124,7 +124,7 @@ export default class OperationContainer extends PureComponent { onResetClick = (pathMethod) => { const defaultRequestBodyValue = this.props.oas3Selectors.selectDefaultRequestBodyValue(...pathMethod) - this.props.oas3Actions.setRequestBodyValue({ value: defaultRequestBodyValue, pathMethod }) + this.props.oas3Actions.setRequestBodyValue({ value: OrderedMap(JSON.parse(defaultRequestBodyValue)), pathMethod }) } onExecute = () => { diff --git a/src/core/plugins/oas3/reducers.js b/src/core/plugins/oas3/reducers.js index 9efdb267726..2e3060f1bee 100644 --- a/src/core/plugins/oas3/reducers.js +++ b/src/core/plugins/oas3/reducers.js @@ -29,15 +29,18 @@ export default { // context: user switch from application/json to application/x-www-form-urlencoded currentVal = Map() } - let newVal + let newVal = currentVal const [...valueKeys] = value.keys() valueKeys.forEach((valueKey) => { let valueKeyVal = value.getIn([valueKey]) - if (!currentVal.has(valueKey)) { - newVal = currentVal.setIn([valueKey, "value"], valueKeyVal) + if (!newVal.has(valueKey)) { + newVal = newVal.setIn([valueKey, "value"], valueKeyVal) } else if (!Map.isMap(valueKeyVal)) { // context: user input will be received as String - newVal = currentVal.setIn([valueKey, "value"], valueKeyVal) + newVal = newVal.setIn([valueKey, "value"], valueKeyVal) + } else { + // context: If multiple values are edited only last edited is string, previous are map. + newVal = newVal.set(valueKey, valueKeyVal) } }) return state.setIn(["requestData", path, method, "bodyValue"], newVal) From e9f156041ac40a607223519827256f28acad48c5 Mon Sep 17 00:00:00 2001 From: Aviral Badola Date: Mon, 4 Dec 2023 23:15:05 +0530 Subject: [PATCH 2/9] Add test to cover 9158 --- test/e2e-cypress/e2e/bugs/9158.cy.js | 29 ++++++++++++ .../static/documents/bugs/9158.yaml | 46 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 test/e2e-cypress/e2e/bugs/9158.cy.js create mode 100644 test/e2e-cypress/static/documents/bugs/9158.yaml diff --git a/test/e2e-cypress/e2e/bugs/9158.cy.js b/test/e2e-cypress/e2e/bugs/9158.cy.js new file mode 100644 index 00000000000..93eab66585e --- /dev/null +++ b/test/e2e-cypress/e2e/bugs/9158.cy.js @@ -0,0 +1,29 @@ +describe("#9158: Reset button creates invalid inputs in the Try It Out form", () => { + it("it reset the user edited value and executes with the default value in case of try out reset. (#6517)", () => { + cy + .visit("?url=/documents/bugs/9158.yaml") + .get("#operations-default-post_users") + .click() + // Expand Try It Out + .get(".try-out__btn") + .click() + // replace multiple default values with bad value + .get(`.parameters[data-property-name="name"] input[type=text]`) + .type("{selectall}not the default name value") + .get(`.parameters[data-property-name="badgeid"] input[type=text]`) + .type("{selectall}not the default badge value") + // Reset Try It Out + .get(".try-out__btn.reset") + .click() + // Submit using default value + .get(".btn.execute") + .click() + // No required validation error on body parameter + .get(`.parameters[data-property-name="name"] input`) + .should("have.value", "default name") + .and("not.have.class", "invalid") + .get(`.parameters[data-property-name="badgeid"] input`) + .should("have.value", "12345") + .and("not.have.class", "invalid") + }) + }) \ No newline at end of file diff --git a/test/e2e-cypress/static/documents/bugs/9158.yaml b/test/e2e-cypress/static/documents/bugs/9158.yaml new file mode 100644 index 00000000000..ec888fe3d48 --- /dev/null +++ b/test/e2e-cypress/static/documents/bugs/9158.yaml @@ -0,0 +1,46 @@ +openapi: 3.0.3 +info: + title: Test API + version: 1.0.0 +paths: + /users: + post: + summary: Create a user + description: Create a user, one of various ways + requestBody: + content: + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/UserSource' + responses: + '204': + description: Successfully opened document + '400': + description: Invalid request + content: + application/json: + schema: + properties: + output: + type: string + example: "Invalid request" +components: + schemas: + UserSource: + type: object + properties: + name: + description: Full name + type: string + example: "default name" + badgeid: + description: Badge number + type: integer + format: uint32 + example: 12345 + email: + description: E-mail + type: string + example: "jsmith@business.com" + minProperties: 1 + maxProperties: 3 \ No newline at end of file From cefaf8f6217c58db80b82b18c4c98ffe6c0b98fe Mon Sep 17 00:00:00 2001 From: Oliwia Rogala Date: Tue, 19 Mar 2024 16:08:45 +0100 Subject: [PATCH 3/9] fix(oas3): reset request body values in try it out --- src/core/containers/OperationContainer.jsx | 24 ++++++++++++-- src/core/plugins/oas3/reducers.js | 2 +- test/e2e-cypress/e2e/bugs/9158.cy.js | 29 ----------------- .../plugins/oas3/try-it-out-reset.cy.js | 32 +++++++++++++++++++ .../oas3-try-it-out-reset.yaml} | 2 +- 5 files changed, 56 insertions(+), 33 deletions(-) delete mode 100644 test/e2e-cypress/e2e/bugs/9158.cy.js create mode 100644 test/e2e-cypress/e2e/features/plugins/oas3/try-it-out-reset.cy.js rename test/e2e-cypress/static/documents/{bugs/9158.yaml => features/oas3-try-it-out-reset.yaml} (97%) diff --git a/src/core/containers/OperationContainer.jsx b/src/core/containers/OperationContainer.jsx index 65a2a74bbf6..23ab3110a89 100644 --- a/src/core/containers/OperationContainer.jsx +++ b/src/core/containers/OperationContainer.jsx @@ -2,7 +2,7 @@ import React, { PureComponent } from "react" import PropTypes from "prop-types" import ImPropTypes from "react-immutable-proptypes" import { opId } from "swagger-client/es/helpers" -import { Iterable, fromJS, Map, OrderedMap } from "immutable" +import { Iterable, fromJS, Map } from "immutable" export default class OperationContainer extends PureComponent { constructor(props, context) { @@ -124,7 +124,27 @@ export default class OperationContainer extends PureComponent { onResetClick = (pathMethod) => { const defaultRequestBodyValue = this.props.oas3Selectors.selectDefaultRequestBodyValue(...pathMethod) - this.props.oas3Actions.setRequestBodyValue({ value: OrderedMap(JSON.parse(defaultRequestBodyValue)), pathMethod }) + const contentType = this.props.oas3Selectors.requestContentType(...pathMethod) + const isOAS31 = this.props.specSelectors.isOAS31() + + if (!isOAS31 && (contentType === "application/x-www-form-urlencoded" || contentType === "multipart/form-data")) { + const jsonRequestBodyValue = JSON.parse(defaultRequestBodyValue) + Object.entries(jsonRequestBodyValue).forEach(([key, value]) => { + if (Array.isArray(value)) { + jsonRequestBodyValue[key] = jsonRequestBodyValue[key].map((val) => { + if (typeof val === "object") { + return JSON.stringify(val, null, 2) + } + return val + }) + } else if (typeof value === "object") { + jsonRequestBodyValue[key] = JSON.stringify(jsonRequestBodyValue[key], null, 2) + } + }) + this.props.oas3Actions.setRequestBodyValue({ value: fromJS(jsonRequestBodyValue), pathMethod }) + } else { + this.props.oas3Actions.setRequestBodyValue({ value: defaultRequestBodyValue, pathMethod }) + } } onExecute = () => { diff --git a/src/core/plugins/oas3/reducers.js b/src/core/plugins/oas3/reducers.js index 2e3060f1bee..84fab577cb4 100644 --- a/src/core/plugins/oas3/reducers.js +++ b/src/core/plugins/oas3/reducers.js @@ -34,7 +34,7 @@ export default { valueKeys.forEach((valueKey) => { let valueKeyVal = value.getIn([valueKey]) if (!newVal.has(valueKey)) { - newVal = newVal.setIn([valueKey, "value"], valueKeyVal) + newVal = newVal.setIn([valueKey, "value"], valueKeyVal) } else if (!Map.isMap(valueKeyVal)) { // context: user input will be received as String newVal = newVal.setIn([valueKey, "value"], valueKeyVal) diff --git a/test/e2e-cypress/e2e/bugs/9158.cy.js b/test/e2e-cypress/e2e/bugs/9158.cy.js deleted file mode 100644 index 93eab66585e..00000000000 --- a/test/e2e-cypress/e2e/bugs/9158.cy.js +++ /dev/null @@ -1,29 +0,0 @@ -describe("#9158: Reset button creates invalid inputs in the Try It Out form", () => { - it("it reset the user edited value and executes with the default value in case of try out reset. (#6517)", () => { - cy - .visit("?url=/documents/bugs/9158.yaml") - .get("#operations-default-post_users") - .click() - // Expand Try It Out - .get(".try-out__btn") - .click() - // replace multiple default values with bad value - .get(`.parameters[data-property-name="name"] input[type=text]`) - .type("{selectall}not the default name value") - .get(`.parameters[data-property-name="badgeid"] input[type=text]`) - .type("{selectall}not the default badge value") - // Reset Try It Out - .get(".try-out__btn.reset") - .click() - // Submit using default value - .get(".btn.execute") - .click() - // No required validation error on body parameter - .get(`.parameters[data-property-name="name"] input`) - .should("have.value", "default name") - .and("not.have.class", "invalid") - .get(`.parameters[data-property-name="badgeid"] input`) - .should("have.value", "12345") - .and("not.have.class", "invalid") - }) - }) \ No newline at end of file diff --git a/test/e2e-cypress/e2e/features/plugins/oas3/try-it-out-reset.cy.js b/test/e2e-cypress/e2e/features/plugins/oas3/try-it-out-reset.cy.js new file mode 100644 index 00000000000..82082c4715a --- /dev/null +++ b/test/e2e-cypress/e2e/features/plugins/oas3/try-it-out-reset.cy.js @@ -0,0 +1,32 @@ +/** + * @prettier + */ + +describe("Reset button in try it out", () => { + it("should reset the edited request body value and execute try it out with the default value", () => { + cy.visit("?url=/documents/features/oas3-try-it-out-reset.yaml") + .get("#operations-default-post_users") + .click() + // Expand Try It Out + .get(".try-out__btn") + .click() + // replace multiple default values with bad value + .get(`.parameters[data-property-name="name"] input[type=text]`) + .type("{selectall}not the default name value") + .get(`.parameters[data-property-name="badgeid"] input[type=text]`) + .type("{selectall}not the default badge value") + // Reset Try It Out + .get(".try-out__btn.reset") + .click() + // Submit using default value + .get(".btn.execute") + .click() + // No required validation error on body parameter + .get(`.parameters[data-property-name="name"] input`) + .should("have.value", "default name") + .and("not.have.class", "invalid") + .get(`.parameters[data-property-name="badgeid"] input`) + .should("have.value", "12345") + .and("not.have.class", "invalid") + }) +}) diff --git a/test/e2e-cypress/static/documents/bugs/9158.yaml b/test/e2e-cypress/static/documents/features/oas3-try-it-out-reset.yaml similarity index 97% rename from test/e2e-cypress/static/documents/bugs/9158.yaml rename to test/e2e-cypress/static/documents/features/oas3-try-it-out-reset.yaml index ec888fe3d48..5b3a55f11a9 100644 --- a/test/e2e-cypress/static/documents/bugs/9158.yaml +++ b/test/e2e-cypress/static/documents/features/oas3-try-it-out-reset.yaml @@ -43,4 +43,4 @@ components: type: string example: "jsmith@business.com" minProperties: 1 - maxProperties: 3 \ No newline at end of file + maxProperties: 3 From 32c5093181faff152d5c68ff27b82cc63f80dfaa Mon Sep 17 00:00:00 2001 From: Oliwia Rogala Date: Tue, 7 May 2024 15:52:11 +0200 Subject: [PATCH 4/9] fix reset in OpenAPI 3.1 --- src/core/containers/OperationContainer.jsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/containers/OperationContainer.jsx b/src/core/containers/OperationContainer.jsx index 23ab3110a89..9f69b13ab0c 100644 --- a/src/core/containers/OperationContainer.jsx +++ b/src/core/containers/OperationContainer.jsx @@ -125,9 +125,8 @@ export default class OperationContainer extends PureComponent { onResetClick = (pathMethod) => { const defaultRequestBodyValue = this.props.oas3Selectors.selectDefaultRequestBodyValue(...pathMethod) const contentType = this.props.oas3Selectors.requestContentType(...pathMethod) - const isOAS31 = this.props.specSelectors.isOAS31() - if (!isOAS31 && (contentType === "application/x-www-form-urlencoded" || contentType === "multipart/form-data")) { + if (contentType === "application/x-www-form-urlencoded" || contentType === "multipart/form-data") { const jsonRequestBodyValue = JSON.parse(defaultRequestBodyValue) Object.entries(jsonRequestBodyValue).forEach(([key, value]) => { if (Array.isArray(value)) { From 6b5f23af5885e360c45279691a88e682fbea6075 Mon Sep 17 00:00:00 2001 From: Oliwia Rogala Date: Thu, 9 May 2024 09:21:51 +0200 Subject: [PATCH 5/9] update test --- .../{plugins/oas3 => }/try-it-out-reset.cy.js | 19 +++++++------------ ...t-out-reset.yaml => try-it-out-reset.yaml} | 0 2 files changed, 7 insertions(+), 12 deletions(-) rename test/e2e-cypress/e2e/features/{plugins/oas3 => }/try-it-out-reset.cy.js (56%) rename test/e2e-cypress/static/documents/features/{oas3-try-it-out-reset.yaml => try-it-out-reset.yaml} (100%) diff --git a/test/e2e-cypress/e2e/features/plugins/oas3/try-it-out-reset.cy.js b/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js similarity index 56% rename from test/e2e-cypress/e2e/features/plugins/oas3/try-it-out-reset.cy.js rename to test/e2e-cypress/e2e/features/try-it-out-reset.cy.js index 82082c4715a..3d91c4b59b0 100644 --- a/test/e2e-cypress/e2e/features/plugins/oas3/try-it-out-reset.cy.js +++ b/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js @@ -4,29 +4,24 @@ describe("Reset button in try it out", () => { it("should reset the edited request body value and execute try it out with the default value", () => { - cy.visit("?url=/documents/features/oas3-try-it-out-reset.yaml") + cy.visit("?url=/documents/features/try-it-out-reset.yaml") .get("#operations-default-post_users") .click() - // Expand Try It Out .get(".try-out__btn") .click() - // replace multiple default values with bad value .get(`.parameters[data-property-name="name"] input[type=text]`) .type("{selectall}not the default name value") .get(`.parameters[data-property-name="badgeid"] input[type=text]`) .type("{selectall}not the default badge value") - // Reset Try It Out + .get(`.parameters[data-property-name="email"] input[type=text]`) + .type("{selectall}not the default email value") .get(".try-out__btn.reset") .click() - // Submit using default value - .get(".btn.execute") - .click() - // No required validation error on body parameter - .get(`.parameters[data-property-name="name"] input`) + .get(`.parameters[data-property-name="name"] input[type=text]`) .should("have.value", "default name") - .and("not.have.class", "invalid") - .get(`.parameters[data-property-name="badgeid"] input`) + .get(`.parameters[data-property-name="badgeid"] input[type=text]`) .should("have.value", "12345") - .and("not.have.class", "invalid") + .get(`.parameters[data-property-name="email"] input[type=text]`) + .should("have.value", "jsmith@business.com") }) }) diff --git a/test/e2e-cypress/static/documents/features/oas3-try-it-out-reset.yaml b/test/e2e-cypress/static/documents/features/try-it-out-reset.yaml similarity index 100% rename from test/e2e-cypress/static/documents/features/oas3-try-it-out-reset.yaml rename to test/e2e-cypress/static/documents/features/try-it-out-reset.yaml From 5bf439256fc595c90246f9bf6de79c51f2ee96bc Mon Sep 17 00:00:00 2001 From: Oliwia Rogala Date: Thu, 9 May 2024 09:33:04 +0200 Subject: [PATCH 6/9] update test --- test/e2e-cypress/e2e/features/try-it-out-reset.cy.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js b/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js index 3d91c4b59b0..e87363f28ce 100644 --- a/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js +++ b/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js @@ -23,5 +23,10 @@ describe("Reset button in try it out", () => { .should("have.value", "12345") .get(`.parameters[data-property-name="email"] input[type=text]`) .should("have.value", "jsmith@business.com") + .get(".btn.execute") + .click() + .get(".curl-command") + .contains("name=default%20name&badgeid=12345&email=jsmith%40business.com") + .should("exist") }) }) From 6643e4a4743b8cf0c7fdaad98174ad4a626b26ea Mon Sep 17 00:00:00 2001 From: Oliwia Rogala Date: Thu, 9 May 2024 09:49:17 +0200 Subject: [PATCH 7/9] wait after reset button click in test --- test/e2e-cypress/e2e/features/try-it-out-reset.cy.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js b/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js index e87363f28ce..b59e7db418d 100644 --- a/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js +++ b/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js @@ -17,6 +17,7 @@ describe("Reset button in try it out", () => { .type("{selectall}not the default email value") .get(".try-out__btn.reset") .click() + .wait(1000) .get(`.parameters[data-property-name="name"] input[type=text]`) .should("have.value", "default name") .get(`.parameters[data-property-name="badgeid"] input[type=text]`) From 3f6b60840d52c79d8770b1e0db6f9cb788cfbd42 Mon Sep 17 00:00:00 2001 From: Oliwia Rogala Date: Thu, 9 May 2024 12:39:08 +0200 Subject: [PATCH 8/9] try waiting for longer in test --- test/e2e-cypress/e2e/features/try-it-out-reset.cy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js b/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js index b59e7db418d..7f8d57e89e5 100644 --- a/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js +++ b/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js @@ -17,7 +17,7 @@ describe("Reset button in try it out", () => { .type("{selectall}not the default email value") .get(".try-out__btn.reset") .click() - .wait(1000) + .wait(3000) .get(`.parameters[data-property-name="name"] input[type=text]`) .should("have.value", "default name") .get(`.parameters[data-property-name="badgeid"] input[type=text]`) From e8b9b8f2fe3cc5f5c7cf13654e7dcecef2c27e63 Mon Sep 17 00:00:00 2001 From: Oliwia Rogala Date: Thu, 9 May 2024 13:04:41 +0200 Subject: [PATCH 9/9] test without checking input values --- .../e2e/features/try-it-out-reset.cy.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js b/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js index 7f8d57e89e5..a6f707aada7 100644 --- a/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js +++ b/test/e2e-cypress/e2e/features/try-it-out-reset.cy.js @@ -15,15 +15,15 @@ describe("Reset button in try it out", () => { .type("{selectall}not the default badge value") .get(`.parameters[data-property-name="email"] input[type=text]`) .type("{selectall}not the default email value") + .get(".btn.execute") + .click() + .get(".curl-command") + .contains( + "name=not%20the%20default%20name%20value&badgeid=not%20the%20default%20badge%20value&email=not%20the%20default%20email%20value" + ) + .should("exist") .get(".try-out__btn.reset") .click() - .wait(3000) - .get(`.parameters[data-property-name="name"] input[type=text]`) - .should("have.value", "default name") - .get(`.parameters[data-property-name="badgeid"] input[type=text]`) - .should("have.value", "12345") - .get(`.parameters[data-property-name="email"] input[type=text]`) - .should("have.value", "jsmith@business.com") .get(".btn.execute") .click() .get(".curl-command")