Any tool to convert RAML to JAX-RS


#1

Hi,

Are there tools available to convert RAML to JAX-RS?


#2

Hi @DarVar,

I know that there are some JAX-RS tools in the works right now, but I’m not sure where they stand. I will let you know when I have more info.

In the meantime - welcome to the RAML community! What are you hoping to do with RAML + JAX-RS?


#3

Thanks,

I guess my ideal workflow would be to design my REST API using RAML, Then use the RAML file to generate a template JAX-RS 1.x or 2.x Service and Client to get me started.

There is already a Maven plugin to convert WADL to JAX-RS. SO something similar would be great.
https://wadl.java.net/wadl2java.html


#4

@ddossot is working on some very relevant stuff here…


#5

The project I’m currently working on generates JAX-RS 1.x annotated interfaces in order to enable a RAML-first approach for API creation. It’s currently server-side only, but could be extended to support client-side as well.

As a side note, in term of developer tooling, the RAML support for SOAPui is worth checking: http://olensmar.blogspot.se/2013/12/a-raml-apihub-plugin-for-soapui.html


#6

Hi @ddossot,

Is this project on GitHub?


#7

Not yet but … coming soon!


#8

Hey all: @ddossot’s slick new RAML --> JAX-RS codegen project is now open on github! Find a link to it as well as a description on the projects page or go directly to github. It’s very early, but quite useful already. Feedback is always appreciated.


#9

When I try to build this project , it’s always failing with the following error.

Downloading: https://repo.maven.apache.org/maven2/org/raml/jaxrs/jaxrs-code-generator/2.1.0/jaxrs-code-generator-2.1.0.pom
[WARNING] The POM for org.raml.jaxrs:jaxrs-code-generator:jar:2.1.0 is missing, no dependency information available
Downloading: https://repo.maven.apache.org/maven2/org/raml/jaxrs/jaxrs-code-generator/2.1.0/jaxrs-code-generator-2.1.0.jar


#10

@drajareddy: can you show us your POM?


#11

POM file is already there in the folllowing project , can you guide me how to execute this project and verify the result


#12

Are you creating your own project with a POM that has a dependency entry for the raml-for-jax-rs project? Or what are you doing exactly?


#13

I am not creating any new project , I have checked out the RAML-FOR-JAX-RS project into my eclipse and try to run this project in my machine and see how it is generating POJO’s . My requirement is to generate POJO’s from RAML file to use it in my project to consume data (Json) coming from other application who provided me RAML.

Thanks in advance.


#14

Did you have a chance to look at the documentation? https://github.com/mulesoft-labs/raml-for-jax-rs/blob/master/raml-to-jaxrs/README.md


#15

@christian_vogel yes I have tried this example , in this example RAML has JSONSchema which is used to convert to POJO’s but RAML 1.0 does not have JSonschema to convert to POJO’s

Thanks alot for your replay.


#16

What do you mean RAML 1.0 does not have JSON Schema? It does.

Are you referring to the tool not converting JSON Schema into POJO’s?


#17

Here is my RAML file sample provided by vender , I want generate a code to consume data from them . can you please suggest me how do I create a client and POJO’s from this RAML.

#%RAML 1.0 DataType

type: object
properties:
  actionCode?: string
  id: string
  name: string
  desc?: string
  type: string
  group?: string
  status?: string
  created?: datetime
  createdBy?: string
  lastModified?: datetime
  lastModifiedBy?: string
  lastActivityDate?: datetime
  vintage: string
  exclusiveSaleCountry?: string []
  priceListCode?: string[]
  numberPerCase: number
  volumeSize?: string
  productHierarchy: number
  characteristics:
    type: array
    items: !include product-characteristic.raml
example: !include ../examples/product-request-example.raml

#18

There is a bit missing here. The RAML you posted does only describe a data model, but not the API.

You need the actual description of the API and provide that to the generator. For example:

#%RAML 1.0
title: My API

/customers:
  get:
    ...

The above example is a description for an API. This can include other files like the data model you posted to also describe the payload. Do you have such a file?


#19

Here is the root RAML

#%RAML 1.0

title: aaaaaaaxxx
version: v1
#baseUri: http://xxxxxxx.com

#mediaType: application/json

resourceTypes:
collection: !include common/resourceTypes/collection.raml
item: !include common/resourceTypes/item.raml

/products:
post:
body:
application/json:
type: !include dataTypes/product.raml
responses:
201:
body:
application/json:
example: |
{
“message” : “The resource has been created.”
}


#20

@drajareddy: I see you’ve been looking at the simple-json-example which has a JSON schema but no RAML types. If you’re looking for an example with RAML types, you might want to take a look at raml-defined-example.

Note that you can run each of these examples by executing $ mvn exec:java as described in the README of the Maven examples. In that same README, there is a list of configuration parameters, the one you’ll probably want to check is generateTypesWith which controls how (RAML) types are translated in the generated code. Hope this helps.