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

Problem when parsing !included traits #915

@AndrewGibb

Description

@AndrewGibb

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"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions