I'm writing a spec for spring-boot app to generate an API for clients using openapi-generator-maven-plugin. There are a few models which I wanted to import so I tried to import them as usual, using schemaMappings property, just in the same way as I did with openapi-generator-gradle-plugin. In yaml spec, I created empty schemas of the models I wanted to import and specified desired types in plugin settings in the pom.xml. My plugins settings:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.4.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi/some-api.yaml</inputSpec>
<generatorName>spring</generatorName>
<output>${project.build.directory}/generated-sources/openapi</output>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateModelTests>false</generateModelTests>
<generateModelDocumentation>false</generateModelDocumentation>
<importMappings>
<importMapping>MyDto1=com.some.project.metric.MyDto1</importMapping>
<importMapping>MyDto2=com.some.project.metric.MyDto2</importMapping>
</importMappings>
<configOptions>
<title>Some project</title>
<library>spring-boot</library>
<useTags>true</useTags>
<dateLibrary>java8</dateLibrary>
<basePackage>${default.package}</basePackage>
<apiPackage>${default.package}.api</apiPackage>
<modelPackage>${default.package}.model</modelPackage>
<performBeanValidation>true</performBeanValidation>
<interfaceOnly>true</interfaceOnly>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
But suddenly I found that for some reason the openapi-generator-maven-plugin, unlike openapi-generator-gradle-plugin, doesn't use the importMappings property. It's present in the code of the plugin and you can use it either in the configuration or in configOptions of a generator, but eventually, it doesn't work with my own DTOs. Checked one more time. In Gradle, everything worked fine, but not in Maven. It didn't generate the POJOs because they are free-form objects and simply substituted them with the Object type. I started digging into the problem and after some time I saw that the problem exists for a long time. At least from version 5.3.1. You can see here
I've spent on this issue a lot of time so maybe it will be useful to post it here. The solution is to use schemaMappings instead of importMappings. Like that:
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi/some-api.yaml</inputSpec>
<generatorName>spring</generatorName>
<output>${project.build.directory}/generated-sources/openapi</output>
<schemaMappings>MyDto1=com.some.project.metric.MyDto1,MyDto2=com.some.project.metric.MyDto2</schemaMappings>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateModelTests>false</generateModelTests>
<generateModelDocumentation>false</generateModelDocumentation>
<configOptions>
<title>Some project</title>
<library>spring-boot</library>
<useTags>true</useTags>
<dateLibrary>java8</dateLibrary>
<basePackage>${default.package}</basePackage>
<apiPackage>${default.package}.api</apiPackage>
<modelPackage>${default.package}.model</modelPackage>
<performBeanValidation>true</performBeanValidation>
<interfaceOnly>true</interfaceOnly>
</configOptions>
</configuration>
Will be glad if you also provide your suggestions.