Code Monkey home page Code Monkey logo

raml-java-client-generator's Introduction

RAML Client Generator

alt text

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

Example

For this api

#%RAML 0.8
title: Client API
version: 0.1
baseUri: http://mycompany.com/clientservice/api
documentation:
  - title : Users Platform
    content : This api describes how to access to the users platform
mediaType: application/json
/users:
  description: "Users in the platform"
  get:
    description: "Returns the list of all users"
    responses:
      200:
        body:
          application/json:
            example: |
             [{"user" : "Mariano"}]

Using the generated api

final ClientAPIResponse<List<UsersGETResponseBody>> result = ClientAPIClient.create().users.get();

Customizing the client

final ClientAPIClient client = new ClientAPIClient() {
    @Override
    protected Client getClient() {
        final Client client = ClientBuilder.newClient();
        client.property(ClientProperties.CONNECT_TIMEOUT, 1000);
        client.property(ClientProperties.READ_TIMEOUT, 1000);
        return client;
    }
};
client.users.userId("luis").get();

Calling the code generator from Java

It can easily be embedded the code generation into your code just. Add the dependency to pom.xml

  <dependency>
        <groupId>org.mule.raml.codegen</groupId>
        <artifactId>raml-client-generator-core</artifactId>
        <version>0.11</version>
  </dependency>

Note: Since the RAML Java Client Generator artifacts are not published to Maven Central you will also have to add the following repository either to your pom.xml or an active profile in your maven settings.

  <repositories>
    <repository>
      <id>mulesoft-releases</id>
      <name>Mule Release Repository</name>
      <url>https://repository-master.mulesoft.org/nexus/content/repositories/releases</url>
    </repository>
  </repositories>

And then call the RamlJavaClientGenerator

 new RamlJavaClientGenerator(
                "com.acme",
                targetFolder).generate(this.getClass().getClassLoader().getResource("simple/basic.raml"));

Generate client code from RAML using the maven plugin

There is also a maven plugin that allows you to generate the client code during your build process.

    <build>
        <plugins>
            <plugin>
                <groupId>org.mule.raml.codegen</groupId>
                <artifactId>raml-client-generator-maven-plugin</artifactId>
                <version>0.11</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate-client</goal>
                        </goals>
                        <configuration>
                            <basePackage>org.mule.example</basePackage>
                            <useJava8Dates>false</useJava8Dates>                            
                            <!--True by default                            -->
                            <includeAdditionalProperties>true</includeAdditionalProperties>
                            <!--False by default                            -->
                            <useOptionalForGetters>false</useOptionalForGetters>
                            <!--False by default                            -->
                            <useBigDecimals>false</useBigDecimals>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Note: Since the RAML Java Client Generator artifacts are not published to Maven Central you will also have to add the following plugin repository either to your pom.xml or an active profile in your maven settings.

  <pluginRepositories>
    <pluginRepository>
      <id>mulesoft-releases</id>
      <name>Mule Release Repository</name>
      <url>https://repository-master.mulesoft.org/nexus/content/repositories/releases</url>
    </pluginRepository>
  </pluginRepositories>

Disclaimer

This is an incubator project (so expect bugs) so no mulesoft oficial support. If any issue is detected please report an issue and we will try to fix it. Also PR are welcome.

raml-java-client-generator's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

raml-java-client-generator's Issues

MessageBodyReader not found for media type=text/plain

I used the raml-java-client-generator to generate jars for MashapeWeatherAPIClient which are later put in my Java project. When i try to run my java project I get an error. Can someone help me solve this?

package com.newpackage;

import org.mule.example.api.MashapeWeatherAPIClient;
import org.mule.example.resource.weatherdata.model.WeatherdataGETHeader;
import org.mule.example.resource.weatherdata.model.WeatherdataGETQueryParam;

public class TheMain {
public static void main(String[] args){
WeatherdataGETHeader header = new WeatherdataGETHeader();
header.setXMashapeKey("g9zsZDIplfmshIOO3pNVkHjHn1Kep13OsF3jsn4bVomnkRBy5x");
WeatherdataGETQueryParam queryParams = new WeatherdataGETQueryParam( -121.955236, 37.354108);

	MashapeWeatherAPIClient.create().weatherdata.get(queryParams, header);
}

}

My error is

