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?
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.
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.
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.
@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.
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”]
Raml snippet having items tag:
RamlJavaClientGenerator ramlCltGenObj = new RamlJavaClientGenerator(“com.test”,new File(“target”));
<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
updated- java.lang.RuntimeException: Invalid RAML descriptor [Unexpected key ‘items’. has been fixed…
We use this: