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
296 stars 181 forks source link

Set Access-Control-Allow-Origin in Raml API #420

Open elhamroshan opened 4 years ago

elhamroshan commented 4 years ago

I'm trying to set Access-Control-Allow-Origin in my Raml API. Found in the web that I can do that by adding headers to my responses like:

    responses:
      200:
        headers:
          Access-Control-Allow-Origin:
            example: |
              *
          Access-Control-Allow-Methods:
            example: |
              GET, POST
          Access-Control-Allow-Headers:
            example: |
              Content-Type

I've done this but it fails compiling the code with the following error:

 method respond200WithApplicationJson in class GetApiV1ProjectsResponse cannot be applied to given types;
[ERROR]   required: ApiV1Projects.GetApiV1ProjectsResponse.HeadersFor200
[ERROR]   found: java.lang.String
[ERROR]   reason: actual and formal argument lists differ in length

Current java code when returning the response:

return GetApiV1ProjectsResponse.respond200WithApplicationJson(projectsToJson(restResponse));

Should I add any changes to my response implementation? What is missing here?

Thanks in advance!

jpbelang commented 4 years ago

I've been busy elsewhere, sorry for the delay. I'll check this tomorrow morning. Promise.

jpbelang commented 4 years ago

There is an example in the project of using headers: raml-to-jaxrs/examples/maven-examples/raml-defined-example/src/main/java/server/humanity/HumanityImpl.java

But if you could give me a mode complete example maybe I could see what is wrong ?