phoenixnap / springmvc-raml-plugin

Spring MVC - RAML Spec Synchroniser Plugin. A Maven plugin designed to Generate Server & Client code in Spring from a RAML API descriptor and conversely, a RAML API document from the SpringMVC Server implementation.
Apache License 2.0
136 stars 84 forks source link

Type inheritance is broken for array types #285

Open tburny opened 5 years ago

tburny commented 5 years ago

Given the following RAML where Bar extends Foo and an endpoint that returns a Bar array:

#%RAML 1.0
---
title: e-BookMobile API
baseUri: http://example.com/{version}
version: v1

types:
    Foo:
        type: object
    Bar:
        type: Foo

/bar:
  get:
    responses:
      200:
        body:
          application/json:
            type: array
            items: Bar

Expected result

class Bar extends Foo in the generated Java code:

public class Bar
    extends Foo
    implements Serializable
{ 

Actual result

Bar does not extend Foo, as seen here:

public class Bar implements Serializable
{

(the extends Foo is missing). The cause is probably because the return type is array (so Bar is not referenced directly) and the generic type in items is Bar: However note that both Foo and Bar are still generated:

tobias@hattutsch gen/wow » ls -R
.:
BarController.java  model

./model:
Bar.java  Foo.java

When changing the endpoint to use square brackets

/bar:
  get:
    responses:
      200:
        body:
          application/json:
            type: Bar[]

the Bar model is generated correctly

public class Bar
    extends Foo
    implements Serializable
{
stojsavljevic commented 5 years ago

Hi,

thanks for reporting the issue. However, it seems that problem is in raml-parser-2. I reported the issue using your test case: https://github.com/raml-org/raml-java-parser/issues/552