RAML to SpringMVC?


Hey all,

I’m creating a REST based API running in a SpringMVC context. I found that I can reuse some of the code generated by raml-to-jaxrs (mostly the models) but the interfaces need some work (getting rid of reponse wrappers, adding some annotations, etc). I’m considering adding a springMVC option to the raml-to-jax tool. Before I do that, are there any other tools that maybe already do that? Has anyone tried something similar? And if I do, is there any interest in sharing that back with the project?



Hi @egloben,

thanks a lot for considering adding something so valuable :blush: SpringMVC is for server code right?

Have you had a look on the generator tools we have using handlebar templates? It would be nice, if you think that makes sense for you, to contribute to them. The two main one are the raml-client-generator and raml2code (both are available on github). We are working right now to find a way to actually have only one in the future, but both will use handlebar templates for specific languages.

With regards to the SpringMVC approach - I haven’t seen one yet, so that would be something new. :wink:


Hey Christian,

I believe you can build both client and server using Spring MVC however, I’m focusing on server code at the moment. I’ll take a look at the handlebar templates and see if they fit to generate my controllers. That definitely seems like a good way to go. Thanks for the pointer!



Hi @egloben,

It would be definitely great if we find more and more contributors for the handlebars template initiative. We are setting up the base right now to make it easier to contribute templates and if you have any questions - please post it here. I’ll setup another label specifically for that when we have everything grounded to bring some more structure to the forum tackling specific question.



Hi @christian_vogel,

I took a look at the client generator. It doesn’t seem to recognize our RAML file (I get something like unused variable: schema) although the jaxrs generator seems to have no problem with it. For now, I’ve got the raml-to-jaxrs generator producing SpringMVC controllers through an extension. It’s still a bit hacky and required some changes to the way extensions are used (and a lot of code duplication :/) but it looks like a good start. I might be ready to share it on github today so anyone else who’s interested can jump on.