Exception in thread "main" org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/plain, type=class org.mule.example.resource.weatherdata.model.WeatherdataGETResponse, genericType=class org.mule.example.resource.weatherdata.model.WeatherdataGETResponse.
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:232)
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1085)
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:853)
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:785)
at org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:326)
at org.glassfish.jersey.client.InboundJaxrsResponse$1.call(InboundJaxrsResponse.java:111)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:419)
at org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:108)
at org.mule.example.resource.weatherdata.Weatherdata.get(Weatherdata.java:52)
at com.newpackage.TheMain.main(TheMain.java:13)

Unable to run generate-client goal with arguments

Hi there- thanks for your plugin, appreciate your work on it!

I'm running into an issue with the basePackage argument when trying to generate classes with Maven on the command line:

mvn raml-client-generator-maven-plugin:generate-client -DbasePackage=com.example.mypackage
[ERROR] Failed to execute goal org.mule.raml.codegen:raml-client-generator-maven-plugin:0.1.1:generate-client (default-cli) on project integration-services: The parameters 'basePackage' for goal org.mule.raml.codegen:raml-client-generator-maven-plugin:0.1.1:generate-client are missing or invalid -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.mule.raml.codegen:raml-client-generator-maven-plugin:0.1.1:generate-client (default-cli) on project integration-services: The parameters 'basePackage' for goal org.mule.raml.codegen:raml-client-generator-maven-plugin:0.1.1:generate-client are missing or invalid
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginParameterException: The parameters 'basePackage' for goal org.mule.raml.codegen:raml-client-generator-maven-plugin:0.1.1:generate-client are missing or invalid
        at org.apache.maven.plugin.internal.DefaultMavenPluginManager.populatePluginFields(DefaultMavenPluginManager.java:643)
        at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:596)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:121)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        ... 20 more

I may be missing something, though can't seem to find the correct usage of the plugin documented anywhere?

Is this still being maintained? If so I'd like to learn more or help resolve an issue if there is one!

Thanks and all the best!

Version 0.2 of raml-client-generator-maven-plugin is not available on maven?

Describe the bug

I get "the POM for org.mule.raml.codegen:raml-client-generator-maven-plugin:jar:0.2 is missing, no dependency information available" when I run maven

To Reproduce
I added the following to my pom.xml file (exactly as in the github README):

<build>
    <plugins>
        <plugin>
            <groupId>org.mule.raml.codegen</groupId>
            <artifactId>raml-client-generator-maven-plugin</artifactId>
            <version>0.2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate-client</goal>
                    </goals>
                    <configuration>
                        <basePackage>org.mule.example</basePackage>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

I also added the repos I found in the pom.xml from the project

<repositories>
    <repository>
        <id>mulesoft-releases</id>
        <name>Mule Release Repository</name>
        <url>https://repository.mulesoft.org/releases</url>
    </repository>
    <repository>
        <id>mulesoft-snapshots</id>
        <name>Mule Snapshot Repository</name>
        <url>https://repository.mulesoft.org/snapshots</url>
    </repository>
</repositories>

in the pom.xml as well as trying 0.2-SNAPSHOT for the plugin version (instead of 0.2). Nothing seems to work.

Expected behavior
The plugin gets downloaded and added to project?

Subresource on same line generates invalid default constructor.

Describe the bug
When a resource with a sub-resource is defined on the same line the default constructor of the parent resource class does not properly initialize the sub-resource.

To Reproduce
Steps to reproduce the behavior:

  1. Create a RAML that contains the following resource definition.
/projects/rename:
      put:
        description: Rename a project
        body:
          #schema: projectName
        responses:
          202:
          404:
  1. Generate client code
  2. Try to compile the generated source
  3. There is a error The blank final field rename may not have been initialized on the default constructor for the projects resource class (resource/projects/Projects.java).

Expected behavior
The subresource attribute should be initialized to null in the default constructor as is the case when defining the subresource on a second line.

Unable to generate client with RAML 1.0 and Libraries

Hello, we are unable to generate client code using RAML 1.0 and libraries. Attached RAML file that causing issues. Initially I was getting "Unrecognized token 'yaml': was expecting ('true', 'false' or 'null')
at [Source: [yaml-type-flag]; line: 1, column: 6]". Did a local update to pass the right typeDeclaration string in getTypeAsString class and passed the issue. The RAML uses the "uses" syntax and doesn't have "types" inline in the RAML. Because of that the "types" aren't recognized and using the examples to create the client classes. Updated the RAML to have inline "types" and now erroring out "com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input". Still working on how to fix this issue.

