Skip to content

displayRequestDuration not working as expected #7243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Lazu13 opened this issue May 6, 2021 · 4 comments
Open

displayRequestDuration not working as expected #7243

Lazu13 opened this issue May 6, 2021 · 4 comments

Comments

@Lazu13
Copy link

Lazu13 commented May 6, 2021

Q&A (please complete the following information)

  • OS: Linux
  • Browser: firefox,chrom
  • Version: 88.0 (64-bit)
  • Method of installation: maven (scala tapir library dependency)
  • Swagger-UI version: 3.45.0
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.3
info:
  title: The tapir library
  version: 1.0.0
paths:
  /books/list/all:
    get:
      operationId: getBooksListAll
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Book'
  /books/add:
    post:
      operationId: postBooksAdd
      requestBody:
        description: The book to add
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Book'
            example:
              title: Pride and Prejudice
              year: 1813
              author:
                name: Jane Austen
        required: true
      responses:
        '200':
          description: ''
components:
  schemas:
    Book:
      required:
      - title
      - year
      - author
      type: object
      properties:
        title:
          type: string
        year:
          type: integer
        author:
          $ref: '#/components/schemas/Author'
    Author:
      required:
      - name
      type: object
      properties:
        name:
          type: string

Swagger-UI configuration options:

SwaggerUIBundle({
        url: "https://petstore.swagger.io/v2/swagger.json",
        dom_id: '#swagger-ui',
        deepLinking: true,
        presets: [
          SwaggerUIBundle.presets.apis,
          SwaggerUIStandalonePreset
        ],
        plugins: [
          SwaggerUIBundle.plugins.DownloadUrl
        ],
        layout: "StandaloneLayout"
      });

Query string options

?url=/admin/docs/docs.yaml&displayRequestDuration=true

Describe the bug you're encountering

after adding displayRequestduration to swagger query parameters: displayRequestDuration=true as per above, I can see request duration, however time shown is far from what other means of measurements calculated.

The request duration is not correctly calculated.

To reproduce...

Steps to reproduce the behavior:

  1. Install and run sample akka-http project with tapir. I will use this one as an example: sample-project
  2. Go to localhost.swagger-ui.html with displayRequestDuration=true already appended in query parameters.
  3. Try it out on /books/list/all endpoint.
  4. See request duration
  5. Use the same query with other tools like Postman or CURL
  6. See the difference in request duration times

Expected behavior

I expect time to be at least similar (not 4 or 5 times higher) to the time shown by Postman or CURL.

Screenshots

Swagger
obraz-20210423-093822
Postman
obraz-20210423-093630
In-application metrics
obraz-20210423-093659

Additional context or thoughts

Maybe the time that I see is, somehow, correct? If so, please let me know how should I interpret it.

@miroljub1995
Copy link

I can confirm this too.

@MemeDeveloper
Copy link

I can also confirm ms values here can easily be double or triple the actual request time.

I've been comparing the Chrome Dev Tools Network tab ms #s, and using postman.

Often get swaggerUI reporting massively inflated ms #'s.

N.B. I do generally see much closer reported duration when I set
syntaxHighlight:false

With .net and swashbuckle:
o.ConfigObject.AdditionalItems.Add("syntaxHighlight", false);

@Mathias02 Mathias02 mentioned this issue Apr 5, 2025
17 tasks
@Mathias02
Copy link

Mathias02 commented Apr 6, 2025

This issue has to do with the optimization of the app. We look at the network, the machine that it's being run on and also the browser. I am currently using Linux Mint, my browser is Firefox version 137.0 and my internet connection speed is at 51%. After setting displayRequestDuration to true and run the app, I got response time of less than 1000ms for different requests which is much better.

@char0n
Copy link
Member

char0n commented May 27, 2025

Hi everybody,

displayRequestDuration not working as expected

When turned on, the indicator does compute the total time needed to build a request from OpenAPI spec, issue the actual HTTP request and serialize the response. Which means that the time needed to issue an actual request and receive a response is just part of that number. If actual HTTP request/response time is needed then the closes approximation to that would be to use request and response interceptors to measure it (but that would also include the response serialization which might be significant number depending of payload size).

So to remedy this, we would need to do a change probably here to get a pure network request/response time and attach it to a response object. PR for swagger-client is welcome. When we have the swagger-client change we can use the response.networkDuration here in SwaggerUI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants