openapi-generator
openapi-generator copied to clipboard
[BUG] openapi-generator-maven-plugin native library with async does not generate fully httpcomponents.client5 code
To work with the native library and asyncNative=true I have to use the following dependencies:
- org.apache.httpcomponents.client5:httpclient5:5.4.4
- org.apache.httpcomponents:httpmime:4.5.14
Because generating an api class gets the imports of
- import org.apache.http.HttpEntity Which comes from org.apache.httpcomponents:httpcore:4.4.16
But I expected it to come from org.apache.httpcomponents:httpcore5:5.3.4, which is part of the dependency list of the client5
The same counts for imports in the api for
import org.apache.http.NameValuePair;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
full config in mvn project pom (the input-spec is en openapi 3.1.0 schema yaml):
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.17.0</version>
<executions>
<execution>
<id>dinq-client</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<globalProperties>
<skipFormModel>false</skipFormModel>
</globalProperties>
<inputSpec>${openapi-generator.input-spec}</inputSpec>
<generatorName>java</generatorName>
<configOptions>
<library>native</library>
<packageName>dinq-maven-plugin.client</packageName>
<generateApis>true</generateApis>
<generateApiDocumentation>false</generateApiDocumentation>
<apiPackage>${openapi-generator.base-package}.api</apiPackage>
<modelPackage>${openapi-generator.base-package}.model</modelPackage>
<generateSupportingFiles>true</generateSupportingFiles>
<configHelp>false</configHelp>
<generateSourceCodeOnly>true</generateSourceCodeOnly>
<disallowAdditionalPropertiesIfNotPresent>false
</disallowAdditionalPropertiesIfNotPresent>
<generateBuilders>true</generateBuilders>
<useJakartaEe>true</useJakartaEe>
<asyncNative>true</asyncNative>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
I saw a suggestion for the javax to jakarta change ... and tried the replacer plugin with the following setting (and it works!):
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>replace-httpclient4-code</id>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<basedir>
${project.build.directory}/generated-sources/openapi/src/main/java/nl/belastingdienst/ysf/dinq/api
</basedir>
<includes>
<include>**/*.java</include>
</includes>
<regex>false</regex>
<replacements>
<replacement>
<token>org.apache.http.entity.mime</token>
<value>org.apache.hc.client5.http.entity.mime</value>
</replacement>
<replacement>
<token>org.apache.http.client.entity</token>
<value>org.apache.hc.client5.http.entity</value>
</replacement>
<replacement>
<token>org.apache.http</token>
<value>org.apache.hc.core5.http</value>
</replacement>
<replacement>
<token>entity.getContentType().getValue()</token>
<value>entity.getContentType()</value>
</replacement>
</replacements>
</configuration>
</plugin>