diff --git a/src/core/containers/OperationContainer.jsx b/src/core/containers/OperationContainer.jsx index 89ce7f51ae1..2a5cb4f5487 100644 --- a/src/core/containers/OperationContainer.jsx +++ b/src/core/containers/OperationContainer.jsx @@ -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: fromJS(JSON.parse(defaultRequestBodyValue)), pathMethod }) } onExecute = () => { diff --git a/src/core/plugins/json-schema-5-samples/fn/index.js b/src/core/plugins/json-schema-5-samples/fn/index.js index 6434c50666b..14c1da6ca55 100644 --- a/src/core/plugins/json-schema-5-samples/fn/index.js +++ b/src/core/plugins/json-schema-5-samples/fn/index.js @@ -283,7 +283,7 @@ export const sampleFromSchemaGeneric = (schema, config={}, exampleOverride = und } const canAddProperty = (propName) => { - if(!schema || schema.maxProperties === null || schema.maxProperties === undefined) { + if(!respectXML || !schema || schema.maxProperties === null || schema.maxProperties === undefined) { return true } if(hasExceededMaxProperties()) { 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) 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