Open berntmelba opened 6 years ago
@berntmelba: sorry for the late response. I had to update this library for another issue so I took a quick look at your issue and it seems to be a legitimate scenario. Unfortunately, I did not have time to work on a fix.
Like you said, it shouldn't be too complicated to fix. Update the schema
assignment in jsonBodyHandler()
, add tests cases, etc. Feel free to make a PR if you have time.
In cases where the schema field of a request body declaration for
application/json
type refers to a named schema declared in the root section of the RAML content as in the following example, I have observed that an unexpected error is thrown when creating theospreyMethodHandler
for the associated RAML.Example RAML snippet
Problem This results in the following unexpected error when attempting to create the associated ospreyMethodHandler.
Root Cause Here is the offending code I found in the
jsonBodyHandler()
function that causes this error.The
body.schema
in the example RAML shown above is"newBooking"
while the actual JSON schema content is inbody.schemaContent
. The value"newBooking"
assigned to theschema
variable is then passed as input tojsonBodyValidationHandler()
which then attempts to performJSON.parse()
on this value resulting in the observed error. In cases where theschema
field in the RAML definition of a request/response body for a given media type is an inline JSON schema or refers to an external schema via an include statement, the logic above works fine because the schema content in these cases is populated in bothbody.schema
andbody.schemaContent
by theraml-1-parser
that is being used to parse the RAML.Suggested Fix Change the assignment statement from
schema = body.schema
toschema = body.schemaContent || body.schema