Skip to content

Commit

Permalink
Merge pull request #97 from christophd/issue/95/support-openapi-v3
Browse files Browse the repository at this point in the history
fix(#95): Fix base path handling to avoid duplicate "/" in server URL
  • Loading branch information
christophd authored Apr 30, 2020
2 parents d95f48e + 934c059 commit d5b39da
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void loadOpenApiResource(String resource) {
} else {
openApiDoc = OpenApiResourceLoader.fromWebResource(url);
}
clientSteps.setUrl(String.format("%s://%s%s/%s", url.getProtocol(), url.getHost(), url.getPort() > 0 ? ":" + url.getPort() : "", OasModelHelper.getBasePath(openApiDoc)));
clientSteps.setUrl(String.format("%s://%s%s%s", url.getProtocol(), url.getHost(), url.getPort() > 0 ? ":" + url.getPort() : "", OasModelHelper.getBasePath(openApiDoc)));
} catch (MalformedURLException e) {
throw new IllegalStateException("Failed to retrieve Open API specification as web resource: " + resource, e);
}
Expand All @@ -105,7 +105,7 @@ public void loadOpenApiResource(String resource) {
.findFirst()
.orElse("http");

clientSteps.setUrl(String.format("%s://%s/%s", schemeToUse, OasModelHelper.getHost(openApiDoc), OasModelHelper.getBasePath(openApiDoc)));
clientSteps.setUrl(String.format("%s://%s%s", schemeToUse, OasModelHelper.getHost(openApiDoc), OasModelHelper.getBasePath(openApiDoc)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static List<String> getSchemes(Oas20Document openApiDoc) {

public static String getBasePath(Oas20Document openApiDoc) {
return Optional.ofNullable(openApiDoc.basePath)
.map(basePath -> basePath.startsWith("/") ? basePath.substring(1) : basePath).orElse("");
.map(basePath -> basePath.startsWith("/") ? basePath : "/" + basePath).orElse("/");
}

public static Map<String, OasSchema> getSchemaDefinitions(Oas20Document openApiDoc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static String getBasePath(Oas30Document openApiDoc) {
basePath = serverUrl;
}

return basePath.length() > 0 ? basePath : "/";
return basePath.startsWith("/") ? basePath : "/" + basePath;
}

public static Map<String, OasSchema> getSchemaDefinitions(Oas30Document openApiDoc) {
Expand Down

0 comments on commit d5b39da

Please sign in to comment.