Allows for elements other than objets at the root of JSON requests.
Currently, osprey-method-handler only accepts resources that use object types in their body. However, all RAML types should be valid for request and response bodies, including array, string, integer, ... (Granted, using strings or integers as root elements in request or response-bodies isn't a nice thing to do, but arrays should be perfectly valid and if you must, even a single number is valid JSON.)
Example:
Using the following specification in Osprey yields an error in osprey-method-handler.
#%RAML 1.0
title: Test API
/test:
post:
body:
application/json:
type: array
items: string
SyntaxError: Unable to compile JSON schema for post /test: Unexpected token a in JSON at position 0
at JSON.parse (<anonymous>)
at jsonBodyValidationHandler (/[...]/osprey-method-handler/osprey-method-handler.js:429:21)
at jsonBodyHandler (/[...]/osprey-method-handler/osprey-method-handler.js:350:21)
at /[...]/osprey-method-handler/osprey-method-handler.js:295:29
at Array.forEach (native)
at /[...]/osprey-method-handler/osprey-method-handler.js:291:14
at Array.forEach (native)
at bodyHandler (/[...]/osprey-method-handler/osprey-method-handler.js:279:9)
at ospreyMethodHandler (/[...]/osprey-method-handler/osprey-method-handler.js:105:21)
at /[...]/osprey/lib/server.js:39:12
Depends on mulesoft-labs/node-raml-validate#6
Allows for elements other than objets at the root of JSON requests.
Currently,
osprey-method-handler
only accepts resources that use object types in their body. However, all RAML types should be valid for request and response bodies, includingarray
,string
,integer
, ... (Granted, using strings or integers as root elements in request or response-bodies isn't a nice thing to do, but arrays should be perfectly valid and if you must, even a single number is valid JSON.)Example: Using the following specification in Osprey yields an error in
osprey-method-handler
.(This PR also includes #24)