Skip to content

Commit b352d2c

Browse files
committed
fix: Fixed some issues
1 parent 287184c commit b352d2c

File tree

6 files changed

+155
-10
lines changed

6 files changed

+155
-10
lines changed

README.md

+50-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,50 @@
1-
# laravel-swagger
2-
laravel swagger
1+
# laravel-swagger | A Web Installer [Package](https://packagist.org/packages/westhack/laravel-swagger)
2+
3+
- [About](#about)
4+
- [Requirements](#requirements)
5+
- [Installation](#installation)
6+
- [License](#license)
7+
8+
## About
9+
This is the Swagger 3.0 ui
10+
11+
## Requirements
12+
13+
* [Laravel 5.1, 5.2, 5.3, 5.4, or 5.5+](https://laravel.com/docs/installation)
14+
15+
## Installation
16+
17+
1. From your projects root folder in terminal run:
18+
19+
```bash
20+
composer require rachidlaasri/laravel-installer
21+
```
22+
23+
2. Register the package
24+
25+
* Laravel 5.5 and up
26+
Uses package auto discovery feature, no need to edit the `config/app.php` file.
27+
28+
* Laravel 5.4 and below
29+
Register the package with laravel in `config/app.php` under `providers` with the following:
30+
31+
```php
32+
'providers' => [
33+
\Westhack\LaravelSwagger\Providers\SwaggerServiceProvider::class,
34+
];
35+
```
36+
37+
3. Publish the packages views, config file, assets files by running the following from your projects root folder:
38+
39+
```bash
40+
php artisan vendor:publish --provider="Westhack\LaravelSwagger\Providers\SwaggerServiceProvider"
41+
```
42+
43+
## Routes
44+
45+
* `/swagger`
46+
* `/api/swagger`
47+
48+
## License
49+
50+
MIT license

composer.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
}
1010
],
1111
"require": {
12-
"php": ">=7.0.0"
12+
"php": ">=7.0.0",
13+
"illuminate/support": "^5.1",
14+
"zircote/swagger-php": "^3.0"
1315
},
1416
"autoload": {
1517
"psr-4": {

src/Controllers/SwaggerApiController.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Westhack\LaravelSwagger\Controllers;
44

55
use Illuminate\Routing\Controller;
6+
use Illuminate\Support\Facades\Cache;
7+
use Illuminate\Http\Response;
68

79
class SwaggerApiController extends Controller
810
{
@@ -48,9 +50,9 @@ public function index()
4850
$this->clearCache();
4951

5052
if ($this->enableCache) {
51-
if (($swagger = Cache::get($this->cacheKey)) === false) {
53+
if (($swagger = $this->cache->get($this->cacheKey)) === false) {
5254
$swagger = $this->getSwagger();
53-
Cache::put($this->cacheKey, $swagger);
55+
$this->cache->put($this->cacheKey, $swagger);
5456
}
5557
} else {
5658
$swagger = $this->getSwagger();
@@ -75,7 +77,7 @@ protected function clearCache()
7577
{
7678
$clearCache = request('clear-cache', false);
7779
if ($clearCache !== false) {
78-
Cache::forget($this->cacheKey);
80+
$this->cache->forget($this->cacheKey);
7981
}
8082
}
8183

@@ -95,4 +97,4 @@ function ($path) {
9597

9698
return \OpenApi\scan($scanDirs, $this->scanOptions)->toJson();
9799
}
98-
}
100+
}

src/Providers/SwaggerServiceProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function publishFiles()
4646
], 'laravelswagger');
4747

4848
$this->publishes([
49-
__DIR__.'/../assets' => public_path('swagger'),
49+
__DIR__.'/../assets' => public_path('assets/swagger'),
5050
], 'laravelswagger');
5151

5252
$this->publishes([

src/Routes/web.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
Route::get('/swagger', 'Swagger\SwaggerController@index');
3+
Route::get('/swagger', '\Westhack\LaravelSwagger\Controllers\SwaggerController@index');
44

5-
Route::get('/api/swagger', 'Swagger\SwaggerApiController@index');
5+
Route::get('/api/swagger', '\Westhack\LaravelSwagger\Controllers\SwaggerApiController@index');
66

src/Views/index.blade.php

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>{{$title}}</title>
6+
<!--<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">-->
7+
<link rel="icon" type="image/png" href="{{ asset('assets/swagger/favicon-32x32.png') }}" sizes="32x32" />
8+
<link rel="icon" type="image/png" href="{{ asset('assets/swagger/favicon-16x16.png') }}" sizes="16x16" />
9+
<style>
10+
html
11+
{
12+
box-sizing: border-box;
13+
overflow: -moz-scrollbars-vertical;
14+
overflow-y: scroll;
15+
}
16+
*,
17+
*:before,
18+
*:after
19+
{
20+
box-sizing: inherit;
21+
}
22+
23+
body {
24+
margin:0;
25+
background: #fafafa;
26+
}
27+
</style>
28+
<link rel="stylesheet" href="{{ asset('assets/swagger/swagger-ui.css') }}">
29+
</head>
30+
31+
<body>
32+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
33+
<defs>
34+
<symbol viewBox="0 0 20 20" id="unlocked">
35+
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
36+
</symbol>
37+
38+
<symbol viewBox="0 0 20 20" id="locked">
39+
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
40+
</symbol>
41+
42+
<symbol viewBox="0 0 20 20" id="close">
43+
<path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
44+
</symbol>
45+
46+
<symbol viewBox="0 0 20 20" id="large-arrow">
47+
<path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
48+
</symbol>
49+
50+
<symbol viewBox="0 0 20 20" id="large-arrow-down">
51+
<path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
52+
</symbol>
53+
54+
55+
<symbol viewBox="0 0 24 24" id="jump-to">
56+
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
57+
</symbol>
58+
59+
<symbol viewBox="0 0 24 24" id="expand">
60+
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
61+
</symbol>
62+
63+
</defs>
64+
</svg>
65+
66+
<div id="swagger-ui"></div>
67+
<script type="text/javascript" src="{{ asset('assets/swagger/swagger-ui-bundle.js') }}"></script>
68+
<script type="text/javascript" src="{{ asset('assets/swagger/swagger-ui-standalone-preset.js') }}"></script>
69+
70+
<script>
71+
window.onload = function() {
72+
// Build a system
73+
const ui = SwaggerUIBundle({
74+
url: "/api/swagger",
75+
dom_id: '#swagger-ui',
76+
deepLinking: true,
77+
validatorUrl: false,
78+
presets: [
79+
SwaggerUIBundle.presets.apis,
80+
SwaggerUIStandalonePreset
81+
],
82+
plugins: [
83+
SwaggerUIBundle.plugins.DownloadUrl
84+
],
85+
layout: "StandaloneLayout"
86+
});
87+
88+
window.ui = ui
89+
}
90+
</script>
91+
</body>
92+
93+
</html>

0 commit comments

Comments
 (0)