question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$ref downloading doesn't use requestInterceptor

See original GitHub issue
Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? 2.0
Which Swagger-UI version? 3.3.2
How did you install Swagger-UI? git checkout, dist dir
Which browser & version? Chrome 63
Which operating system? macOS 10.13

Demonstration API definition

  1. The ‘petstore’ example from here: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore.json

  2. The ‘petstore-separate’ example from here: https://github.com/OAI/OpenAPI-Specification/tree/master/examples/v2.0/json/petstore-separate

…both hosted on a local server that requires basic authentication.

Configuration (browser query string, constructor, config.yaml)

{
  url: "http://locahost:3000/spec/swagger.json",  /* or http://localhost:3000/petstore.json */
  requestInterceptor: (req) => {
    if (req.loadSpec) {
        req.headers.Authorization = 'Basic ' + btoa("admin:secret");
    }
    return req;
  },
  ...
}

Expected Behavior

In swagger-ui@3.3.2, #3738 fixes a gap where the requestInterceptor() wasn’t being invoked for the download of the spec URL.

Current Behavior

I have been testing this feature and can confirm that it works as expected for the initial spec URL.

For example, when loading the simple petstore.json example, the requestInterceptor is invoked and the correct Authorization: Basic <base64(admin:secret)> header is passed in the fetch.

Similarly, for the ‘separate’ example, the requestInterceptor is invoked on the fetch of spec/swagger.json and the correct Authorization header is passed.

However, when resolving and fetching any the $ref URLs in spec/swagger.json (i.e. spec/parameters.json, spec/Pet.json, spec/NewPet.json and common/Error.json), the requestInterceptor doesn’t appear to be invoked; and as a result these sub-fetches fail with a 401 Unauthorized.

Possible Solution

Ensure that requestInterceptor is correctly called for any $ref downloads.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
scottoharacommented, Oct 20, 2017

You do an amazing job, @shockey. Many thanks.

1reaction
shockeycommented, Oct 26, 2017

Okay, this should be working now - I tested it on my end before merging #3830.

This will be released tomorrow evening as part of our weekly release.

Thanks everyone!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: How to revert to the old Create New Change request...
Hello,. We are a brand new instance implemented on Quebec and we are seeing that the Create New Change request interceptor page was...
Read more >
Using OpenAPI and Swagger UI - Quarkus
This guide explains how your Quarkus application can expose its API description through an OpenAPI specification and how you can test it via...
Read more >
Intercept and modify REST calls :: SDKs - ForgeRock Backstage
The request body and post data. Request interceptors. The SDKs provide "request interceptor" interfaces you can use to customize requests.
Read more >
Spring MVC Interceptor HandlerInterceptorAdapter ...
We can use this spring interceptor method to determine the time taken by handler method to process the client request. void afterCompletion( ...
Read more >
Adding Interceptors in OkHTTP - Baeldung
Likewise, we should consider using a network interceptor when our logic doesn't rely on the actual content of the response; Using a network ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found