Skip to content

Commit

Permalink
chore: apis for swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
doyouhaobaby committed Jul 31, 2019
1 parent 36f427a commit 45d39b0
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 21 deletions.
64 changes: 43 additions & 21 deletions apis/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,54 @@
<script src="./swagger-ui-standalone-preset.js"> </script>
<script>
window.onload = function() {
if ('/' !== window.location.href.substr(-1) && 'index.html' !== window.location.href.substr(-10)) {
if ('/' !== window.location.href.substr(-1) &&
'index.html' !== window.location.href.substr(-10)) {
window.location.href = window.location.href+'/';
}

var url = '/swagger/';
if (window.location.hash) {
url = window.location.hash.substr(1)
}
fetch('/swagger/apis',{
cache: 'no-cache',
headers: {
'user-agent': 'Mozilla/4.0 MDN Example',
'content-type': 'application/json'
},
method: 'GET',
})
.then(function(response) {
return response.json();
})
.then(function(apis) {
var url = '/swagger/user';
if (window.location.hash) {
url = window.location.hash.substr(1)
}

var primaryName = '';
for (var i=0;i<apis.length;i++) {
if (apis[i]['url'].indexOf(url) != -1) {
primaryName = apis[i]['name'];
}
}

// Build a system
const ui = SwaggerUIBundle({
url: url,
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
// Build a system
const ui = SwaggerUIBundle({
urls: apis,
'urls.primaryName': primaryName,
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})

window.ui = ui
}
window.ui = ui
});
};
</script>
</body>
</html>
46 changes: 46 additions & 0 deletions application/app/App/Controller/Swagger/Apis.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/*
* This file is part of the your app package.
*
* The PHP Application For Code Poem For You.
* (c) 2018-2099 http://yourdomian.com All rights reserved.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace App\App\Controller\Swagger;

/**
* 文档汇总.
*
* @author Name Your <[email protected]>
*
* @since 2019.07.31
*
* @version 1.0
*/
class Apis
{
/**
* 响应.
*
* @return array
*/
public function handle(): array
{
return [
[
'name' => 'User Api',
'url' => '/swagger/user',
],
[
'name' => 'QueryPHP API',
'url' => '/swagger',
],
];
}
}

0 comments on commit 45d39b0

Please sign in to comment.