[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][JAVA] Invalid code generated: non-existent ApiClient is referred in toUrlQueryString #19142

Open
4 of 6 tasks
sephiroth-j opened this issue Jul 11, 2024 · 0 comments
Open
4 of 6 tasks

Comments

@sephiroth-j
Copy link
sephiroth-j commented Jul 11, 2024

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

After upgrading from v7.6.0 to v7.7.0, we have noticed that the generated code is invalid.

  • The generated model class has an import of a class ApiClient which is not generated.
  • The generated model class has a function toUrlQueryString(String) that uses a static function valueToString from the class ApiClient which is not generated.
    The old code was
joiner.add(String.format("%sfoo%s=%s", prefix, suffix, URLEncoder.encode(String.valueOf(getFoo()), StandardCharsets.UTF_8).replaceAll("\\+", "%20")));

The new code is

joiner.add(String.format("%sfoo%s=%s", prefix, suffix, URLEncoder.encode(ApiClient.valueToString(getFoo()), StandardCharsets.UTF_8).replaceAll("\\+", "%20")));
openapi-generator version

7.7.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Example API v1
  description: A reference API
  contact: {}
  version: 2.0.0
paths:
  /demo:
    get:
      responses:
        '200':
          description: Test
          content:
            'application/json':
              schema:
                type: object
                properties:
                  foo:
                    type: string
Generation Details

language: java
library: native

				<groupId>org.openapitools</groupId>
				<artifactId>openapi-generator-maven-plugin</artifactId>
				<version>7.7.0</version>
				<configuration>
					<generatorName>java</generatorName>
					<skipValidateSpec>false</skipValidateSpec>
					<generateApis>false</generateApis>
					<generateSupportingFiles>false</generateSupportingFiles>
					<generateModelTests>false</generateModelTests>
					<generateModelDocumentation>false</generateModelDocumentation>
					<generateApiTests>false</generateApiTests>
					<generateApiDocumentation>false</generateApiDocumentation>
					<output>${project.build.directory}/generated-sources</output>
					<configOptions>
						<sourceFolder>openapi</sourceFolder>
						<useJakartaEe>true</useJakartaEe>
						<withXml>true</withXml>
						<serializationLibrary>jackson</serializationLibrary>
						<library>native</library>
						<dateLibrary>java8</dateLibrary>
						<disallowAdditionalPropertiesIfNotPresent>false</disallowAdditionalPropertiesIfNotPresent>
					</configOptions>
				</configuration>
				<executions>
					<execution>
						<id>demo</id>
						<goals>
							<goal>generate</goal>
						</goals>
						<phase>generate-sources</phase>
						<configuration>
							<inputSpec>src/main/openapi/demo.yaml</inputSpec>
							<configOptions>
								<modelPackage>de.demo</modelPackage>
							</configOptions>
						</configuration>
					</execution>
				</executions>
Steps to reproduce
  1. save the file above as src/main/openapi/demo.yaml
  2. add the above plugin configuration to a maven pom
  3. run mvn generate-sources
  4. check target/generated-sources/openapi/de/demo/DemoGet200Response.java
Related issues/PRs

seems to be a regression from #18743
https://github.com/OpenAPITools/openapi-generator/pull/18743/files#diff-2eefc7a98c8e6aff3fa4589d8f2c364e7214c35e98806786e8dae207c42352df

Workaround

Set supportUrlQuery to false when toUrlQueryString is not needed.

@sephiroth-j sephiroth-j changed the title [BUG][JAVA] Invalid code generated: ApiClient is referred but not present [BUG][JAVA] Invalid code generated: non-existend ApiClient is referred in toUrlQueryString Jul 11, 2024
@sephiroth-j sephiroth-j changed the title [BUG][JAVA] Invalid code generated: non-existend ApiClient is referred in toUrlQueryString [BUG][JAVA] Invalid code generated: non-existent ApiClient is referred in toUrlQueryString Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant