swagger-api / swagger-api/swagger-ui
Rewriting request.url for loadSpec requests does not update URL selector box
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Q&A (please complete the following information)
- OS: Windows
- Browser: Chrome
- Version: 69
- Method of installation: swagger-ui-dist
- Swagger-UI version: 3.19.3
- Swagger/OpenAPI version: Swagger 2.0
Content & configuration
Example Swagger/OpenAPI definition:
N/A
Swagger-UI configuration options:
function _usp(url, fn) {
url = url.split('?');
var usp = new URLSearchParams(url[1]);
fn(usp);
url[1] = usp.toString();
return url[1] ? url.join('?') : url[0];
}
function setQueryParam(url, key, value) {
return _usp(url, function (usp) {
usp.set(key, value);
});
}
SwaggerUI({
requestInterceptor: function (request) {
if (request.loadSpec) {
// pass query params from the swagger-ui page to the spec request
var query = new URLSearchParams(window.location.search).entries();
for (var it = query.next(); !it.done; it = query.next()) {
request.url = setQueryParam(request.url, it.value[0], it.value[1]);
}
}
return request;
};
// ... other stuff
})
Describe the bug you're encountering
To reproduce...
Steps to reproduce the behavior:
- Write a request interceptor that modifies the url of loadSpec requests
- Load the page
- Wait for spec to load
- See that the spec selector box has the old URL
Expected behavior
Spec selextor textbox updates with changes made by interceptor.
Additional context or thoughts
https://github.com/swagger-api/swagger-ui/blob/a86fcf312a0d9b04d99982bf88a3d95884eddb9a/src/core/plugins/download-url.js#L38-L40 seems to be the problem, setting the URL back to the old value
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/core/plugins/download-url.js around lines 38-40 and trace how a requestInterceptor changes request.url for loadSpec requests. Reproduce the issue with the provided interceptor, then verify that the spec selector textbox reflects the rewritten URL instead of the original URL.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100