Unrecognized URI - Can't Find Referenced JSON Schema File


#1

EDIT: Workaround to this question is documented in the issue link below.

Hi,

I created issue: https://github.com/mulesoft/raml-for-jax-rs/issues/202, but maybe this is better as a forum posting. I have a raml file which imports a book schema file which in turn references an author schema file. All three files live in the same directory. My raml looks like this:

#%RAML 0.8
---
title: book
version: 1.0
mediaType: application/json
schemas:
  - book:  !include book.json

/books:
  /{bookTitle}:
    get:
      description: Retrieve a specific book title
      queryParameters:
        author:
          displayName: Author
          type: string
          description: An author's full name
          example: Mary Roach
          required: false
        title:
          displayName: Title
          type: string
          description: Title of the book
          example: 1984
          required: false
        genre:
          displayName: Genre
          type: string
          description: Genre
          example: Mystery
          required: false
        isbn:
          displayName: ISBN
          type: string
          minLength: 10
          example: 0321736079
          required: false
      responses:
        200:
          body:
            schema: book

The book.json looks like this:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "book",
    "type": "object",
    "properties": {
        "isbn": {
            "description": "ISBN",
            "type": "string"
        },
        "title": {
            "description": "title",
            "type": "string"
        },
        "genre": {
            "description": "genre",
            "type": "string"
        },
        "author": {
            "$ref": "author.json"
        }
    },
    "required": [
        "title",
        "author",
        "isbn"
    ]
}

and the author.json looks like this:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "author",
    "type": "object",
    "properties": {
        "firstName": {
            "description": "first name",
            "type": "string"
        },
        "lastName": {
            "description": "last name",
            "type": "string"
        }
    },
    "required": [
        "firstName",
        "lastName"
    ]
}

When I try to generate the service interface and model classes, I get this error:

[ERROR] Failed to execute goal org.raml.plugins:raml-jaxrs-maven-plugin:1.3.4:generate (default-cli) on project BookService: Error generating Java classes from: C:\Devel\JavaProjects\BookService\src\api\BookService.raml: Unrecognised URI, can't resolve this: file:/C:/Users/mydir/AppData/Local/Temp/1475181313344-0/author.json: C:\Users\mydir\AppData\Local\Temp\1475181313344-0\author.json (The system cannot find the file specified) -> [Help 1]

Can the plugin not resolve schemas that are referenced in separate files?


#2

You can put RAML file under src/main/api/BookService.raml and JSON schema under src/main/api/schemas sub-folder and examples under src/main/api/examples.
Give relative path under RAML file for the schema & examples files so that RAML can refer these external files.
Also, update pom.xml file for the resource folders definition: src/main/api