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:
@@ -77,6 +77,21 @@ export default class Parameters extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
onChangeMediaType = ( { value, pathMethod } ) => {
|
||||
let { specSelectors, specActions, oas3Selectors, oas3Actions } = this.props
|
||||
let targetMediaType = value
|
||||
let currentMediaType = oas3Selectors.requestContentType(...pathMethod)
|
||||
let schemaPropertiesMatch = specSelectors.isMediaTypeSchemaPropertiesEqual(pathMethod, currentMediaType, targetMediaType)
|
||||
if (!schemaPropertiesMatch) {
|
||||
oas3Actions.clearRequestBodyValue({ pathMethod })
|
||||
specActions.clearResponse(...pathMethod)
|
||||
specActions.clearRequest(...pathMethod)
|
||||
specActions.clearValidateParams(pathMethod)
|
||||
}
|
||||
oas3Actions.setRequestContentType({ value, pathMethod })
|
||||
oas3Actions.initRequestBodyValidateError({ pathMethod })
|
||||
}
|
||||
|
||||
render(){
|
||||
|
||||
let {
|
||||
@@ -187,8 +202,7 @@ export default class Parameters extends Component {
|
||||
value={oas3Selectors.requestContentType(...pathMethod)}
|
||||
contentTypes={ requestBody.get("content", List()).keySeq() }
|
||||
onChange={(value) => {
|
||||
oas3Actions.setRequestContentType({ value, pathMethod })
|
||||
oas3Actions.initRequestBodyValidateError({ pathMethod })
|
||||
this.onChangeMediaType({ value, pathMethod })
|
||||
}}
|
||||
className="body-param-content-type" />
|
||||
</label>
|
||||
|
||||
Reference in New Issue
Block a user