Can we get support for data types defined in library and using "uses" clause in RAML

Duplicate client constructor

The following RAML will create java files with RamlJavaClientGenerator, but the client.java contains a duplicate definition of TestClient() function, one with null, and the other with the base uri.

#%RAML 1.0
title: test
baseUri: https://mulesoft.com
version: v1

/api/a:
get:

/tmp/output/testapi/api/TestClient.java:23: error: constructor TestClient() is already defined in class TestClient
public TestClient() {
^
1 error

The generated code contains:

public class TestClient {

private String _baseUrl;
public final Api api;

public TestClient() {
    _baseUrl = null;
    api = null;
}

public TestClient(String baseUrl) {
_baseUrl = baseUrl;
api = new Api(getBaseUri(), getClient());
}

public TestClient() {
    this("https://mulesoft.com");
}

NPE when full path defined twice

The following raml

#%RAML 1.0
title: test
version: v1

/api/a:
get:
/api/b:
get:

Will cause the following error to be thrown.

java.lang.NullPointerException
at org.mule.client.codegen.RamlJavaClientGenerator.buildResourceClass(RamlJavaClientGenerator.java:277)
at org.mule.client.codegen.RamlJavaClientGenerator.generate(RamlJavaClientGenerator.java:191)
at org.mule.client.codegen.RamlJavaClientGenerator.generate(RamlJavaClientGenerator.java:90)
at BuildJarFromRAML.main(BuildJarFromRAML.java:33)

Because the /api path is defined twice, when processing /api/b the parent of b is not linked correctly as it knows /api already exists but doesn't set it's parent properly.

Java Class duplication among sub types

Describe the bug
Java Classes are duplicated for sub types

To Reproduce
Steps to reproduce the behavior:

generate java classes from ramls in the attached zip, for the complex.raml and the simple.raml,
both generate duplicates of the Log class.

Expected behavior
The Log class should have been generated once.

** version tested **
f9575cf

Additional context
attached zip of ramls

classduplication.zip

For the complex raml, the Logs class is created 7 times. For simple it is generated 4 times.

IllegalArgumentException: URI is not absolute when using external schemas

My RAML contains pretty standard references to external schemas, like:

schema:
    - error: !include schema/error.js

I'm using the latest 0.1-SNAPSHOT of the Maven plug-in, configured with:

<ramlURL>${project.baseUri}/src/main/resources/spec/api.raml</ramlURL>

I'm receiving this exception during codegen:

java.lang.IllegalArgumentException: URI is not absolute
    at java.net.URI.toURL(URI.java:1088)
    at org.jsonschema2pojo.ContentResolver.resolve(ContentResolver.java:65)
    at org.jsonschema2pojo.SchemaStore.create(SchemaStore.java:47)
    at org.jsonschema2pojo.SchemaStore.create(SchemaStore.java:93)
    at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:59)
    at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:30)
    at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:74)
    at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:41)
    at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:60)
    at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:31)
    at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:122)
    at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:66)
    at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:88)
    at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:38)
    at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:73)
    at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:30)
    at org.mule.client.codegen.RamlJavaClientGenerator.generatePojoFromSchema(RamlJavaClientGenerator.java:417)
    at org.mule.client.codegen.RamlJavaClientGenerator.generate(RamlJavaClientGenerator.java:96)
    at org.mule.client.codegen.RamlJavaClientGenerator.generate(RamlJavaClientGenerator.java:86)
    at org.mule.client.codegen.maven.plugin.RamlJavaClientGeneratorMojo.execute(RamlJavaClientGeneratorMojo.java:61)

Support for Enums

Is your feature request related to a problem? Please describe.
It looks like my RAML 1.0 spec is getting ignored on declarations like:

#%RAML 1.0 DataType
displayName: Citizenship Type
description: Applicant's citizenship information.
type: object
additionalProperties: false
properties:
  type:
    type: string
    enum: [CADN, DIPL, INTD, LIMM, MIPE, PERM, REFG, STUV, UNKN, VIST, WRKP]
    description: Visa type code
    example: "STUV"

The generated class Visa has no enums.

Describe the solution you'd like
The generated class Visa should have a public class called TypeEnum with the enumerated values of the types declared in the RAML.

