fix(raw-params): syntax fix, set default only when params is empty or old default

This commit is contained in:
Leonardo Matos
2020-03-17 16:30:15 -03:00
parent b0c327854c
commit f2c3bd54d6

View File

@@ -1435,23 +1435,21 @@ export default {
canListParameters(canToggleRaw) { canListParameters(canToggleRaw) {
this.rawInput = !canToggleRaw this.rawInput = !canToggleRaw
}, },
contentType(contentType) { contentType(contentType, oldContentType) {
const getDefaultParams = contentType => {
switch (contentType) { switch (contentType) {
case "application/json": case "application/json":
case "application/hal+json": case "application/hal+json":
if (!(this.rawParams.charAt(0) in ['"', "{", "["])) { return "{}"
this.rawParams = "{}"
}
break
case "application/xml": case "application/xml":
if (this.rawParams.charAt(0) !== "<" || this.rawParams === "<!doctype html>") { return "<?xml version='1.0' encoding='utf-8'?>"
this.rawParams = "<?xml version='1.0' encoding='utf-8'?>"
}
break
case "text/html": case "text/html":
if (this.rawParams.charAt(0) !== "<" || this.rawParams.startsWith("<?xml")) { return "<!doctype html>"
this.rawParams = "<!doctype html>"
} }
return ""
}
if (!this.rawParams || this.rawParams === getDefaultParams(oldContentType)) {
this.rawParams = getDefaultParams(contentType)
} }
this.setRouteQueryState() this.setRouteQueryState()
}, },