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

Controller name selection direction #217

Open yuranos opened 6 years ago

yuranos commented 6 years ago

At the moment, the very last segment inside the root path is taken as a basis for controller name: RAML:

/errors/{errorId}:
  get:
    description: Get all supported errors
    responses:
      200:
        body:
           application/json:
             type: ErrorInfo[]

would generate controller named: ErrorIdController(it was actually errorIdController, just a couple of days ago before #215 fix). While it's not critical and can easily be circumvented with:

/errors:
  /{errorId};

wouldn't it be nice to be able to set a flag inside a plugin that will use a reverse traversal for Controller naming? What do you think, guys?

stojsavljevic commented 6 years ago

Just to make something clear:

/errors/{errorId}:

produces ErrorIdErrorController while

/errors:
    /{errorId}:

produces ErrorController. Am I correct @yuranos?

Bear in mind that path variable influences this behavior since for:

/abc:
  /efg:

and

/abc/efg: 

it's always the same - EfgAbcController.

So I'm not sure what kind of 'reverse traversal' you have in mind. There is already reverseOrderInClassNames config option which can control the way controller names are generated. With <reverseOrderInClassNames>false</reverseOrderInClassNames> you'll get AbcEfgController instead.

yuranos commented 6 years ago

@stojsavljevic , are you talking about RAML 1.0? I have just tried reverseOrderInClassNames option for both:

/errors:
  /mycontroller:
    post:
       description: Checks and adds booking to customer
       queryParameters:
            siteKey : SiteKey
       body:
           application/json:
              type: AddBookingRequest
       responses:
            201:
              body:
                application/json:
                  type: BookingDetailsDto

and

/errors/mycontroller:
    post:
       description: Checks and adds booking to customer
       queryParameters:
            siteKey : SiteKey
       body:
           application/json:
              type: AddBookingRequest
       responses:
            201:
              body:
                application/json:
                  type: BookingDetailsDto

and the resulting name is always the same: MycontrollerController

To be honest, I was not aware of that option, but it seems not to work as expected, or my expectation is different to the designed one. I also haven't seen anything like EfgAbcController. As you can see in my example, class name always contains only one segment. What are we doing differently?

stojsavljevic commented 6 years ago

Sorry I didn't explain it well.

So there are 2 config options:

I was using resourceDepthInClassNames=2 and reverseOrderInClassNames=true in my abc/efg example. Sorry for the confusion.

To get back to your original question - we can consider ErrorIdController name a bug. It should be ErrorController like with:

/errors:
  /{errorId}