raml-js-parser-2
raml-js-parser-2 copied to clipboard
Problem when parsing !included traits
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"
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:
- Suggest to
raml2obj
maintainers switching fromraml-1-parser
towebapi-parser
. - Make a patch PR in this repo and we'll review/release it.
Thanks!