mulesoft-labs / raml-java-client-generator

Raml Java Client Generator
Apache License 2.0
34 stars 34 forks source link

Generated code does not give access to response headers. #21

Closed ullgren closed 6 years ago

ullgren commented 6 years ago

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

machaval commented 6 years ago

Hi, Thanks for the raising this issue. I would say number 3, the only problem is that we will break any existing client already generated as this is an api breaking change. So we should think if it worth adding a property to work as is used to, new behaviour should be by default but allow people to turn it off and log saying it is the deprecated mode and it will be deleted in next version.

What do you think? Do you need any help?

ullgren commented 6 years ago

Sounds like a good compromise.

I've started looking at it but since it is the first time diving into codemodel it might take some time for me so if anybody has the time to complete it before I will not object :-)

ullgren commented 6 years ago

This initial attempt should not be seen as a final solution just a proof of concept for now.