Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/containers/OperationContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/plugins/json-schema-5-samples/fn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
11 changes: 7 additions & 4 deletions src/core/plugins/oas3/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions test/e2e-cypress/e2e/bugs/9158.cy.js
Original file line number Diff line number Diff line change
@@ -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")
})
})
46 changes: 46 additions & 0 deletions test/e2e-cypress/static/documents/bugs/9158.yaml
Original file line number Diff line number Diff line change
@@ -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