Openapi-generator: [REQ] How to adjust the file name of a generated java class?

Created on 10 May 2019  路  3Comments  路  Source: OpenAPITools/openapi-generator

I played around with creating by own custom template for Java Resttemplate. This works quite nice!

My aim is to alter the class name of the generated API classes. I did so by changing api.mustache:

...
public class {{classVarName}} {
  private ApiClient apiClient;
...

I replaced {{className}} by {{classVarName}} and the output is as expected.

However, Java requires that the class name and the file name are the same.

It appears that the generated Java file name is built with the variable {{className}}.

Suppose my API is named My Service, then the file would be named MyServiceApi.java, and the code would be public class MyService.

How can I alter the file name of the Java class?

Feature Question

Most helpful comment

Well I noticed that the filename consists of the tag plus Api. I would prefer that Api is omitted. I am afraid this is currently not possible.

All 3 comments

Given that the class name is based on the tag, What about renaming the tag in your spec instead?

Well I noticed that the filename consists of the tag plus Api. I would prefer that Api is omitted. I am afraid this is currently not possible.

You can customize the Java client generator to name it in whatever way you want.

PM me via Slack if you need help on that.

Was this page helpful?
0 / 5 - 0 ratings