Describe alternatives you've considered
For now, I'm able to work around it, but the Enum support would be fantastic, since the RAML specs defines that the values MUST match with one of the enum values to be valid.

Model java class generated with @JsonPropertyOrder - wrong order

Describe the bug
The model java class generated contains wrong fields order in @JsonPropertyOrder

To Reproduce
Steps to reproduce the behavior:

  1. include the api.raml attached

  2. include the attached schema file
    raml-codegen-issue.zip

  3. include the attached example json request file

  4. run the mvn clean install to generate the java client model class

  5. verify the @JsonPropertyOrder in the generated java model class -- fields are not in the expected/required order to work properly when send the body request.

Expected behavior
the @JsonPropertyOrder in the generated java model class -- fields must be in the expected/required order to work properly when send the body request.

Party.java model generated with @JsonPropertyOrder
expected:
@JsonPropertyOrder({
"@id",
"PartyTypeCode",
"FullName",
"GovtID",
"GovtIDTC",
"GovtIDCertificationDate",
"ResidenceCountry",
"Person",
"Organization",
"Address",
"Phone",
"Producer",
"EMailAddress",
"OLifEExtension"
})

current:
@JsonPropertyOrder({
"@id",
"PartyTypeCode",
"FullName",
"GovtID",
"GovtIDTC",
"GovtIDCertificationDate",
"ResidenceCountry",
"Person",
"Address",
"Phone",
"EMailAddress",
"Producer",
"Organization",

"OLifEExtension"
})

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Generation of @JsonAnyGetter additionalProperties not-working on pre 2.9.0 jackson servers.

Hello

We are using the generator and we have come upon the following problem. The generator is including a @JsonAnyGetter annotated getAdditionalProperties method for the POST bodies.

I have found that this feature has been introduced in jackson from version 2.9.0 but in our case we are trying to deploy our application to a wildfly server which provides us with jackson 2.8.9. In this case jackson is adding an empty additionalProperties to the outgoing JSON which is then rejected by the API we are trying to access.

Is it possible to disable the generation globally or per type of the additionalProperties field & accompanying methods.

Also any other ideas would be greatly appreciated!

Thanks!
Giorgos

media type error

This RAML
/xml:
get:
description: Generates XML
responses:
200:
body:
text/plain:

Is generating
final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);

Unable to expose private API

Having a private API in

https://anypoint.mulesoft.com/apiplatform/---companyname---/#/portals/organizations/----organization-id----/apis/---api-number----/versions/---version-number--

it is not possible to pass any authentication / token informations as just
new InputStreamReader(ramlURL.openStream()))
is done in RamlJavaClientGenerator
not allowing any basic auth or token header.

Result is always:

[ERROR] Failed to execute goal org.mule.raml.codegen:raml-client-generator-maven-plugin:0.1.1:generate-client (default-cli) on project : Exception while generating client. Server returned HTTP response code: 401

(setting API to public is not an option as it is a private one ;-) )

Getting StackOverflowError when RAML contains trees/cycle dependencies for optional children

The 'org.mule.raml.codegen', name: 'raml-client-generator-core', version: '0.2' plugin retrieves StackOverflowError when generating POJO if raml contains trees/cycle dependencies for optional children

To Reproduce
Steps to reproduce the behavior:

  1. Put this raml to your project:
    "
    #%RAML 1.0
    title: locations
    version: 1.0.0
    baseUri: /bar/locations
    protocols: [ HTTPS ]
    mediaType: application/json
    documentation:
  • title: Some title
    content:
    'Blah-blah-blah.'
    types:
    foo:
    type: object
    description: Some definition
    properties:
    children?:
    description: The list of children nodes.
    type: foo[]
    /bar:
    get:
    displayName: SomeDisplayNameValue
    description: SomeDescriptionValue
    responses:
    200:
    body:
    application/json:
    type: foo
    "
  1. Try to generate POJO using 'org.mule.raml.codegen', name: 'raml-client-generator-core', version: '0.2' plugin

  2. See error:

