Parse JSON requestBodies so Client can consume them correctly
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import YAML from "js-yaml"
|
import YAML from "js-yaml"
|
||||||
import parseUrl from "url-parse"
|
import parseUrl from "url-parse"
|
||||||
import serializeError from "serialize-error"
|
import serializeError from "serialize-error"
|
||||||
|
import { isJSONObject } from "core/utils"
|
||||||
|
|
||||||
// Actions conform to FSA (flux-standard-actions)
|
// Actions conform to FSA (flux-standard-actions)
|
||||||
// {type: string,payload: Any|Error, meta: obj, error: bool}
|
// {type: string,payload: Any|Error, meta: obj, error: bool}
|
||||||
@@ -216,8 +217,14 @@ export const executeRequest = (req) =>
|
|||||||
// OAS3 request feature support
|
// OAS3 request feature support
|
||||||
req.server = oas3Selectors.selectedServer()
|
req.server = oas3Selectors.selectedServer()
|
||||||
req.serverVariables = oas3Selectors.serverVariables(req.server).toJS()
|
req.serverVariables = oas3Selectors.serverVariables(req.server).toJS()
|
||||||
req.requestBody = oas3Selectors.requestBodyValue(pathName, method)
|
|
||||||
req.requestContentType = oas3Selectors.requestContentType(pathName, method)
|
req.requestContentType = oas3Selectors.requestContentType(pathName, method)
|
||||||
|
const requestBody = oas3Selectors.requestBodyValue(pathName, method)
|
||||||
|
|
||||||
|
if(isJSONObject(requestBody)) {
|
||||||
|
req.requestBody = JSON.parse(requestBody)
|
||||||
|
} else {
|
||||||
|
req.requestBody = requestBody
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let parsedRequest = Object.assign({}, req)
|
let parsedRequest = Object.assign({}, req)
|
||||||
|
|||||||
@@ -13,6 +13,25 @@ const DEFAULT_REPONSE_KEY = "default"
|
|||||||
|
|
||||||
export const isImmutable = (maybe) => Im.Iterable.isIterable(maybe)
|
export const isImmutable = (maybe) => Im.Iterable.isIterable(maybe)
|
||||||
|
|
||||||
|
export function isJSONObject (str) {
|
||||||
|
try {
|
||||||
|
var o = JSON.parse(str)
|
||||||
|
|
||||||
|
// Handle non-exception-throwing cases:
|
||||||
|
// Neither JSON.parse(false) or JSON.parse(1234) throw errors, hence the type-checking,
|
||||||
|
// but... JSON.parse(null) returns null, and typeof null === "object",
|
||||||
|
// so we must check for that, too. Thankfully, null is falsey, so this suffices:
|
||||||
|
if (o && typeof o === "object") {
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
export function objectify (thing) {
|
export function objectify (thing) {
|
||||||
if(!isObject(thing))
|
if(!isObject(thing))
|
||||||
return {}
|
return {}
|
||||||
|
|||||||
Reference in New Issue
Block a user