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) {
switch (contentType) { const getDefaultParams = contentType => {
case "application/json": switch (contentType) {
case "application/hal+json": case "application/json":
if (!(this.rawParams.charAt(0) in ['"', "{", "["])) { case "application/hal+json":
this.rawParams = "{}" return "{}"
} case "application/xml":
break return "<?xml version='1.0' encoding='utf-8'?>"
case "application/xml": case "text/html":
if (this.rawParams.charAt(0) !== "<" || this.rawParams === "<!doctype html>") { return "<!doctype html>"
this.rawParams = "<?xml version='1.0' encoding='utf-8'?>" }
} return ""
break }
case "text/html": if (!this.rawParams || this.rawParams === getDefaultParams(oldContentType)) {
if (this.rawParams.charAt(0) !== "<" || this.rawParams.startsWith("<?xml")) { this.rawParams = getDefaultParams(contentType)
this.rawParams = "<!doctype html>"
}
} }
this.setRouteQueryState() this.setRouteQueryState()
}, },