API Console and RAML file with external schema


#1

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:

schemas:
 - 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?


#2

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.


#3

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.


#4

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.


#5

Hi
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
traits:
  - !include http://localhost:8081/patterns/v1/trait-paged.yaml
  - cert :
     headers :
      airBags:
          type : integer
          minimum : 4
          required : true
      security :
          type: string
          enum : [ "ADAC"]
          required: false

/cars:
  post:
   body :
    schema : vehicle
  get:
   is : [cert]
   responses:
      200:
        body:
         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

{
    "$schema":"http://json-schema.org/draft-04/schema#",
    "title":"error",
    "description":"schema for api specified errors",
    "type":"object",
    "properties":
    {
        "status":
        {
            "type":"integer",
            "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",
            "minimum":"100",
            "maximum":"599"
        }
    }
}

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
#6

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