OpenApi Generator: Use Long as Numeric default?
Asked Answered
D

2

8

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.

Debbydebee answered 3/3, 2021 at 17:36 Comment(0)
D
2

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

Debbydebee answered 3/12, 2021 at 14:40 Comment(0)
A
19

Use the format keyword to specify int64.

example:
  type: integer
  format: int64
Aparejo answered 3/3, 2021 at 18:19 Comment(2)
As I stated, the data type is not int64. As I failed to mention, we prefer not to modify the swagger definition for various reasons. I'll clarify the question to mention this.Debbydebee
Long varibale_name;Sparke
D
2

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

Debbydebee answered 3/12, 2021 at 14:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.