Allow adding of multiple api versions
Closed this issue · 0 comments
yinx commented
With swagger it is possible to add multiple api versions and allow you to browser both versions.
To allow this, some small changes need to be made to this package.
In the index.blade.php view page, the script should be changed to show the top bar and to load in the multiple urls to the openapi files.
The standalone preset/layout is needed for the topbar. The urls property is where we should load in the different paths to the openapi files.
The urls.primaryName
property lets which file is the default that will be shown.
<body>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-ui-dist@latest/swagger-ui-bundle.js"></script>
<script src="https://unpkg.com/swagger-ui-dist@latest/swagger-ui-standalone-preset.js"></script>
<script>
window.onload = function () {
window.ui = SwaggerUIBundle({
urls: [
{
url: "/swagger/openapi.json",
name: "v1"
},
{
url: "/swagger/openapi-v2.json",
name: "v2"
}
],
"urls.primaryName": "v2",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
layout: 'StandaloneLayout',
});
ui.initOAuth({
clientId: '{{ config('swagger-ui.oauth.client_id') }}',
clientSecret: '{{ config('swagger-ui.oauth.client_secret') }}',
});
};
</script>
</body>
Since there could be more than 1 openapi file like this, the routing would need to take that into account and allow for routing the each file in the swagger folder.