OpenAPITools / OpenAPITools/openapi-generator
[BUG] Version 7.7.0: Generating java.net.URLEncoder.encode(String, String) instead of the preferable one java.net.URLEncoder.encode(String, Charset)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Version 7.7.0:
Generating java.net.URLEncoder.encode(String, String) instead of the preferable one java.net.URLEncoder.encode(String, Charset)
Problem is when I am using org.gaul:modernizer-maven-plugin:2.7.0:modernizer (modernizer) on project it is forcing the build to fail as the generated code is not using the most preferable method signature i.e. java.net.URLEncoder.encode(String, Charset)
spring-boot-starter-parent version : 2.7.7
java version : 11
openapi-generator-maven-plugin version : 7.7.0
openapi-generator-maven-plugin version : 2.7.0
generatorName : java using with "resttemplate" library.
Error:
openapi-generator version
7.7.0
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: Sample API
description: A simple API example
version: 1.0.0
paths:
/greet:
get:
summary: Greet the user
parameters:
- name: name
in: query
required: true
schema:
type: string
responses:
'200':
description: A greeting message
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: Hello, World!
Generation Details
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.7.0</version>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<configuration>
<inputSpec>
${project.basedir}/src/main/resources/api-spec.yaml</inputSpec>
<generatorName>java</generatorName>
<output>
${project.build.directory}/generated-sources/openapi</output>
<apiPackage>com.ukb.openapi.demo.api</apiPackage>
<modelPackage>com.ukb.openapi.demo.model</modelPackage>
<invokerPackage>com.ukb.openapi.demo.invoker</invokerPackage>
<groupId>com.ukb.openapi.demo</groupId>
<artifactId>open-api-demo</artifactId>
<artifactVersion>1.0.0</artifactVersion>
<configOptions>
<dateLibrary>java8</dateLibrary>
<library>resttemplate</library>
<withXml>false</withXml>
<sourceDirectory>
${project.build.directory}/generated-sources/openapi/src/main/java</sourceDirectory>
</configOptions>
</configuration>
</plugin>
<plugin>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-plugin</artifactId>
<version>2.7.0</version>
<configuration>
<javaVersion>11</javaVersion>
</configuration>
<executions>
<execution>
<id>modernizer</id>
<phase>verify</phase>
<goals>
<goal>modernizer</goal>
</goals>
</execution>
</executions>
</plugin>
Steps to reproduce
Prepare a simple springboot project using the pom.xml and api-spec.yaml and run
mvn clean install
Error:
.zip file of the project is also included as attachment.
Suggest a fix
- Generate the code with corresponding active method signature. i.e. java.net.URLEncoder.encode(String, Charset) for java 11.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the pom.xml and api-spec.yaml from the reproduction project, then run mvn clean install to inspect the generated Java client and the modernizer failure. Trace the generated URL-encoding call and verify that the output uses java.net.URLEncoder.encode(String, Charset) for Java 11 and passes the modernizer check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100