Skip to content

Instantly share code, notes, and snippets.

@ponelat
Last active March 10, 2020 02:12
Show Gist options
  • Save ponelat/328c2f651760fe3fdab2 to your computer and use it in GitHub Desktop.
Save ponelat/328c2f651760fe3fdab2 to your computer and use it in GitHub Desktop.
For having multiple specs in swagger-ui
<script>
// ...
var selectedUrl = "One";
var spec = {
"One": "/One.json",
"Two": "/Two.json"
}
function updateMultipleSpecs() {
var sel = $('#input_baseUrl');
sel.html("");
$.each(spec,function(key,val){
var opt = $('<option>')
.prop('value', val)
.prop('selected', selectedUrl === val)
.html(key);
sel.append(opt);
});
}
$('#input_baseUrl').change(function() {
var url = $(this).val();
window.swaggerUi.updateSwaggerUi({
url: url
});
selectedUrl = url;
updateMultipleSpecs();
});
updateMultipleSpecs();
// ...
</script>
<!-- ... -->
<!-- replace existing input_baseUrl with a select -->
<div class="input">
<select id="input_baseUrl" name="baseUrl"></select>
</div>
<!-- ... -->
@erajkovic
Copy link

Is the value 'selectedUrl' the correct way to setup the default selection ? in some other code snippet, I found that 'urls.primaryName' was used.

@sanja-stanimirovic
Copy link

When I try this I get an error on page load:

Uncaught TypeError: consumes.filter is not a function
    at C.n.contains (StatusCodeView.js:32)
    at C.n.render (StatusCodeView.js:32)
    at C.n.addParameter (StatusCodeView.js:32)
    at C.n.render (StatusCodeView.js:32)
    at C.n.addOperation (StatusCodeView.js:32)
    at C.n.render (StatusCodeView.js:32)
    at C.n.addResource (StatusCodeView.js:32)
    at C.n.render (StatusCodeView.js:32)
    at C.n.render (StatusCodeView.js:32)
    at module.exports.options.success (StatusCodeView.js:32)

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