RAML 1.0 to REST/JSON Client Converter


#1

Hi everyone,
We have received RAML specs from one of our customers who are providers of REST /JSON service. We need to send/receive the JSON request/response respectively by developing a REST Client from the provided RAML file. (.raml extension) What is the best way to proceed. I would really like to generate client code using directly this .raml file. Is there already a tool?


#2

I think you are trying to create API implementation from the RAML file.

In this case, Mulesoft anypoint studio has an option to use api tool kit to create api implementation from RAML file.

Is this what you looking for?

Just try to create a project in Mulesoft anypoint studio IDE with RAML api, it will automatically generate the interface.

Refer: https://docs.mulesoft.com/apikit/v/3.x/apikit-tutorial


#3

HI, Thanks for getting back to me so quickly.

Actually the client has the API service already created at their end and we need to call that service using a Rest client. All they have shared is RAML specs and some JSON samples . (e.g for creating XML request/response from WSDL we used WSDL2Java tool and accordingly it created Client classes and model so as to call webservice) Similarly I wanted to create Java client code from this RAML so as to call the customer API service by sending JSON request to it.


#4

Hi,

Postman tool is a rest client to invoke the restful services.

But I am not sure about whether it will generate a java client code.


#5

@shilpa: if you’re looking for an opensource Java tool, there is an artifact here: https://github.com/mulesoft-labs/raml-java-tools called raml-to-pojo that might help you. There is also https://github.com/mulesoft-labs/raml-java-client-generator, it only works with RAML 0.8 though.


#6

Thank you @jstoiko I tried the ram java client generator and was able to generate the client classes/model by using below lines of code and by adding below dependencies in the pom xml of my maven project

I was able to run this from demo api.raml but when i replace the same with the raml which customer shared with us, I get below error, I see in raml we have tags like items under array objects

java.lang.RuntimeException: Invalid RAML descriptor [Unexpected key ‘items’. Options are : “additionalProperties” or “default” or “description” or “discriminator” or “discriminatorValue” or “displayName” or “example” or “examples” or “facets” or “maxProperties” or “minProperties” or “properties” or “required” or “usage” or “xml” or /((.+))/ or Any of :“type”,“schema”]
at org.mule.raml.ApiModelLoader.wrapApiModel(ApiModelLoader.java:45)
at org.mule.raml.ApiModelLoader.build(ApiModelLoader.java:74)
at org.mule.client.codegen.RamlJavaClientGenerator.generate(RamlJavaClientGenerator.java:88)

Raml snippet having items tag:

Attributes:
type: array
items:
type: object
properties:
Attribute:
type: object
properties:
AttributeNm:
type: string

Java code:
RamlJavaClientGenerator ramlCltGenObj = new RamlJavaClientGenerator(“com.test”,new File(“target”));
ramlCltGenObj.generate(this.getClass().getClassLoader().getResource(“service/api.raml”));

Pom xml

org.mule.raml.codegen
raml-client-generator-core
0.2

 	<dependency>
     	<groupId>org.mule.raml.codegen</groupId>
        <artifactId>raml-client-generator-maven-plugin</artifactId>
        <version>0.2</version>
 	</dependency>

Also, I see this link, it does say it supports both 1.0 and 0.8 versions of RAML


This tool generates a java rest client for a raml based api using a resource api approach. Supports both 0.8 and 1.0 versions of Raml


#7

updated- java.lang.RuntimeException: Invalid RAML descriptor [Unexpected key ‘items’. has been fixed…


#8

We use this:
https://github.com/phoenixnap/springmvc-raml-plugin