Skip to content

Commit 75ebac7

Browse files
authored
Merge pull request #794 from ymohdriz/branch_v2.0.1_Fix745
Fix for issue 745 (Issue in converting server url in RFC 3986 format from OpenAPI Spec 2 to Open API Spec 3)
2 parents 82e0008 + 6d41824 commit 75ebac7

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ private List<Server> convert(List<Scheme> schemes, String host, String basePath)
414414
servers.add(server);
415415
}
416416
} else {
417+
if (!"/".equals(baseUrl)) {
418+
baseUrl = "//" + baseUrl;
419+
}
417420
Server server = new Server();
418421
server.setUrl(baseUrl);
419422
servers.add(server);

modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public class V2ConverterTest {
7979
private static final String ISSUE_673_YAML = "issue-673.yaml";
8080
private static final String ISSUE_676_JSON = "issue-676.json";
8181
private static final String ISSUE_708_YAML = "issue-708.yaml";
82+
private static final String ISSUE_745_YAML = "issue-745.yaml";
8283
private static final String ISSUE_755_YAML = "issue-755.yaml";
8384
private static final String ISSUE_740_YAML = "issue-740.yaml";
8485
private static final String ISSUE_756_JSON = "issue-756.json";
@@ -87,7 +88,6 @@ public class V2ConverterTest {
8788
private static final String ISSUE_765_YAML = "issue-765.yaml";
8889
private static final String ISSUE_768_JSON = "issue-786.json";
8990

90-
9191
private static final String API_BATCH_PATH = "/api/batch/";
9292
private static final String PETS_PATH = "/pets";
9393
private static final String PET_FIND_BY_STATUS_PATH = "/pet/findByStatus";
@@ -626,6 +626,12 @@ public void testIssue708() throws Exception {
626626
assertEquals(schema.getPattern(), "^[0-9]+$");
627627
}
628628

629+
@Test(description = "Issue in converting server url in RFC 3986 format from OpenAPI Spec 2 to Open API Spec 3")
630+
public void testIssue745() throws Exception {
631+
OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_745_YAML);
632+
assertTrue(oas.getServers().get(0).getUrl().startsWith("//"));
633+
}
634+
629635
@Test(description = "OpenAPIParser.readLocation fails when fetching valid Swagger 2.0 resource with AuthorizationValues provided")
630636
public void testIssue785() {
631637
AuthorizationValue apiKey = new AuthorizationValue("api_key", "special-key", "header");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
swagger: '2.0'
2+
info:
3+
description: 'Test'
4+
version: 1.0.0
5+
title: OpenAPI Test
6+
license:
7+
name: Apache-2.0
8+
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
9+
host: petstore.swagger.io
10+
basePath: /v2

0 commit comments

Comments
 (0)