Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenApi Generator: Use Long as Numeric default?

We are using openapi-generator's openapi-generator-maven-plugin to automate an integration with a swagger which uses Numeric datatypes that are not int64. Our codebase tries to standardize around using Long values, but openapi generates artifacts which use int. Is it possible to configure the plugin to generate POJOs which use Long instead of Integer?

We could modify the swagger definition to specify the int64 format but prefer to do this via configuration outside of the swagger.

like image 723
IcedDante Avatar asked Mar 21 '26 01:03

IcedDante


2 Answers

Use the format keyword to specify int64.

example:
  type: integer
  format: int64
like image 158
Software2 Avatar answered Mar 23 '26 13:03

Software2


I used the typeMappings parameter for this. Using a maven plugin configuration it looks like this:

<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.1.0</version>
<configuration>
    <typeMappings>integer=Long,int=Long</typeMappings>
</configuration>
<executions>
    <execution>
    ...
    </execution>
</executions>
</plugin>

Note that this configuration, as of this writing, does not work inside of the execution as it did with swagger-codegen. the typemappings parameter can also be used when calling the openapi-generator directly

like image 22
IcedDante Avatar answered Mar 23 '26 13:03

IcedDante



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!