Exception in thread "main" java.lang.StackOverflowError
at com.sun.codemodel.JPackage._class(JPackage.java:177)
at com.sun.codemodel.JPackage._class(JPackage.java:164)
at com.sun.codemodel.JPackage._class(JPackage.java:197)
at org.jsonschema2pojo.rules.ObjectRule.makeUnique(ObjectRule.java:631)
at org.jsonschema2pojo.rules.ObjectRule.makeUnique(ObjectRule.java:635)
...
at org.jsonschema2pojo.rules.ObjectRule.makeUnique(ObjectRule.java:635)
at org.jsonschema2pojo.rules.ObjectRule.makeUnique(ObjectRule.java:635)
at org.jsonschema2pojo.rules.ObjectRule.getClassName(ObjectRule.java:613)
at org.jsonschema2pojo.rules.ObjectRule.createClass(ObjectRule.java:306)
at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:98)
at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:70)
at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:90)
at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:40)
at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:73)
at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:66)
at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:30)
at org.jsonschema2pojo.rules.ArrayRule.apply(ArrayRule.java:81)
at org.jsonschema2pojo.rules.ArrayRule.apply(ArrayRule.java:37)
at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:113)
at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:40)
at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:73)
at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:30)
at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:75)
at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:43)
at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:70)
at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:38)
at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:119)
at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:70)
....
at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:113)
at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:40)
at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:73)
at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:30)
at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:75)
at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:43)
at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:70)
at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:38)
at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:119)
at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:70)
at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:90)
at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:40)
at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:73)

Expected behavior
POJO files must be generated

Set timeout

Currently timeout is infinite when the generated

    private Client getClient() {
        return ClientBuilder.newClient();
    }

is called.

Please generate

	private Client getClient() {
		return ClientBuilder.newClient(createConfiguration());
	}

	protected Configuration createConfiguration() {
		return new ClientConfig();
	}

with a configurable configuration.

see http://www.adam-bien.com/roller/abien/entry/setting_timeout_for_the_jax

NullPointerException while trying to use application/xml as a body for PUT api

Template RAML where the issue is seen,

/myapi:
description: "Some description"
put:
description: "some description."
queryParameters:
someName:
description: "Some name"
type: "string"
required: true
example: "some example"
body:
application/xml:
type: MyAPI
responses:
200:
body:
type: "string"
500:
body:
type: Error

Include cannot be resolved

We have a raml which has child raml's and the child raml's are included in the main api.raml using Include keyword. When we use this plugin, we are getting this error " Include cannot be resolved"

Can you please hlep.

generate with error: Provider org.glassfish.json.JsonProviderImpl could not be instantiated: java.lang.ClassCastException

Describe the bug
I used to generate RAML file from salefore: https://github.com/SalesforceCommerceCloud/commerce-sdk/tree/master/apis/product/products

it shown the error as below.

Note: it worked well with api.raml file.

To Reproduce
Steps to reproduce the behavior:

  1. Config raml like this:
    ${project.build.resources[0].directory}/apis/product/catalogs/catalogs.raml
  2. Run and gennerate code
    Expected behavior
    Java file will be generated successfully.

Screenshots
If applicable, add screenshots to help explain your problem.

[INFO] Total time: 8.466 s
[INFO] Finished at: 2022-03-31T17:12:00+07:00
[INFO] Final Memory: 23M/257M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.mule.raml.codegen:raml-client-generator-maven-plugin:0.11:generate-client (default) on project raml-client-generator-example: Exception while generating client. Internal error while trying to call public abstract java.lang.String org.raml.v2.api.model.v10.datamodel.TypeDeclaration.toJsonSchema(): InvocationTargetException: Provider org.glassfish.json.JsonProviderImpl could not be instantiated: java.lang.ClassCastException: org.glassfish.json.JsonProviderImpl (loaded by org.codehaus.plexus.classworlds.realm.ClassRealm@0x00000001000602b0) cannot be cast to javax.json.spi.JsonProvider (loaded by org.codehaus.plexus.classworlds.realm.ClassRealm@0x00000001000602b0) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.mule.raml.codegen:raml-client-generator-maven-plugin:0.11:generate-client (default) on project raml-client-generator-example: Exception while generating client.
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Exception while generating client.
	at org.mule.client.codegen.maven.plugin.RamlJavaClientGeneratorMojo.execute(RamlJavaClientGeneratorMojo.java:90)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
	... 20 more
