Search code examples
javaopenapi-generator

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.


Solution

  • 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