We’re starting to planning native support for RAML in springfox (http://springfox.github.io/springfox/) which supports swagger currently. Would love to get ideas from this community, also people who might be interested in collaborating. My Twitter handle is the same as my handle in this forum.



@egloben, how are you doing mate? want to ask for a quick update on your project :wink:


@Dilipkrish, that sounds great. what kind of help do you need explicitly?


I’m looking for contributors that are more intimately familiar with the RAML spec and help us build a spring-mvc service to RAML offering.

We already have service model that we build up based on spring mvc conventions. What needs to be done is as far as RAML goes is the mapping layer between the service model and the RAML representation for that model.



Sorry about the radio silence here. Got carried away by other priorities. I create a somewhat hacky extension for raml-to-jax. Required a bunch of code duplication and some changes to core as well (neither of which I like very much). Two things came up:

  1. Looks like a major change was committed to the project such that merging is a major pain.
  2. Spring MVC annotations are not inherited. This means that the current approach of generating a interface doesn’t offer much since I have to copy all the annotations to the implementing class anyway. I was thinking of generating full controller classes but like I said, other priorities took over.

I tried looking at some of the javascript generators you have out there but I’m unfamiliar with the tools so things got painful pretty fast… :confused:



First, can you confirm… are you trying to write java code that parses springMVC annotated classes, and from that generate a RAML file? Or are you trying to do what I hope you are…which is the single-source-of-truth route with RAML being the single source of truth, generating SpringMVC classes?

If you are going the RAML to SpringMVC, I can assure you, after much speculation (just ask @christian_vogel and @blakeembrey) about whether or not the raml-client-generator project could handle this, that it can indeed quite easily and quickly be used to generate code. It does require a bit of understanding of both nodejs (and some slight functional JS but not much) and the Handlebars.js templating engine. But, after about two weeks of messing around (and some help from those two guys), I have been able to generate a consumable SDK in java, python and ruby, and I don’t know python and ruby very well. It’s far from done/ready, but it works against our deployed APIs that “match” the RAML definition I build. I even have json schema converting to java pojos (using jsonschema2pojo right now, but working on a pure handlebars.js template to do the same thing). I will first say that the ruby and python code I generate was a direct copy of the java template I built, with language specific changes. Over some time the templates would be a bit different so that each language would mimic what a developer of that language would expect, but otherwise, it works.

@blakeembrey put together a separate project, raml-generator, that is a little more capable in that you can (and will) customize the “starter” JS code for your specific API, possibly repurposing the initial one provided. I did that to spit out specific files for one template for example, as well as to handle conditions such as inlined schemas vs included schemas. It’s been quite some fun working on it, and I think raml-generator has improved a bit as a result.

I am with you on the “painful” side of things. I too tried it, then gave up and went back to RAML-2-JAXRS and started writing java code to generate java code. But I kept on thinking for each language, I will need a language expert (in the case of SDK generators for languages like python, go, ruby, .net, etc) and a RAML parser for those languages that works as well. The beauty of the raml-generator project is the engine parses the RAML and calls the templates with various aspects of the RAML file details, like the initial “root” context, individual resources, etc. In the end, having a roughly similar template that can be used with minor differences for each language seemed to make more sense. As well, this very same process could be used to replace the RAML-2-JAXRS project, the RAML2HTML project, and others. Anything you can think of, you can use this one project with some templates to generate output. HTML, PDF, language code, server side code, etc.

I’d be happy to help get you started so that @blakeembrey and @christian_vogel can focus on the 1.0 spec that is hopefully coming sooner than later. Shoot me a PM here, and we can get you started.



To your first question, I was working on generating Java code from RAML. I appreciate your offer but as I said before, this is no longer a priority for me. I got a decent working solution in the RAML-to-JAX framework and then I realized that much of the code that’s generated will have to be replicated anyway (see above comment about annotation inheritance) so the whole thing is not as useful as I had hoped it would be.


It’s not an offer of help I’m afraid, more like a heads-up about something that stumped me when I was looking at exposing RAML from Spring @Controller-annotated classes; the details are in the forum post Can RAML Support multiple request bindings to one URL/Verb


Hi guys,

Not sure if this is happening yet or not, but i would like to start working on a generator from RAML to the Java Spring framework MVC.

I have forked the raml-client-generator project on GitHub and would like to start working on that. I need it for one of my projects anyway so i will be more than happy to contribute here.



We need the same RAML --> Spring MVC generator as well. I would be happy to contribute to this project.


@Alexandru_Godri & @muraalee what kind of help do you need? Please see the gitter conversation we had for the generation tool.

It’s a pretty good overview about the generator and how you use it to develop your own generator. It’s not based on the client-generator as we extracted the core out of it and published it here: https://github.com/mulesoft-labs/raml-generator

Please shout out for any questions!


Hi @christian_vogel,

Thanks for the shared information. I will take my time and read the conversation there, its pretty big, but i will find time to get through it.

I would like to achieve two things:

  1. I want to be able to generate a full project structure (folders and files) for the Spring framework in Java starting from a RAML document. This should create all the necessary controllers with the required annotations. It should also create the models according to the fields in the RAML specification. It should/could also create service and dao classes, all empty obviously.
    Ideally, this should be somehow parametrized, so you could only create the controllers if that is what you want and skip the models, services and/or DAOs.

  2. I want to be able to generate RAML documents starting from an already existing project in Spring, something like reverse engineering. This way i can take existing projects and generate the RAML Document. It will not be final, it will need some manual laboring, but still, it is something to go from.

Also, i am not sure if there is such a thing for LoopBack (http://loopback.io/)
I have searched a little and didn’t find anything yet. If there is nothing of the sort, this will be the next one after the integration with Spring :slight_smile:
I really like this RAML stuff and seeing as the two big sources for my APIs are Spring and Loopback i want to contribute in this aspect.

I will also join the chat on gitter, thanks for that link :slight_smile:


Is there any update on the subject? We’re ready to use RAML but since Swagger was previously used to generate server model/controllers for Spring projects it would be hard to sell RAML to our management without similar tooling.


I would say a couple things. First… while I may sound biased, the RAML 1.0 spec is the more capable spec, and has some big names behind it, so that may help sell it more so today then a few months ago to your management. The tooling is better and getting better every week or so when updates come out.

RAML 1.0 is still in RC but almost final, which means that most projects probably won’t start until shortly after it goes final on updating to 1.0. It will inevitably take some time for projects to move to 1.0 partly because some of the tooling for update spec will require some time to finish/test/fix, but also because there is a decent amount of additions to the 1.0 spec that will take developers parsing it a bit more time to learn and utilize.

As for the Swagger/RAML debate… they are both specs, very similar in many ways, although Swagger 2s spec is more like a subset of RAML 1.0 at this point. I am sure the specs will continue to advance, but regardless, there has, as long as I can remember, been a tool to convert from one to the other and back again. I believe their is a swagger to raml tool, that should take the full of swagger 2 and convert it to a raml 0.8 spec right now although I do not know the maturity of the project. With RAML 1.0 I would hope there is some update that could take advantage of things like YAML types, annotations and more. Point is, you can (or with a little work should be able to) take existing Swagger 1/2 docs, and convert them to RAML 0.8/1.0 now/soon.

Not sure that helps/reassures you much, but I am pretty sure there will be several updated RAML 1.0 projects coming soon.


A bit late to the discussion :slight_smile: but we have developed a free Maven Plugin (and standalone library) that converts RAML to Spring MVC Controllers & Client and also generates RAML from code.

Link: https://github.com/phoenixnap/springmvc-raml-plugin