Skip to content

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

Description

@techpavan

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions