fix(oas3): switching media types should update schema properties (#6518)
* When the media-type is changed, there is a new `onChangeMediaType` method to handle actions. * If target schema properties key/value pairs does NOT equals current schema properties, clear the requestBodyValue, try-it-out request/response and validation params. * If target schema properties key/value pairs DOES equals current schema properties, do not change or re-render schema properties * oas3Selector `validateShallowRequired` now also validates required keys against target media-type Fixes #6201, #6250, #6476
This commit is contained in:
@@ -504,4 +504,79 @@ describe("oas3 plugin - reducer", function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe("CLEAR_REQUEST_BODY_VALUE", function () {
|
||||
const clearRequestBodyValue = reducer["oas3_clear_request_body_value"]
|
||||
describe("when requestBodyValue is a String", () => {
|
||||
it("should clear requestBodyValue with empty String", () => {
|
||||
const state = fromJS({
|
||||
requestData: {
|
||||
"/pet": {
|
||||
post: {
|
||||
bodyValue: "some random string",
|
||||
requestContentType: "application/json"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const result = clearRequestBodyValue(state, {
|
||||
payload: {
|
||||
pathMethod: ["/pet", "post"],
|
||||
}
|
||||
})
|
||||
|
||||
const expectedResult = {
|
||||
requestData: {
|
||||
"/pet": {
|
||||
post: {
|
||||
bodyValue: "",
|
||||
requestContentType: "application/json",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expect(result.toJS()).toEqual(expectedResult)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when requestBodyValue is a Map", () => {
|
||||
it("should clear requestBodyValue with empty Map", () => {
|
||||
const state = fromJS({
|
||||
requestData: {
|
||||
"/pet": {
|
||||
post: {
|
||||
bodyValue: {
|
||||
id: {
|
||||
value: "10",
|
||||
},
|
||||
},
|
||||
requestContentType: "application/x-www-form-urlencoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const result = clearRequestBodyValue(state, {
|
||||
payload: {
|
||||
pathMethod: ["/pet", "post"],
|
||||
}
|
||||
})
|
||||
|
||||
const expectedResult = {
|
||||
requestData: {
|
||||
"/pet": {
|
||||
post: {
|
||||
bodyValue: {},
|
||||
requestContentType: "application/x-www-form-urlencoded",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expect(result.toJS()).toEqual(expectedResult)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user