Skip to content
Merged
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 @@ -14,10 +14,7 @@
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.net.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
Expand Down Expand Up @@ -109,42 +106,45 @@ public static String urlToString(String url, List<AuthorizationValue> auths) thr
BufferedReader br = null;

try {
final URL inUrl = new URL(cleanUrl(url));
final List<AuthorizationValue> query = new ArrayList<>();
final List<AuthorizationValue> header = new ArrayList<>();
if (auths != null && auths.size() > 0) {
for (AuthorizationValue auth : auths) {
if ("query".equals(auth.getType())) {
appendValue(inUrl, auth, query);
} else if ("header".equals(auth.getType())) {
appendValue(inUrl, auth, header);
URLConnection conn;
do {
final URL inUrl = new URL(cleanUrl(url));
final List<AuthorizationValue> query = new ArrayList<>();
final List<AuthorizationValue> header = new ArrayList<>();
if (auths != null && auths.size() > 0) {
for (AuthorizationValue auth : auths) {
if ("query".equals(auth.getType())) {
appendValue(inUrl, auth, query);
} else if ("header".equals(auth.getType())) {
appendValue(inUrl, auth, header);
}
}
}
}
final URLConnection conn;
if (!query.isEmpty()) {
final URI inUri = inUrl.toURI();
final StringBuilder newQuery = new StringBuilder(inUri.getQuery() == null ? "" : inUri.getQuery());
for (AuthorizationValue item : query) {
if (newQuery.length() > 0) {
newQuery.append("&");
if (!query.isEmpty()) {
final URI inUri = inUrl.toURI();
final StringBuilder newQuery = new StringBuilder(inUri.getQuery() == null ? "" : inUri.getQuery());
for (AuthorizationValue item : query) {
if (newQuery.length() > 0) {
newQuery.append("&");
}
newQuery.append(URLEncoder.encode(item.getKeyName(), UTF_8.name())).append("=")
.append(URLEncoder.encode(item.getValue(), UTF_8.name()));
}
newQuery.append(URLEncoder.encode(item.getKeyName(), UTF_8.name())).append("=")
.append(URLEncoder.encode(item.getValue(), UTF_8.name()));
conn = new URI(inUri.getScheme(), inUri.getAuthority(), inUri.getPath(), newQuery.toString(),
inUri.getFragment()).toURL().openConnection();
} else {
conn = inUrl.openConnection();
}
CONNECTION_CONFIGURATOR.process(conn);
for (AuthorizationValue item : header) {
conn.setRequestProperty(item.getKeyName(), item.getValue());
}
conn = new URI(inUri.getScheme(), inUri.getAuthority(), inUri.getPath(), newQuery.toString(),
inUri.getFragment()).toURL().openConnection();
} else {
conn = inUrl.openConnection();
}
CONNECTION_CONFIGURATOR.process(conn);
for (AuthorizationValue item : header) {
conn.setRequestProperty(item.getKeyName(), item.getValue());
}

conn.setRequestProperty("Accept", ACCEPT_HEADER_VALUE);
conn.setRequestProperty("User-Agent", USER_AGENT_HEADER_VALUE);
conn.connect();
conn.setRequestProperty("Accept", ACCEPT_HEADER_VALUE);
conn.setRequestProperty("User-Agent", USER_AGENT_HEADER_VALUE);
conn.connect();
url = ((HttpURLConnection) conn).getHeaderField("Location");
} while (301 == ((HttpURLConnection) conn).getResponseCode());
InputStream in = conn.getInputStream();

StringBuilder contents = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,15 @@ public void testIssue813() throws Exception {
assertTrue(result.getOpenAPI() != null);

}

@Test
public void testIssue844() {
OpenAPIParser openApiParser = new OpenAPIParser();
ParseOptions options = new ParseOptions();
options.setResolve(true);

OpenAPI openAPI = openApiParser.readLocation("reusableParametersWithExternalRef.json", null, options).getOpenAPI();
assertNotNull(openAPI);
assertEquals(openAPI.getPaths().get("/pets/{id}").getGet().getParameters().get(0).getIn(), "header");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"openapi": "3.0.1",
"info": {
"version": "1.0.9-abcd",
"title": "Swagger Sample API Reusable Parameters"
},
"paths": {
"/pets/{id}": {
"get": {
"description": "Returns pets based on ID",
"summary": "Find pets by ID",
"operationId": "getPetsById",
"parameters": [
{ "$ref": "http://docs.baikalplatform.com/common/v2.0/common.json#/parameters/x-correlator" }
],
"responses": {
"200": {
"description": "pet response"
},
"default": {
"description": "error payload"
}
}
}
}
}
}