Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requests and Responses with Multiple Types with different MediaType are not supported #299

Open
techpavan opened this issue Apr 4, 2019 · 2 comments

Comments

@techpavan
Copy link

techpavan commented Apr 4, 2019

Provided below is a RAML which is valid and parsed well by other tools. But when we try to generate Java code, it fails with the exception provided at the bottom. The below method could be represented in the controller as public Single<ResponseEntity<?>> createMessage(Object object, HttpHeaders httpHeaders) where the implementer owns the responsibility on how to respond.

If the below RAML is slightly changed by removing the request body and support multiple response types, only the first one gets picked for code generation and that too is incorrect.

Please see if these could be handled better.

Reproducer: https://github.com/techpavan/springmvc-raml-plugin-issues/tree/master/2

#%RAML 1.0
title: MessageServer

types:
  Email:
    type: object
    properties:
      subject: string
      body: string
  Sms:
    type: object
    properties:
      content: string

/messages:
  post:
    body:
      application/json:
        type: Email
      applicationV2/json:
        type: Sms
    responses:
      200:
        body:
          application/json:
            type: Email
          applicationV2/json:
            type: Sms

Exception thrown:

Caused by: java.lang.IllegalStateException: Body Metadata is immutable
    at com.phoenixnap.oss.ramlplugin.raml2code.data.ApiActionMetadata.setRequestBody (ApiActionMetadata.java:350)
    at com.phoenixnap.oss.ramlplugin.raml2code.data.ApiActionMetadata.collectBodyParams (ApiActionMetadata.java:173)
    at com.phoenixnap.oss.ramlplugin.raml2code.data.ApiActionMetadata.parseRequest (ApiActionMetadata.java:134)
    at com.phoenixnap.oss.ramlplugin.raml2code.data.ApiActionMetadata.<init> (ApiActionMetadata.java:77)
    at com.phoenixnap.oss.ramlplugin.raml2code.data.ApiResourceMetadata.addApiCall (ApiResourceMetadata.java:55)
    at com.phoenixnap.oss.ramlplugin.raml2code.helpers.RamlParser.checkResource (RamlParser.java:167)
    at com.phoenixnap.oss.ramlplugin.raml2code.helpers.RamlParser.extractControllers (RamlParser.java:77)
    at com.phoenixnap.oss.ramlplugin.raml2code.plugin.SpringMvcEndpointGeneratorMojo.generateEndpoints (SpringMvcEndpointGeneratorMojo.java:284)
    at com.phoenixnap.oss.ramlplugin.raml2code.plugin.SpringMvcEndpointGeneratorMojo.execute (SpringMvcEndpointGeneratorMojo.java:527)
@stojsavljevic
Copy link
Contributor

Yeah, multiple request's media types are not supported. That's why I'm marking this as an enhancement.

Unfortunately, supporting this is not going to be very easy. We should be generating one method for every media type of request. In your example, we should generate a method that receives Email and another for Sms. This should be done for all rules.

Can you please consider a PR?

@techpavan
Copy link
Author

Not sure if I can find time to take a deep dive and come up with PR in my current occupancy. But do share some hints on classes and methods that are closely involved and I can try to see if I could attempt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants