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

RAML parser throws errors on headers in a trait #144

Closed mblout closed 9 years ago

mblout commented 9 years ago

I'm getting a validation error on the following (snippet) - it flags the 'description' (the first item) as an error - "each header must be a map'.

[see this line in validate_headers: if (!(util.isNullableMapping(param[1]) || util.isNullableSequence(param[1])))]

Here's my RAML, defining headers in a trait:

#%RAML 0.8

---
title: Test Service
baseUri: http://sometest.org/mobile/platform/test
version: 1.0
mediaType: application/json
protocols: [HTTPS]

traits:
  - sql:
      headers:
        test-Mobile-Sql:
        description: blah blah blah
        type: string
        required: true
        example: |
          SELECT "title" from "Movies"

/sql:
  description: |
    blah blah blah
  get:
    description: blah blah blah
    is: [ sql ]
    queryParameters:
      argX:
        description: blah blah blah
        type: string
      parameterX:
        description: blah blah blah
        type: string
    responses:
      200:
        body:
          application/json:
            example: |
              [{ "title" : "The Imitation Game"}]
dmartinezg commented 9 years ago

I had to look at the format, you pasted this:

#%RAML 0.8
title: Test Service
baseUri: http://sometest.org/mobile/platform/test
version: 1.0
mediaType: application/json
protocols: [HTTPS]

traits:
  - sql:
      headers:
        test-Mobile-Sql:
        description: blah blah blah
        type: string
        required: true
        example: |
          SELECT "title" from "Movies"

/sql:
  description: |
    blah blah blah
  get:
    description: blah blah blah
    is: [ sql ]
    queryParameters:
      argX:
        description: blah blah blah
        type: string
      parameterX:
        description: blah blah blah
        type: string
    responses:
      200:
        body:
          application/json:
            example: |
              [{ "title" : "The Imitation Game"}]

The test-Mobile-Sql header is wrongly indented, and the error message is in line 11 which it expects to be a mapping (a hash), but is a string... you should have something like:

#%RAML 0.8
title: Test Service
baseUri: http://sometest.org/mobile/platform/test
version: 1.0
mediaType: application/json
protocols: [HTTPS]
traits:
  - sql:
      headers:
        test-Mobile-Sql:
          description: blah blah blah
          type: string
          required: true
          example: |
            SELECT "title" from "Movies"
/sql:
  description: |
    blah blah blah
  get:
    description: blah blah blah
    is: [ sql ]
    queryParameters:
      argX:
        description: blah blah blah
        type: string
      parameterX:
        description: blah blah blah
        type: string
    responses:
      200:
        body:
          application/json:
            example: |
              [{ "title" : "The Imitation Game"}]
mblout commented 9 years ago

ooof, my bad [confirmed]. thanks!