Bugfix for remote specs with params (#21634)

* [Bugfix][Maven-Plugin] Bugfix for remote input specs with parameters

If the inputSpec was a web address that contained parameters, code generation would fail, because the filepath would contain illegal characters, since the code inside the if-block would be skipped. A side effect of this was, that in the log and in the filename in linux the parameters would be leaked, which could potentially sensitive information like Gitlab Access Tokens

* [Test][Gradle Plugin] Update GenerateTaskDslTest.kt

Extended the Test for testing remote inputSpecs with urlParams, a case that caused problems in the maven plugin.
This commit is contained in:
Tobias Guttenberger 2025-07-28 10:40:20 +02:00 committed by GitHub
parent edbacaa3c7
commit 1c2ef3356d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 2 deletions

View File

@ -34,6 +34,7 @@ class GenerateTaskDslTest : TestBase() {
@Test
fun `openApiGenerate should create an expected file structure from URL config`() {
val specUrl = "https://raw.githubusercontent.com/OpenAPITools/openapi-generator/b6b8c0db872fb4a418ae496e89c7e656e14be165/modules/openapi-generator-gradle-plugin/src/test/resources/specs/petstore-v3.0.yaml"
val urlParams ="?meaningless=params&so=it&results=in&illegal=filenames&on=windows"
// Arrange
val buildContents = """
plugins {
@ -41,7 +42,7 @@ class GenerateTaskDslTest : TestBase() {
}
openApiGenerate {
generatorName = "kotlin"
remoteInputSpec = "$specUrl"
remoteInputSpec = "$specUrl$urlParams"
outputDir = file("build/kotlin").absolutePath
apiPackage = "org.openapitools.example.api"
invokerPackage = "org.openapitools.example.invoker"

View File

@ -1066,7 +1066,7 @@ public class CodeGenMojo extends AbstractMojo {
String name = inputSpecFile.getName();
URL url = inputSpecRemoteUrl();
if (inputSpecFile.exists() && url != null) {
if (url != null) {
String[] segments = url.getPath().split("/");
name = Files.getNameWithoutExtension(segments[segments.length - 1]);
}

View File

@ -68,6 +68,10 @@ public class CodeGenMojoTest extends BaseTestCase {
testCommonConfiguration("jar");
}
public void testCommonConfigurationWithRemoteInputSpec() throws Exception {
testCommonConfiguration("remote");
}
@SuppressWarnings("unchecked")
private void testCommonConfiguration(String profile) throws Exception {
CodeGenMojo mojo = loadMojo(newTempFolder(), "src/test/resources/default", profile);

View File

@ -55,6 +55,12 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>remote</id>
<properties>
<inputSpec>https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml?meaningless=params&amp;so=it&amp;results=in&amp;illegal=filenames&amp;on=windows</inputSpec>
</properties>
</profile>
</profiles>
<build>
<finalName>common-maven</finalName>