Caused by: java.lang.RuntimeException: Internal error while trying to call public abstract java.lang.String org.raml.v2.api.model.v10.datamodel.TypeDeclaration.toJsonSchema()
	at org.raml.yagi.framework.model.ModelProxyBuilder$SimpleProxy.invoke(ModelProxyBuilder.java:79)
	at com.sun.proxy.$Proxy30.toJsonSchema(Unknown Source)
	at org.mule.raml.impl.v10.model.ApiModelImpl.getTypeAsString(ApiModelImpl.java:103)
	at org.mule.raml.impl.v10.model.ApiModelImpl.getSchemas(ApiModelImpl.java:78)
	at org.mule.client.codegen.RamlJavaClientGenerator.generate(RamlJavaClientGenerator.java:138)
	at org.mule.client.codegen.RamlJavaClientGenerator.generate(RamlJavaClientGenerator.java:129)
	at org.mule.client.codegen.maven.plugin.RamlJavaClientGeneratorMojo.execute(RamlJavaClientGeneratorMojo.java:85)
	... 22 more
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.raml.yagi.framework.model.ModelProxyBuilder$SimpleProxy.fromMethod(ModelProxyBuilder.java:98)
	at org.raml.yagi.framework.model.ModelProxyBuilder$SimpleProxy.invoke(ModelProxyBuilder.java:74)
	... 28 more
Caused by: javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl could not be instantiated: java.lang.ClassCastException: org.glassfish.json.JsonProviderImpl (loaded by org.codehaus.plexus.classworlds.realm.ClassRealm@0x00000001000602b0) cannot be cast to javax.json.spi.JsonProvider (loaded by org.codehaus.plexus.classworlds.realm.ClassRealm@0x00000001000602b0)
	at javax.json.spi.JsonProvider.provider(JsonProvider.java:100)
	at javax.json.Json.createBuilderFactory(Json.java:282)
	at org.raml.v2.internal.impl.v10.type.TypeToJsonSchemaVisitor.<init>(TypeToJsonSchemaVisitor.java:59)
	at org.raml.v2.internal.impl.commons.model.type.TypeDeclaration.toJsonSchema(TypeDeclaration.java:270)
	... 34 more
Caused by: java.lang.ClassCastException: org.glassfish.json.JsonProviderImpl (loaded by org.codehaus.plexus.classworlds.realm.ClassRealm@0x00000001000602b0) cannot be cast to javax.json.spi.JsonProvider (loaded by org.codehaus.plexus.classworlds.realm.ClassRealm@0x00000001000602b0)
	at javax.json.spi.JsonProvider.provider(JsonProvider.java:95)
	... 37 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :raml-client-generator-example

Desktop (please complete the following information):

  • OS: Win 10

Generated code does not give access to response headers.

We have several APIs where part of the response is send as headers in the HTTP response.
The way the the generator generates the client code there is no way to get this information since it is not stored in the generated model classes nor is the javax.ws.rs.core.Response object accessible to the program calling the generated resource client.

I can see three possible solutions to this:

  1. Add a headers field into the generated module classes (in the example UserIdGETResponse) and have the resource method parse the headers and store them in the class. Downside is that there is no elegant solution for when the API returns a List (as in the /users resource in the example).
  2. Store the javax.ws.rs.core.Response in the generated model class. Same downside as above but will allow us to get more information than just the headers.
  3. Make all resource methods return a generic response object that wrapps the headers and the response object. Downside of this is that it will break API compatibility.

Before I go ahead and implement a solution I would like to know which of these, or any other, is more likely to get accepted by the project.

Here is a fork where I've added a response header to the api.raml file.
https://github.com/ullgren/raml-java-client-generator/tree/handle-response-headers

Support for RAML 1.0 spec

Hi

could you please advise whether raml-java-client-generator has support for RAML 1.0 spec ?
also when the release for 0.2 is expected ?

securedBy coming from uses is not generating user/password client

Describe the bug
Having a raml file with

uses: 
  candaCommons: exchange_modules/6b05fd51-2fe5-4078-b1a1-83d16894bf76/canda-commons/1.0.8/canda-commons.raml
securedBy: [candaCommons.basicAuth]

with canda-commons.raml

securitySchemes:
  basicAuth:
    displayName: Basic Authentication
    description: This API supports Basic Authentication. The client has to provide an "Authorization" header with valid credentials.
    type: Basic Authentication
    describedBy:
      headers:
        Authorization:
          description: Used to send valid credentials.
          type: string
      responses:
        401:
          description: Credentials are missing or could not be validated by the server.

creates an Client without authentication while

securitySchemes:
  clientid:
    type: Basic Authentication
securedBy: [clientid]

