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

Enums create String.java source file which is confusing #282

Closed techpavan closed 5 years ago

techpavan commented 5 years ago

I have a project where RAML defines some parameters that accept a string array whose values are confined in an enum. When code is generated for this API, it generates a class String.java which adds confusion during development.

Below is the link to reproducer. https://github.com/techpavan/springmvc-raml-plugin-issues/tree/master/1

stojsavljevic commented 5 years ago

Hi @techpavan

so you have Bus object defined like this:

type: object
properties:
  metadata:
    type: array
    items:
        enum: [ac, multi-axle, reading-light, sleeper]

why don't you define separate enum object like this:

MyEnum:
  type: string
  enum: [ac, multi-axle, reading-light, sleeper]

and use it like this in Bus declaration:

type: object
properties:
  metadata:
    type: array
    items: MyEnum

That way you'll get MyEnum.java generated.

stojsavljevic commented 5 years ago

I can set some default name in case like yours. But defining separate enum is better way forward IMHO.

stojsavljevic commented 5 years ago

DefaultEnum is default name that will be set in situations like this.

techpavan commented 5 years ago

Haven't tested it, but I sense a problem. When multiple such enums exist, I guess all of them will co-exist in the same DefaultEnum class as it is happening in String. Is it so? Any workarounds?

stojsavljevic commented 5 years ago

The fix was only regarding enum name.

Implementing this kind of check would be cumbersome and we wouldn't get much. Just define separate data types in raml and there will be no problems like this.

techpavan commented 5 years ago

Sure, will account that. Its definitely cumbersome if the plugin tries to come up with its own names, but if RAML supports some metadata (like we have displayName for methods) and plugin can take a hint using that, it would be cleaner.