1

I know there are different ways to enable the HTTP request duration in Swagger UI 3.x:

Swagger UI accepts configuration parameters in four locations.

From lowest to highest precedence:

  • The swagger-config.yaml in the project root directory, if it exists, is baked into the application
  • configuration object passed as an argument to Swagger UI (SwaggerUI({ ... }))
  • configuration document fetched from a specified configUrl
  • configuration items passed as key/value pairs in the URL query string

For example with a Docker variable:

DISPLAY_REQUEST_DURATION="true"

I've some API stuck with the older Swagger UI 2.x, though.

  • In 2.x, is it possible to enable the duration through the Docker variable?

  • If not, what choices do I have to do it through configuration (not through software)?

Helen
  • 87,344
  • 17
  • 243
  • 314
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • Just to clarify - by 2.0 and 3.0 do you mean [Swagger UI versions](https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/version-detection.md)? Request duration is only available in Swagger UI 3.x, it's not available in UI 2.x. – Helen Nov 24 '20 at 20:14
  • Thank you Helen, yes, I meant that. Please turn it into an answer so I can accept it... I suspected it but wanted to be sure – Andrea Ligios Nov 24 '20 at 21:09

1 Answers1

2

Request duration is only available in Swagger UI 3.0.18+, it's not available in v. 2.x

Helen
  • 87,344
  • 17
  • 243
  • 314
  • How painful would it be migrating the UI from 2 to 3, in your opinion? – Andrea Ligios Nov 24 '20 at 22:54
  • If you just host the dist assets without customizations, it should be as simple as replacing the dist assets and updating the `url` in index.html to point to your YAML/JSON file. But in the general case, migration depends on many factors, for example: 1) whether you use UI's dist assets directly or bundled with some library (e.g. Springfox/Swashbuckle); 2) whether you need custom CSS or other look & feel tweaks; 3) whether you need UI localization, support for the old Swagger 1.x Specification, Internet Explorer support - these things are in UI 2.x only. Keep in mind that UI 2.x is EOL. – Helen Nov 24 '20 at 23:11
  • Well @Helen, actually is this one: https://github.com/Alfresco/rest-api-explorer/blob/master/src/main/webapp/index.html Apart from the sparse files now reunited in a single CSS and a single JS in v3, I see some jQuery initialization there that I suppose won't be supported anymore in v3, right? – Andrea Ligios Nov 25 '20 at 16:22
  • 1
    Yes, jQuery tweaks won't work, the new version uses React. Here're [examples of React-based customizations](https://github.com/swagger-api/swagger-ui/issues/5027#issuecomment-438745785) for the reference. Most configs in `new SwaggerUi(...)` are also supported in v. 3, I think. API definition selector ([this](https://github.com/Alfresco/rest-api-explorer/blob/master/src/main/webapp/index.html#L121)) is now supported using the `urls` config. – Helen Nov 25 '20 at 17:40
  • 1
    (cont.) Request authentication (`addAuthorization()` in your linked file) is done by adding `securityDefinitions`+`security` to the API definition itself and using the "Authorize" button in Swagger UI. There's also [`preauthorizeBasic`](https://stackoverflow.com/a/49637597/113116) to apply auth programmatically. – Helen Nov 25 '20 at 17:47
  • Hi Helen, I've finally found the time to migrate it to Swagger UI 3, thank you a lot for your help! It's 99% ready, but there's a small error that I don't know if it's a false positive from Swagger UI 3 or if there's actually something to change in that particular API definition. I'd really appreciate your opinion about it, if you can: https://stackoverflow.com/q/65584131/1654265 – Andrea Ligios Jan 08 '21 at 11:18