nidi3 / raml-tester

Test if a request/response matches a given raml definition
Apache License 2.0
71 stars 14 forks source link

!include ignored in resource type parameters #52

Closed greenrd closed 9 years ago

greenrd commented 9 years ago

If I pass an included file to a resource type, like this:

exampleCollection: !include example/sites.json

then when validating the RAML, instead of reading the file example/sites.json, it just behaves as if the !include keyword wasn't there, and tries to parse the filename as if it were JSON.

Here is the relevant part of the stacktrace:

  [1] com.fasterxml.jackson.core.base.ParserMinimalBase._reportError (ParserMinimalBase.java:533)
  [2] com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken (ReaderBasedJsonParser.java:2,462)
  [3] com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue (ReaderBasedJsonParser.java:1,621)
  [4] com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken (ReaderBasedJsonParser.java:689)
  [5] com.fasterxml.jackson.databind.MappingIterator.hasNextValue (MappingIterator.java:240)
  [6] com.github.fge.jackson.JsonNodeReader.readNode (JsonNodeReader.java:142)
  [7] com.github.fge.jackson.JsonNodeReader.fromReader (JsonNodeReader.java:127)
  [8] com.github.fge.jackson.JsonLoader.fromReader (JsonLoader.java:179)
  [9] com.github.fge.jackson.JsonLoader.fromString (JsonLoader.java:192)
  [10] com.jayway.restassured.module.jsv.JsonSchemaValidator.matchesSafely (JsonSchemaValidator.java:214)
  [11] com.jayway.restassured.module.jsv.JsonSchemaValidator.matchesSafely (JsonSchemaValidator.java:75)
  [12] org.hamcrest.TypeSafeMatcher.matches (TypeSafeMatcher.java:65)
  [13] guru.nidi.ramltester.validator.RestassuredSchemaValidator.validate (RestassuredSchemaValidator.java:97)
  [14] guru.nidi.ramltester.core.RamlValidatorChecker.exampleSchema (RamlValidatorChecker.java:275)
  [15] guru.nidi.ramltester.core.RamlValidator.mimeType (RamlValidator.java:117)
  [16] guru.nidi.ramltester.core.RamlValidator.action (RamlValidator.java:102)
  [17] guru.nidi.ramltester.core.RamlValidator.resource (RamlValidator.java:85)
  [18] guru.nidi.ramltester.core.RamlValidator.validate (RamlValidator.java:66)
  [19] guru.nidi.ramltester.RamlDefinition.validate (RamlDefinition.java:122)

This is with raml-tester 0.8.4.

greenrd commented 9 years ago

Not sure how relevant this is, but 2 other RAML validators (ramlev and raml-validator) think my RAML is OK.

NoOrdInaryGuy commented 9 years ago

Here's a simple RAML file that reproduces the issue:

#%RAML 0.8
---
title: Example RAML API
baseUri: https://mydomain.com/api/{version}
version: v1

resourceTypes:
  - myCollection:
      get:
        responses:
          200:
            body:
              application/json:
                schema: |
                  {
                   "type": "string"
                  }
                example: |
                  <<exampleCollection>>

/site:
  type:
    myCollection:
      exampleCollection: !include example/sites.json

Issue manifests as: Message: Schema invalid: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'example': was expecting ('true', 'false' or 'null')

nidi3 commented 9 years ago

This is an issues of the raml parser. I created an issue for it: https://github.com/raml-org/raml-java-parser/issues/80 I'll have a look if I can fix it temporarily in raml-tester.

nidi3 commented 9 years ago

I don't think I can do anything here. Because raml-tester does not see the !include, it cannot know when to manually include a file.

nidi3 commented 9 years ago

Added a patched version of raml-java-parser's TemplateResolver. This should help.

nidi3 commented 9 years ago

Just saw this is already fixed, but the version containing the fix is not on maven central :-1: