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.

requestInterceptor that returns promise breaks curlify output

See original GitHub issue

Q&A (please complete the following information)

  • OS: Windows 10
  • Browser: Chrome
  • Version: 67.0.3396.99
  • Method of installation: dist assets
  • Swagger-UI version: 3.17.6
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

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));
          }
})

Describe the bug you’re encountering

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.

To reproduce…

Steps to reproduce the behavior:

  1. See this jsfiddle: https://jsfiddle.net/falxfalx/6xy24zL9/32/
  2. Press play
  3. Try it out on GET /pets
  4. Execute
  5. Observe generated curl request
  6. Now comment requestInterceptor return statement and uncomment the return req; line
  7. Repeat step 2 through 5 (this is expected behaviour)

Expected behavior

The displayed curl request should not be undefined.

Additional context or thoughts

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);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
copitzcommented, Jan 22, 2019

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
          }
})
2reactions
restfulheadcommented, May 12, 2019

Adding showMutatedRequest: false to the config seems to work for me. Without this option I’m seeing the same issue with the curl output.

Read more comments on GitHub >

github_iconTop Results From Across the Web

swagger-ui-dist - UNPKG
node_modules/@babel/runtime-corejs2/core-js/promise.js","webpack://SwaggerUIBundle/. ... src/core/curlify.js","webpack://SwaggerUIBundle/.
Read more >
share/swagger-ui.js.map - metacpan.org
node_modules/core-js/modules/_new-promise-capability.js","webpack://SwaggerUICore/. ... src/core/curlify.js","webpack://SwaggerUICore/.
Read more >
swagger-static.swagger-ui-bundle.js.map Maven / Gradle / Ivy
swagger-static.swagger-ui-bundle.js.map maven / gradle build tool code. The class is part of the package ➦ Group: com.smoketurner ➦ Artifact: ...
Read more >
swagger-ui: Versions - Openbase
ES Module output bundle path now points to swagger-ui-es-bundle-core , which ... requestInterceptor: use async/await to support return new Promise (#6279) ...
Read more >
api/docs/swagger-ui-es-bundle-core.js.map - Fossies
node_modules/@babel/runtime-corejs3/core-js-stable/promise.js","webpack://SwaggerUIBundle/. ... src/core/curlify.js","webpack://SwaggerUIBundle/.
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