mulesoft-labs / osprey-method-handler

Middleware for validating requests and responses based on a RAML method object
Other
16 stars 16 forks source link

TypeError: Cannot read property 'constructor' of undefined at jsonBodyHandler osprey-method-handler.js:347:26 #26

Closed MaxenceDupressoir closed 7 years ago

MaxenceDupressoir commented 7 years ago

Hello, I'm facing an issue with osprey-mock-service and I tracked it down to this library. When I'm loading a a RAML (0.8) with only an example in the body property:

put:
    is: [userSecured]

    description: |
        Update member's contact information

    body:
        application/json:
            example: !include ../examples-fixtures/request/200-put-account-contact-information.json

I'm having an error: TypeError: Cannot read property 'constructor' of undefined at jsonBodyHandler osprey-method-handler.js:347:26

And this seems legit regarding this so called line:

var schema = body && (body.properties || body.type || body.schema) || undefined
  var isRAMLType = schema.constructor === {}.constructor

Ive looked back at the RAML 1.0 spec and type OR schema seems to be mandatory but it's not in 0.8.

Is this parser only compatible with RAML 1.0 and I'm missing a conf in the parent lib in order to use a 0.8 compatible parser or is this an error in this parser ?

Thanks !

jstoiko commented 7 years ago

Thanks for reporting this and thanks for the contribution Maxence!

There is a branch that contains a fix for your issue as well as other issues that have been reported. Feel free to give it a try and let me know if it works for you.