Java RAML parser - How can I access response code and example response?



I have a need to access the response code and example response, as defined in a .raml file, from my Java code. Is there a way of achieving this?

I’ve managed to get each Resource, and all of their ‘nested’ resources, and for each Resource I’ve managed to get their Actions as well. But I can’t seem to access elements of the Actions’ Response members. Only body, description and headers are available.

Am I missing something?


Could you post your RAML here. Let me test this.

The Action class does have a method to get the responses as you can see here:


I am using that exact method, but the Response objects that are returned do not have the members to represent the response code or the example response.


              example: |
                  "data" : {
                    "uuid" : "0021b6c3-d838-4d78-b59b-0ea42133e177",
                    "product_name" : "RECKITT BENCKISER",
                    "product_categories_uuid" : "de66f565-18bf-11e4-8694-00163e2ce2b8"
                  "success" : true,
                  "status" : 200


I’ve found the missing members that I was looking for. Actually I was just looking in the wrong place. The Objects are nested exactly as they are in the RAML spec. So the Resource has an Action member, which has a Response member. Inside the Response object is where I assumed I would find the example.

Here is what worked :

private void foo(Action _a,) {

        Collection<Response> responses = _a.getResponses().values();
        for (Response r : responses) {
            Collection<MimeType> mime = r.getBody().values();
            for(MimeType m : mime) {


That makes sense - good you’ve seen it first. Sorry for the delay in my response :blush:


I tried your code and I still do not see the response code from the RAML file displayed. In my RAML file, under responses, I have 200: 400: 500: etc… but I can never find anywhere in the code to get the 200 from. It’s not part of the response, body, mimetypes, etc. It seems the data below each of the response codes is returned, and maybe the JavaScript parser has some way of getting at that since the documentation part of the designer shows it. But the Java RAML parser doesn’t seem to give you that code that I can see.

Basically I am trying to figure out how to build my methods (generated SDK code from RAML file) by looking for a 2xx response code type, then using the schema defined there to figure out the method response class to use.

I believe the JAX-RS module responds with a ResponseWrapper class and that’s the right way to do this since there is the possibility of error responses and other response bodies, but I am still trying to figure out how to pick out the specific 2xx response code in the RAML file. Any thoughts?


Can you send me the RAML file you’ll try. I’ll have a look as soon as I have some time :wink:


In the snippet below, I am trying to get the 200, 400, 401, 403 and 500 values. I have iterated the Response collection, and I can get everything else but the value of the response code. I think either I am missing some obscure way to access that, or it was not added to the RAML java parser code, in which case it probably should be added.

schema: users
example: !include example/json/users.json
schema: errors
example: |
“status”: 400,
“code”: “E400-1”,
“message”: “Bad client info”,
schema: errors


Hi @justjacksonn - I tried it and I am getting the 200 back without any problem. So can you elaborate more on what you tried?


can you provide java code for parse raml.

thanks in advance