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.79k stars 6.58k forks source link

[BUG] Version 7.7.0: Generating java.net.URLEncoder.encode(String, String) instead of the preferable one java.net.URLEncoder.encode(String, Charset) #19370

Open iamuddalak opened 2 months ago

iamuddalak commented 2 months ago
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: 358629247-3dab7a4e-761d-4a7c-8ee2-a2471502bf8a~2

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: 358629247-3dab7a4e-761d-4a7c-8ee2-a2471502bf8a~2

.zip file of the project is also included as attachment.

open-api-demo.zip

Suggest a fix
  1. Generate the code with corresponding active method signature. i.e. java.net.URLEncoder.encode(String, Charset) for java 11.
iamuddalak commented 2 months ago

This may not submitted as bug. This should be a Change Request. I am not able to change the tag now.