Contributions
Re: How to use requestInterceptor in SwaggerUIBundle call
I figured it out with the help for a for-in loop to get the properties of the request object. The request object that requestInterceptor gets isn't the one that's described in the Fetch API. It's just got a headers array and you can add directly to it. So: req.headers['authorization-token'] = 'myheadertokenvalue'; works fine.7.3KViews1like0CommentsHow to use requestInterceptor in SwaggerUIBundle call
I'm trying to use requestInterceptor in my SwaggerUIBundle call to add a header to the outgoing request. My code is: window.onload = function() { // Begin Swagger UI call region const ui = SwaggerUIBundle({ url: '@Model.SwaggerFilename', dom_id: '#swagger-ui', requestInterceptor: (req) => { req.headers.append('myheader', 'wombats'); return req; }, //request.curlOptions: [ "-H apikey: abcd"], presets: [ SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset ], plugins: [ SwaggerUIBundle.plugins.DownloadUrl ], layout: "StandaloneLayout" }); The error I get is: request.headers.append is not a function. Could anyone explain how to do this, or point me to documentation on the request object that is passed to the requestInterceptor? Thank you.Solved7KViews0likes1CommentBest way to set api key dynamically
Hi, all. I've got a Swagger spec file that I'd like to use with the Try It Out function in SwaggerUI. We're hosting SwaggerUI on our site in a section of the site that requires authorization, so users have already entered name & password once. I'd like them to be able to use Try It Out without authenticating again and I'd like to do it without actually writing the API key data into the Swagger JSON file itself. Does anyone have a recommendation on the best way to do this? I've tried: 1. Adding a spec parameter to the code below and writing the Swagger info to it 2. Setting request.curlOptions and adding a header value for the api key 3. Adding the line requestInterceptor: (req) => { req.headers.append('apikey', 'apikeyvalue'); return req; }, but none of those worked for me. Thanks very much. window.onload = function() { // Begin Swagger UI call region const ui = SwaggerUIBundle({ url: '@Model.SwaggerFilename', dom_id: '#swagger-ui', deepLinking: true, request.curlOptions: '[ -H "apikey: abcd"]', presets: [ SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset ], plugins: [ SwaggerUIBundle.plugins.DownloadUrl ], layout: "StandaloneLayout" }); window.onload = function() { // Begin Swagger UI call region const ui = SwaggerUIBundle({ url: '@Model.SwaggerFilename', dom_id: '#swagger-ui', deepLinking: true, request.curlOptions: '[ -H "apikey: abcd"]', presets: [ SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset ], plugins: [ SwaggerUIBundle.plugins.DownloadUrl ], layout: "StandaloneLayout" });742Views0likes0Comments