Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Problem when parsing !included traits #915

Open
AndrewGibb opened this issue Dec 4, 2019 · 1 comment
Open

Problem when parsing !included traits #915

AndrewGibb opened this issue Dec 4, 2019 · 1 comment

Comments

@AndrewGibb
Copy link

AndrewGibb commented Dec 4, 2019

I've encountered this problem when using raml2html. Including traits from external files causes some spurious parsing errors. The raml2html repository directs parsing errors here.

Here's an example. Running $ raml2html - v on this file produces no errors:

#%RAML 1.0

title: My API
version: 0.1
mediaType: application/json

traits:
  resource_listing_head:
    responses:
      200:
        body:
          type: string

  uuid_validator:
    usage: Apply this to any resource which includes a uuid.
    description: |
      If the uuid-space in the URI does not contain a valid uuid,
      return 400 and a useful error message.
    responses:
      400:
        body:
          type: error
          example:
            description: Malformed URI
            debug: "AFISH is not a valid UUID"

types:
  error:
    description: A type containing an error message.
    properties:
      description:
        type: string
        description: Human-readable message describing the problem.
      debug:
        type: string
        description: |
          Machine-supplied information which might help
          the recipient solve the problem.

Whereas including the traits from external files and validating results in this error:

Api contains errors.

UNKNOWN_NODE: Unknown node: '200' (resource_listing_head.raml:3:1)
  ERROR_IN_INCLUDED_FILE: Error in the included file: Unknown node: '200' (TestA
PI.raml:7:3)
INVALID_PROPERTY_USAGE: RAML 1.0 does not allow using 'type' property within tra
its (resource_listing_head.raml:5:3)
  ERROR_IN_INCLUDED_FILE: Error in the included file: RAML 1.0 does not allow us
ing 'type' property within traits (TestAPI.raml:7:3)

Here is the API and the traits:

#%RAML 1.0

title: My API
version: 0.1
mediaType: application/json

traits:
   resource_listing_head: !include resource_listing_head.raml
   uuid_validator: !include uuid_validator.raml

resource_listing_head.raml:

#%RAML 1.0 Trait

responses:
  200:
    body:
      type: string

uuid_validator.raml:

#%RAML 1.0 Trait

usage: Apply this to any resource which includes a uuid.
description: |
  If the uuid-space in the URI does not contain a valid uuid,
  return 400 and a useful error message.
responses:
  400:
    body:
      type: error
      example:
        description: Malformed URI
        debug: "AFISH is not a valid UUID"
@postatum
Copy link
Contributor

Hi @AndrewGibb.
Note that raml-js-parser-2 has been deprecated, the new official parser is webapi-parser.

From what I see the dependency chain is raml2html -> raml2obj -> raml-1-parser.

Please either:

  1. Suggest to raml2obj maintainers switching from raml-1-parser to webapi-parser.
  2. Make a patch PR in this repo and we'll review/release it.

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants