OpenAPITools / OpenAPITools/openapi-generator

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

Open
#11,026 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the openapi-generator-maven-plugin configuration and its handling of plugin-level versus execution-level parameters. Reproduce the Maven build using the provided execution configuration and compare the generated Java POJO when typeMappings is placed in each location. Done means the supported configuration behavior is clear and the execution-level mapping either takes effect or is documented as unsupported.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.