Customizing Swagger 3.x
When reporting an issue, please provide the following details:
- swagger-ui version 3.0.8
The documentation is not clear or old for the current version. Is there any documentation available on how to customize version 3.x
http://swagger.io/docs/swagger-tools/#customization-36
Couldn't find any of the folders / css /js files as mentioned in the guide
Unfortunately, there is no documentation yet, and it's not going to be immediate. We're fairly overloaded right now, but we'll do our best to put something out there.
Thanks for the update Ron. Atleast any suggestion on customisation ?
I want to provide user to switch source json url.
Hi @farhan-ejaz, I don't know if it's the correct way to do it, but I have a dropdown in my page (the dropdown options value are my json urls) and on the dropdown onchange event I inject the selected json url on swagger ui instance
// init swaggerUI
const ui = SwaggerUIBundle({
url: '',
dom_id: jqDom_id, // here change your jqDom_id
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
validatorUrl: null,
operationsSorter: "alpha"
})
window.ui = ui
// dropdown onchange event
jQuery('.my-dropdown-jqEl').on("change", function(e) {
var jsonDocUrl = jQuery(e.target).val();
ui.specActions.updateUrl(jsonDocUrl);
ui.specActions.download(jsonDocUrl);
});
I hope this can help you.
Hello All,
how can we call in angularJS 2 below code. const ui = SwaggerUIBundle({ url: '', dom_id: jqDom_id, // here change your jqDom_id presets: [ SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset ], plugins: [ SwaggerUIBundle.plugins.DownloadUrl ], layout: "StandaloneLayout", validatorUrl: null, operationsSorter: "alpha" }) window.ui = ui
I am importing import { SwaggerUIBundle, SwaggerUIStandalonePreset } from 'swagger-ui-dist' its getting cannot find module.
We are also eager to customize the look & feel of swagger-ui 3 for our project. We are embedding swagger-ui within another web app, and we require a swagger-ui look & feel that works a bit better within the limited screen real estate we have available for it. Ideally we would like to re-skin swagger-ui without modifying core code so it is easy to stay up-to-date with the latest version of swagger-ui.
We are unclear what extension points have been built into swagger-ui 3, and are hoping that docs will be coming soon. Even some brief comments posted here about the extension points could be very helpful until more complete docs are available. Any advise from the developers would be much appreciated!
@webron a quick question for customizing swagger-ui 3.*:
If our front-end is not based on React, could we customize swagger-ui 3.* to render some x- attribute? I'm back-end developer and new to swagger-ui, appreciate if you could help, thanks!
@hellosnow yes, you can still customize it.
@webron thanks! We'll explore how to customize swagger-ui 3.*, if any updated documentation please let use know. 😄
Hi All, I am also trying to customise the swagger ui 3.x but i am not able to inject authorization header from my external JS function. What is the configuration needed to add authorization header?
- I need to add bearer token Please help
Hi for bearer token: in index.html: < input id="bearer-code-input" type="text" placeholder="Enter Bearer Token here" style="width: auto" value="yourtoken" /> then in SwaggerUIBundle constructor: const ui = SwaggerUIBundle({ ..., requestInterceptor: function (req) { req.headers = { 'Authorization': 'Bearer ' + document.getElementById('bearer-code-input').value , 'Accept': 'application/json', 'Content-Type': 'application/json' }; return req; }, ... })
Good morning, do you know when the documentation will be in order to customize the ui?
When @shockey decides to merge his doc branch ;) In the meantime, you can take a look at https://github.com/swagger-api/swagger-ui/tree/ft/docs/docs to get you started.
Customization documentation is now available 😄 https://github.com/swagger-api/swagger-ui#customization
Closing!
@hellosnow, FYI, we just added a showExtensions option: https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md#display
@webron can you please help in fixing apiKey issue. Even though i have added this , it is not taking apiKey in the request url
"security": [ { "api_key": [ "qwerty" ] } ],
"components": { "securitySchemes": { "api_key": { "type": "apiKey", "in": "query", "name": "apiKey" } } }
What should i do??
@zem83 Can you help me, I'm trying to do something similar to be able to choose from multiples API specs when I landed on the main swagger page. Can you tell me what else I need to change here in order for it to work?
// init swaggerUI
const ui = SwaggerUIBundle({
url: '',
dom_id: jqDom_id, // here change your jqDom_id
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
validatorUrl: null,
operationsSorter: "alpha"
})
window.ui = ui
// dropdown onchange event
jQuery('.my-dropdown-jqEl').on("change", function(e) {
var jsonDocUrl = jQuery(e.target).val();
ui.specActions.updateUrl(jsonDocUrl);
ui.specActions.download(jsonDocUrl);
});
Where I need to define '.my-dropdown-jqEl' ?
Thanks!
@edesdan, I have both (jqDom_id and my-dropdown-jqEl) defined into the same HTML page, like this:
<select class="apiSelector">
<option value="path_1">/api/v1</option>
<option value="path_2">/api/v2</option>
</select>
<div id="swagger-ui" class="custom-swagger-ui"></div>
and then into the js file I have the swaggerUI init function that point to 'swagger-ui' div (the jqDom_id in my previous example) and the jQuery function for the onChange event on the HTML 'apiSelector' select (the my-dropdown-jqEl in my previous example).
This should be enough.
@zem83 thanks for your reply. BTW at the end I decided to use the Swagger-UI 3.13.6 release. They added support for a drop-down list menu, pretty handy and very easy to configure!
// Build a system
const ui = SwaggerUIBundle({
urls: [{url: "https://localhost/service-api1.yaml", name: "service-api1"},
{url: "https://localhost/service-api2.yaml", name: "service-api2"},
{url: "https://localhost/service-api3.yaml", name: "service-api3"}],
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
window.ui = ui
@edesdan, yes I saw that feature (and I'm sorry because I forgot to mention it in my answer xD) but I need to use a special style for the dropdown and other HTML components outside the Swagger "dom_id" HTML block, so I used my solution :)