raml-org / raml-js-parser

(deprecated) A RAML parser based on PyYAML written in CoffeScript and available for use as NodeJs module or in-browser.
195 stars 53 forks source link

Parsing resourcetypes with optional methods do not inherit in the resources #174

Closed alexresta closed 8 years ago

alexresta commented 8 years ago

The thing is that if you define methods as optional it doesn't include the traits (headers, queryparameters etc) in the parsed tree.

It does when you force them as required, but then you are breaking the "optional" thing, if you want to define a resource of that type that has a GET and a POST method, but another resource that only implements the GET...

As an example, I have the following very simple RAML, which defines a single trait, a resource type with forced POST and optional GET and a resource.

If you parse this raml you will see that the POST method has headers in there and the GET doesn't inherit them from the resourceType.

#%RAML 0.8
title: test1
version: v1.0
baseUri: http://localhost

traits:
  - secured:
      headers:
        Authorization:
          description: Used to send a valid OAuth access token.
          type: string
          required: true
          example: Bearer xxxxxxxxxxxxxxxx

resourceTypes:
  - collection:
      is: [secured]
      post:
        body:
          application/json:
        responses:
          200?:
            description: Returned if the object was retrieved successful.
          401?:
            description: Returned if the calling user is not authenticated.
      get?:
        responses:
          200:
            body:
              application/json:
          400?:
            description: Returned if the the request is invalid.

/items:
  type: collection
  description: I should have a secured trait, but it's not there
  get:
    responses:
      200:
        body:
          application/json:

  post:
    responses:
      200:
dmartinezg commented 8 years ago

Hi @alexresta, thanks for reporting, we will take care of this right away.

alexresta commented 8 years ago

seems to work! :)

any idea when it will be available as a release? thanks a lot!

dmartinezg commented 8 years ago

Hey @alexresta, I just released v0.8.16 in npm.

alexresta commented 8 years ago

gracias crack!