API Console and RAML file with external schema


I’m new to RAML and MuleSoft’s API Console.
I created a RAML file and some JSON specification files.
I used the include directive to reference the JSON file, like this:

 - user: !include ../schema/user.json
 - element: !include ../schema/element.json

I validated the JSON schemas and RAML file using some JavaScript tools (npm packages 'raml-parse and z-schema.

Then I fired up a the API Console I cloned from github (https://github.com/mulesoft/api-console). I copied and pasted my RAML file into the API console browser and, but got some errors:

{"context":"while fetching ../schema/user.json","context_mark":null,"message":"cannot fetch ../schema/user.json (Not Found)","problem_mark":{"line":7,"column":9,"buffer":"#%RAML 0.8\nbaseUri: http://mystuff.hoffer.org/{version}\ntitle: UNI VPI\nversion: v1\nmediaType: application/json\nprotocols: [ HTTP, HTTPS ]\nschemas:\n - user: !include ../schema/user.json\n - element: !include ../schema/element.json\n/context:\n post:\n description: Send a user's current context to the server\n/element:\n get:\n description: Get a user's current collection of elements\n responses:\n 200:\n body:\n application/json:\n queryParameters:\n user:\n/user:\n /login:\n post:\n description: User logs into the application\u0000","pointer":157}}

It cannot find the schema because I used related path names. I tried using URLs in the include directives, but I still got an error.

How do you properly reference external schema?


Hi @aaron

If you cut and paste, the includes won’t work. As for the errors you got from including those external URLs, may be related to a CORS issue?

If the RAML file is public, host it together with all the other related files and instead of copying and pasting it in the console, launch the console with the query parameter ?raml=http://url.to.the.raml.

Make sure to enable CORS on the server exposing the files for the console to be able to reach them, please see: https://github.com/mulesoft/api-console/issues/29

I hope this helps.


Thanks. Where did you find the documentation on the query parameter and the implied GET service. I did not see anything about that in the README.


Thanks. Where did you find the documentation on the query parameter and the implied GET service. I did not see anything about that in the README.

I am part of the team that developed the console. We will update the documentation to make this a little clearer.


I’m having the exact issue have already enabled CORS
I have running traits , deployed on some jetty web container (lets say at port 8081)
So If I include just the yaml code snippets (traits remotely)

#%RAML 0.8
title: hybris Wishlist API
baseUri: http://api.hybris.com
version: v1
mediaType:  application/json
  - !include http://localhost:8081/patterns/v1/trait-paged.yaml
  - cert :
     headers :
          type : integer
          minimum : 4
          required : true
      security :
          type: string
          enum : [ "ADAC"]
          required: false

   body :
    schema : vehicle
   is : [cert]
         schema : sss

It works fine
But if add a json schema (deployed on the same host, with CORS enabled)

  - someSchema:  !include http://localhost:8081/patterns/v1/example.json

Then i got in the api designer failure with some confusing message

Where the curl example.json returns

    "description":"schema for api specified errors",
            "description":"original http error code, this should not vary from the response http, however there might be cases when request http is remapped by e.g. proxy",

Not so sure if it is really CORS then since for the yaml part it works.
I was playing with escaping content somehow - but still fails

Regards Mariusz

Include of the remote JSON schema causes CORS failure

I am getting an error in my ubuntu machine, i have installed the Anypointstudio and java in ubuntu, and i have created one project using the raml given example raml i was able to acces it from my local machine, when i connect the url from ios side it shows

message = “Unsupported media type”;
dont know why i am getting this message please help. Thanks