swagger-api / swagger-api/swagger-ui

Rewriting request.url for loadSpec requests does not update URL selector box

Open
#4,947 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cat: customization type: bug
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:

  1. Write a request interceptor that modifies the url of loadSpec requests
  2. Load the page
  3. Wait for spec to load
  4. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.