OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.67k stars 6.54k forks source link

[BUG] openapi-generator mvn plugin - typeMappings does not appear to take hold in individual executions #11026

Open randeepbydesign opened 2 years ago

randeepbydesign commented 2 years ago

Bug Report Checklist

Description

We use the maven plugin to generate our artefacts. I was setting up type mappings in my executions so that int32 types were mapped to long instead of Integer:

    <execution>
      <id>myserver-me-api</id>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <inputSpec>${project.basedir}/src/main/resources/myserver-me-api.json</inputSpec>
        <generateApiTests>false</generateApiTests>
        <generateModelTests>false</generateModelTests>
        <generatorName>java</generatorName>
        <configOptions>
          <sourceFolder>com/myserver/api</sourceFolder>
          <apiPackage>client.myserver</apiPackage>
          <modelPackage>client.myserver.model</modelPackage>
          <invokerPackage>client.myserver.handler</invokerPackage>
          <library>resttemplate</library>
          <java8>true</java8>
          <importMappings>integer=Long</importMappings>
          <typeMappings>integer=Long,int=Long</typeMappings>
          <dateLibrary>java8-localdatetime</dateLibrary>
          <serializableModel>true</serializableModel>
        </configOptions>
      </configuration>
    </execution>

However it had no effect and my generated POJO still used Integer here. However, defining typeMappings in the plugin section did work:

  <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>
        ...

Is this a feature-not-a-bug kind of thing or are we supposed to be able to configure the individual executions this way? The openapi-generator-maven-plugin markdown document is not very clear on the distinction so I am unsure.

openapi-generator version

Using 5.1.0 of openapi-generator-maven-plugin

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.1.0</version>
<configuration>
    <typeMappings>integer=Long,int=Long</typeMappings> <!-- this works -->
</configuration>
<executions>
    <execution>
    <id>myapp-me-api</id>
    <goals>
        <goal>generate</goal>
    </goals>
    <configuration>
        <inputSpec>${project.basedir}/src/main/resources/myapp-me-api.json</inputSpec>
        <generateApiTests>false</generateApiTests>
        <generateModelTests>false</generateModelTests>
        <generatorName>java</generatorName>
        <configOptions>
        <sourceFolder>com/myapp/api</sourceFolder>
        <apiPackage>client.myapp</apiPackage>
        <modelPackage>client.myapp.model</modelPackage>
        <invokerPackage>client.myapp.handler</invokerPackage>
        <library>resttemplate</library>
        <java8>true</java8>
        <typeMappings>integer=Long,int=Long</typeMappings> <!-- this don't -->
        <dateLibrary>java8-localdatetime</dateLibrary>
        <serializableModel>true</serializableModel>
        </configOptions>
    </configuration>
    </execution>
</executions>
</plugin>
</plugins>
</build>
Related issues/PRs
Suggest a fix
borsch commented 2 years ago

@randeepbydesign try to use

<importMappings>
  <importMapping>integer=Long</importMapping>
</importMappings>

This works for me on plugin level. Haven't checked on execution level, but who knows :)

randeepbydesign commented 2 years ago

Yes- if you look at my description I confirm that it works at plugin level but not at execution level.

randeepbydesign commented 2 years ago

Ah I see what you were doing. Yes, a specific importMapping does not work at the execution level either

zeekoe commented 2 years ago

Wow, thanks for posting this. I also expected this in the configOptions, it took me nearly an hour to find this. Perhaps the documentation here can be extended with an example where to put the typeMappings (and the fact that importMappings does not work anymore)?