To Reproduce
Steps to reproduce the behavior:

  1. Generate from above raml
  2. See public MuletemplateClient(String baseUrl) { generated.

Expected behavior
public MuletemplateClient(java.lang.String baseUrl, java.lang.String username, java.lang.String password) {
should be generated.

Screenshots

Desktop (please complete the following information):

  • OS: Windows
  • raml-java-client-generator: 0.9

Smartphone (please complete the following information):

Additional context

Support multiple responses

The current raml-java-client-generator only maps the lowest 2xx HTTP response in the RAML file and assumes this type is valid for all 2xx responses.

The following example will create a Java client that incorrectly maps the 201 response to a TypeA instead of a TypeB class:

types:
  typeA:
    type: object
    properties:
      fieldA: string
  typeB:
    type: object
    properties:
      fieldB: integer
/test:
  get:
    responses:
      200:
        body:
          type: typeA
      201:
        body:
          type: typeB

The same is true for non-2xx responses.

The following example will throw an execption for a 401 response, but you will need to create the TypeB class and add the mapping yourself:

types:
  typeA:
    type: object
    properties:
      fieldA: string
  typeB:
    type: object
    properties:
      fieldB: integer
/test:
  get:
    responses:
      200:
        body:
          type: typeA
      401:
        body:
          type: typeB

Can support for multiple responses be added to the generator?

Tag for release 0.2 is not pushed to github

Describe the bug
Tag for release 0.2 is not pushed to github

To Reproduce
Check the Mulesoft maven release repo at https://repository.mulesoft.org/nexus/content/repositories/releases/org/mule/raml/codegen/raml-client-generator-core/ and note that 0.2 is released.

Look for the tag in the git repo:

ponu@bravo:~/raml-java-client-generator (master u=) $ git remote -v
origin	[email protected]:mulesoft-labs/raml-java-client-generator.git (fetch)
origin	[email protected]:mulesoft-labs/raml-java-client-generator.git (push)
ponu@bravo:~/raml-java-client-generator (master u=) $ git fetch --all
Fetching origin
ponu@bravo:~/raml-java-client-generator (master u=) $ git tag -l
v0.1
v0.1.1

Expected behavior
Since 0.2 is released to maven repository the tag v0.2 should exist and be pushed to github.

Screenshots
See above

Query parameter "class" generates invalid code

Describe the bug
A RAML specifying a query parameter named "class" results in the generation of a method getClass(), which is an invalid override of Object.

package com.example.test.resource.test.model;


public class TestGETQueryParam {

    private String _class_;

    public TestGETQueryParam(String class_) {
        _class_ = class_;
    }

    public void setClass(String class_) {
        _class_ = class_;
    }

    public String getClass() {
        return _class_;
    }

}
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project test: Compilation failure
[ERROR] /home/wiono/Projects/test/target/generated-sources/com/example/test/resource/test/model/TestGETQueryParam.java:[17,19] getClass() in com.example.test.resource.test.model.TestGETQueryParam cannot override getClass() in java.lang.Object
[ERROR]   overridden method is final

To Reproduce
Steps to reproduce the behavior:

Generate a client from the following RAML:

#%RAML 1.0
title: Test
mediaType: application/json
/test:
  get:
    queryParameters:
      class:
        type: array

Expected behavior
The generated client should compile.

Additional context
Add any other context about the problem here.

Maven:

Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T12:39:06-07:00)
Maven home: /home/wiono/local/apache-maven-3.5.0
Java version: 1.8.0_171, vendor: Oracle Corporation
Java home: /home/wiono/local/jdk1.8.0_171/jre
Default locale: en_CA, platform encoding: UTF-8
OS name: "linux", version: "4.9.0-11-amd64", arch: "amd64", family: "unix"

Plugin configuration:

<plugin>
	<groupId>org.mule.raml.codegen</groupId>
	<artifactId>raml-client-generator-maven-plugin</artifactId>
	<version>0.11</version>
	<configuration>
		<useJava8Dates>true</useJava8Dates>
	</configuration>
	<executions>
		<execution>
			<id>test</id>
			<phase>generate-sources</phase>
			<goals>
				<goal>generate-client</goal>
			</goals>
			<configuration>
				<basePackage>com.example.test</basePackage>
				<ramlFile>${project.basedir}/src/main/resources/schema/test/test.raml</ramlFile>
			</configuration>
		</execution>
	</executions>
</plugin>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.