mulesoft-labs / raml-for-jax-rs

This project is all about two way transformation of JAX-RS-annotated Java code to RAML API description and back.
Other
295 stars 181 forks source link

raml-to-jax-rs-cli: Problem with generated entity interfaces. #299

Open JoseHdez2 opened 7 years ago

JoseHdez2 commented 7 years ago

Problem

I'm generating a model and its API methods using raml-to-jaxrs, more specifically raml-for-jaxrs-cli 2.1.0.

My model has two generated classes, Product being an interface and ProductImpl its implementing class.


An example, with one of the API endpoint methods:

@Override
public PutProductsResponse putProducts(String xSessionToken, Product entity) {

If I change it to:

@Override
public PutProductsResponse putProducts(String xSessionToken, ProductImpl entity) {

I've Tried


In-depth

I'm using jersey 2.11 and tyrus-container-grizzly-server 1.13 as Maven dependencies.

The error that is returned from the request is:

InboundJaxrsResponse{ClientResponse{method=POST, uri=http://localhost:9998/products, status=500, reason=Request failed.}}

(StackOverflow question)

jpbelang commented 7 years ago

Are you using jackson ? Can you show me your command line ?

Try adding -g jackson.

JoseHdez2 commented 7 years ago

Hello @jpbelang, thank you and sorry for the late follow-up; I was working with a temporary solution (deleting the interfaces and working with just the entities) and forgot to check for replies.

I've been using the latest raml-to-jaxrs-cli, version 2.1.0. I run the JAR executable in the CLI and give the parameters. Using npm install -g jackson shows me I have jackson@0.1.4 installed.

jstoiko commented 7 years ago

can you share the full command used to run the CLI?

JoseHdez2 commented 7 years ago

@jstoiko I am using a bash script I made, which really just runs the JAR:

#!/bin/sh
jar_path="/home/user/Documents/raml-for-jax-rs/raml-to-jaxrs/raml-to-jaxrs-cli/target/raml-to-jaxrs-cli-2.1.0-jar-with-dependencies.jar"
api_dir="/home/user/Documents/project/submodule/src/main/java/"
raml_path="/home/user/Documents/project/submodule/src/main/resources/my_raml.raml"
model_pkg="com.project.model"
resource_pkg="com.project.resource"
support_pkg="com.project.support"

cmd="java -jar $jar_path -d $api_dir -m $model_pkg -r $resource_pkg -s $support_pkg $raml_path"
echo $cmd
eval $cmd

The files are generated just fine; my initial problem is when using the generated code for PUTting or POSTing an entity. I hope this helps.

jpbelang commented 7 years ago

Your script is short the -g jackson option. You are only generating the classes and not the jackson annotations.

I swear I'll make that annotation mandatory. :-) (I think you are the third person in the last two weeks that has had that problem.

JoseHdez2 commented 7 years ago

Thank you very much @jpbelang! Haven't been able to un-scramble the implementation code I had written, but I follow up on Monday to hopefully inform you that it works :+1:

JoseHdez2 commented 6 years ago

Hello, I haven't closed this issue because I still have a problem with the generated classes and the model interfaces (ex. Product) not being mapped to their corresponding implementation class (ex. ProductImpl) in the resources.

I set the -g jackson flag, and now see the @JsonDeserialize Java annotation (and others) is being generated in the model interfaces. My problem now is that some of the model interfaces don't have this annotation.

I thought that it might be faulty difference checking in the generator, but I deleted all the generated model classes and regenerated, and again some were missing the annotation.

I don't know what might be the cause of this, but if I find a common characteristic of the faulty interfaces I'll let you know.

Maybe this is unrelated, but the ResponseDelegate.java has changes even though I haven't made more changes in the resource types or traits, just the resources and types.

jairamrb commented 6 years ago

Hi, I have the same problem generating the model interfaces. All endpoints which use entities without @JsonDeserialize Java annotation are inaccessible.

Any idea?

Thx. Regards.

jpbelang commented 6 years ago

@JoseHdez2 If you could send me and Example, that would be helpful.

@jairamrb inaccessible ? I don't understand.

JoseHdez2 commented 6 years ago

@jpbelang For example, I have in my RAML the types Model1, Model2, Model3, etc. When I generate them (into the model package), they are generated as Java interfaces with corresponding implementation classes (Model1Impl, Model2Impl, Model3Impl, ...).

Most of these interfaces do have the @JsonDeserialize annotation, pointing to their corresponding implementation:

@JsonDeserialize(
    as = com.example.ModelXImpl.class
)
public interface ModelX {
// ...
}

while some are generated (repeatedly) with nothing:

// There should be an annotation here, but nothing is generated.
public interface ModelY {
// ...
}

Right now I don't know why this happens, but it is probably why my problem still exists after applying the -g jackson flag to the generator.

Also, all of the implementation classes have @JsonInclude(JsonInclude.Include.NON_NULL) and @JsonPropertyOrder({/* ... */}) annotations, there is nothing wrong with them.

jairamrb commented 6 years ago

Excuse me @jpbelang, I did not express myself well. When I try to call a POST method, a 500 error is generated. However, if I change the arguments of the methods from interface to implementation, it works correctly.

jpbelang commented 6 years ago

Ah. Ok @JoseHdez2 . Can you give me a class diagram ? I'll build an example with that.

@jairamrb this might relate to your problem. If the @JsonDeserialize is not on an interface, jackson can't figure out what the class to actually implement is.

igc23 commented 6 years ago

Hello @jpbelang, I'm a colleague of @JoseHdez2, we still have the same problem, working for fixing it but not lucky. I'll give u a specific example, hope u can help:

export.tar.gz

If u need some more information just tell us, we will be checking the post. Thank you so much.

jstoiko commented 6 years ago

Using npm install -g jackson shows me I have jackson@0.1.4 installed.

That doesn't sound right. This is a nodeJS package... I believe @jpbelang was referring to Java's Jackson Project.

@igc23: do you have a RAML file to share?

igc23 commented 6 years ago

Hello @jstoiko, it's attached to my previous comment. I can't share the full and real file because it's business logic of the company, but the important thing is what is already attached. Anything else u need, just tell us. Thank you!

igc23 commented 6 years ago

Hello @jstoiko and @jpbelang,

Is there any way to generate the architecture based on the raml file (version 1.0) without including the interfaces? I am referring to the interfaces of the data model, as it happened in version 0.8.

We currently use the following Jackson version:

com.fasterxml.jackson.core jackson-databind 2.5.4 although I have been testing with version 2.9.2 and we did not get results either. I understand that the problem should not be in Jackson, nor in Java, it is more of a logic problem as I see it. Let me explain: in the example I have gone through, if instead of implementing, I extend, everything works correctly, but it breaks the architectural scheme we have. So the solution is to generate everything the same without the interfaces (we use them because they are being generated automatically) or by using Jackson in some other way / version, maybe there is some annotation that I have not proven that solves the problem. We will continue working to solve it and reviewing the post daily. Thank you very much to both of you.
slawekh263 commented 5 years ago

Hi @jpbelang, Do you know, more or less, when 3.0.5 is planned to be released? Or at least when the code is available in the branch? It would be very nice to have this no-interface generation. thanks!

jpbelang commented 5 years ago

3.0.5 should be released this week, but I haven't had time to get to no interfaces (the problem is with plugins). It's the next one....