swagger-api / swagger-api/swagger-ui

Can't get requestInterceptor to fire

Open
#5,312 1 comment 0 reactions 0 assignees View on GitHub

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: macOS
  • Browser: Chrome & Safari
  • Version: 73 & 12/1
  • Method of installation: As part of Swashbuckle.AspNetCore with injected index.html <- this works!
  • Swagger-UI version: 3.19.5
  • Swagger/OpenAPI version: Swagger 2.0
Content & configuration

in following instructions I've added the following to the index.htm as provided here

<script>
    const ui = SwaggerUIBundle({
        url: "/swagger/1.0/swagger.json",
        dom_id: '#swagger-ui',
        requestInterceptor: req => {
                req.headers.myheader = "ABC123";
                console.log(req);
                return req;
        }
    });
    window.ui = ui;
</script>

on page load the Request Interceptor seems to be set up as expected.

How can we help?

I've spent hours trawling google, and prior issues here to no avail, I'm also very new to this area so hope that you can perhaps humor my nubie question.

Given the above, on the TryItNow -> Execute the request is set to the server. debugging the browser client it seem the interceptor is not being invoked, and the set it definitely not getting the myheader

The intention in the longer run is to generate a Custom HMAC hash authentication header based on a provided X-API-Key header that is set up and working. The basis of my future solution is here, that no longer seems to work given current swashbuckle and swagger-ui capabilities.

With help, and one I get this working I'll post the solution here such that other can benefit (and cross link to the Swashbuckle.AspNetCore project.

Thanks!

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 the injected index.html configuration shown in the issue and inspect how SwaggerUIBundle handles requestInterceptor for TryItNow executions. Reproduce the Execute flow in Chrome or Safari while checking whether the interceptor logs the request and whether myheader reaches the server. Done means the interceptor fires and the header is present on the outgoing request.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.