Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private static URL getDefaultUrl() {
public static boolean isRelativeUrl(List<Server> servers) {
if (servers != null && servers.size() > 0) {
final Server firstServer = servers.get(0);
return Pattern.matches("^(\\/[\\w\\d]+)+", firstServer.getUrl());
return Pattern.matches("^(\\/[\\w\\d.~@-]+)+", firstServer.getUrl());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,32 @@ public void testHandlesTrailingSlashInServers() {
Assert.assertEquals(servers.get(2).url, "http://notrailingslash.io:80/v2");
}

@Test
public void testHandlesRelativeUrlsWithSpecialChars() {
final Map<String, String> specToBasePath = Map.of(
"src/test/resources/3_0/relative-url-point.yaml", "/api/v4.0",
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: New test references spec files that are not present under src/test/resources/3_0, so the test will fail with file-not-found unless the resources are added or paths corrected.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultGeneratorTest.java, line 677:

<comment>New test references spec files that are not present under src/test/resources/3_0, so the test will fail with file-not-found unless the resources are added or paths corrected.</comment>

<file context>
@@ -671,6 +671,32 @@ public void testHandlesTrailingSlashInServers() {
+    @Test
+    public void testHandlesRelativeUrlsWithSpecialChars() {
+        final Map<String, String> specToBasePath = Map.of(
+          "src/test/resources/3_0/relative-url-point.yaml", "/api/v4.0",
+          "src/test/resources/3_0/relative-url-dash.yaml", "/api-v3",
+          "src/test/resources/3_0/relative-url-tilde.yaml", "/~api/v5",
</file context>
Fix with Cubic

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are not all specs, but pairs of specs and expected results for the specs.

"src/test/resources/3_0/relative-url-dash.yaml", "/api-v3",
"src/test/resources/3_0/relative-url-tilde.yaml", "/~api/v5",
"src/test/resources/3_0/relative-url-at.yaml", "/api/@6"
);

specToBasePath.forEach((spec, expectedBasePath) -> {
OpenAPI openAPI = TestUtils.parseFlattenSpec(spec);
ClientOptInput opts = new ClientOptInput();
opts.openAPI(openAPI);
DefaultCodegen config = new DefaultCodegen();
config.setStrictSpecBehavior(false);
opts.config(config);
final DefaultGenerator generator = new DefaultGenerator();
generator.opts(opts);
generator.configureGeneratorProperties();

Map<String, Object> bundle = generator.buildSupportFileBundle(new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
final String actualBasePath = (String) bundle.get("basePath");
Assert.assertEquals(actualBasePath, expectedBasePath);
});
}

@Test
public void testHandlesRelativeUrlsInServers() {
OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_10056.yaml");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
openapi: 3.0.1
info:
title: OpenAPI Petstore
description: "sample spec"
license:
name: Apache-2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.0
servers:
- url: /api/@6
tags: []
paths: {}
components:
schemas: {}
securitySchemes: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
openapi: 3.0.1
info:
title: OpenAPI Petstore
description: "sample spec"
license:
name: Apache-2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.0
servers:
- url: /api-v3
tags: []
paths: {}
components:
schemas: {}
securitySchemes: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
openapi: 3.0.1
info:
title: OpenAPI Petstore
description: "sample spec"
license:
name: Apache-2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.0
servers:
- url: /api/v4.0
tags: []
paths: {}
components:
schemas: {}
securitySchemes: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
openapi: 3.0.1
info:
title: OpenAPI Petstore
description: "sample spec"
license:
name: Apache-2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.0
servers:
- url: /~api/v5
tags: []
paths: {}
components:
schemas: {}
securitySchemes: {}
Loading