Example Swagger/OpenAPI definition:
openapi: 3.0.0
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: 'http://petstore.swagger.io/v1'
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
responses:
'200':
description: An paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
Swagger-UI configuration options:
SwaggerUI({
url: "https://api.myjson.com/bins/1h15yo",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl,
],
requestInterceptor: req => {
//return req;
return new Promise((resolve, reject) => resolve(req));
}
})
When using a requestInterceptor that returns a promise (that resolves to the request), instead of the pure request, the curl statement generated with curlify results in curl -X "undefined". Although the modified request is being used to send the http request.
Steps to reproduce the behavior:
return req; lineThe displayed curl request should not be undefined.
Since I saw that curlify.js has a curl function that is to be called with the request as argument, I suspect that when returning a promise, the curlify call becomes: curl(promise) while it should be something like:
const req = await promise;
curl(req);
Can anyone please confirm this? If not, then I will have to fix this in more hacky way, by rewriting parts of the DOM or something like that..
@Falx, bug confirmed - looks to me like we need to await the mutated request in the wrapper we pass to Swagger Client:
Thank you for confirming this @shockey . Right now I worked around it by showing the unmutated request in the curl section and then adding my request mutations (the same ones I do in requestInterceptor) to the request property of the Curl component, with a wrapComponent plugin.
It would of course be nicer to use the built-in features once this is fixed.
Any update on fixing this? It's biting me too, if I set requestInterceptor the curl request is hosed.
It鈥檚 in our queue to be worked on, no promises on a fix ETA.
If anyone would like to make a PR for this, I鈥檇 be happy to go into more detail on what needs to be done.
If the request url isn't changed by requestInterceptor asynchronously this issue can be worked around like this:
SwaggerUI({
// ...
requestInterceptor: req => {
//return req;
const promise = new Promise((resolve, reject) => resolve(req));
promise.url = req.url
return promise
}
})
Adding showMutatedRequest: false to the config seems to work for me. Without this option I'm seeing the same issue with the curl output.
It鈥檚 in our queue to be worked on, no promises on a fix ETA.
If anyone would like to make a PR for this, I鈥檇 be happy to go into more detail on what needs to be done.
@shockey Could you outline where all the code needs to change to make this happen? I'm working on a project where this would be beneficial. Right now I've got a fork that updates the code to work for ONLY promise based requestIntercept functions.
(That is to say the code seems to work for both Promise/Non Promise types, but one test fails)
https://github.com/swagger-api/swagger-ui/pull/5607
Most helpful comment
If the request url isn't changed by requestInterceptor asynchronously this issue can be worked around like this: