Openapi-generator: [Spring] Generated controllers ignore basePath

Created on 16 Jan 2019  路  7Comments  路  Source: OpenAPITools/openapi-generator

I have the following line in the openapi file:

basePath: "/v1"

I would expect generated controllers (interfaces) would use this basePath as prefix for all the paths, but they don't contain this "v1" and just use resource path:

@RequestMapping(value = "/abc", method = RequestMethod.GET)

I'm using latest stable release 3.3.4.

Bug

Most helpful comment

Hello,
This topic was fixed in swagger-codegen following this issue : 5244.
If everybody agrees with the solution, could this be backported here too ?
thank you.

All 7 comments

you can manually add the base path to your application.yml:

server:
  servlet:
    context-path: /v1

That sets the prefix globally for all controllers, even those not from this openapi file (health checks etc.) which is not what would be expected.

You might also want to expose multiple versions of the same API on the same service.

@zadam you are right, it should be fixed in the generator. my comment is just a workaround

Hello,
This topic was fixed in swagger-codegen following this issue : 5244.
If everybody agrees with the solution, could this be backported here too ?
thank you.

I've just noticed that the problem only occurs if interfaceOnly is set to true : the basePath is not present on the generated interface. If interfaceOnly is set to false, the Controller class has got the @RequestMapping annotation.
I guess the fix is only about where is generated the basePath @RequestMapping annotation : it should always be on the interface, shouldn't it ?

apiController.mustache : @RequestMapping("${openapi.<%title%>.base-path:<%>defaultBasePath%>}")
--> this should be in api.mustache only.

@macjohnny If I was to work on a PR for this fix, which branch should I create ? It's not completely clear to me. Would you mind creating it for me ?

simply fork the repository, create a branch with a name you like, and then file a PR against the master branch of https://github.com/OpenAPITools/openapi-generator

Was this page helpful?
0 / 5 - 0 ratings