• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DarkaOnLine / SwaggerLume / 9090835749

15 May 2024 06:09AM UTC coverage: 78.07% (-0.3%) from 78.325%
9090835749

push

github

web-flow
Support Lumen 11 (#140)

* Updating CI

* Update composer.json

* zircot

* Update test-config.yml

* Update test-config.yml

* Latest

* Update test-config.yml

* Update test-config.yml

* Update test-config.yml

* Update composer.json

* Update test-config.yml

* Update composer.json

* Update composer.json

* Update composer.json

* Update test-config.yml

* Update test-config.yml

* Update test-config.yml

* Update test-config.yml

* Update test-config.yml

* Update test-config.yml

* separate tests anotations to files for swagger-php:4 support

---------

Co-authored-by: Darius Matulionis <darius.matulionis@supermetrics.com>

178 of 228 relevant lines covered (78.07%)

4.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.22
/src/Http/Controllers/SwaggerLumeController.php
1
<?php
2

3
namespace SwaggerLume\Http\Controllers;
4

5
use Illuminate\Http\Response;
6
use Illuminate\Support\Facades\File;
7
use Illuminate\Support\Facades\Log;
8
use Illuminate\Support\Facades\Request as RequestFacade;
9
use Laravel\Lumen\Routing\Controller as BaseController;
10
use SwaggerLume\Generator;
11

12
class SwaggerLumeController extends BaseController
13
{
14
    /**
15
     * Dump api-docs.json content endpoint.
16
     *
17
     * @param  null  $docsFile
18
     * @return \Illuminate\Http\Response
19
     */
20
    public function docs()
21
    {
22
        $filePath = sprintf(
4✔
23
            '%s/%s',
4✔
24
            config('swagger-lume.paths.docs'),
4✔
25
            config('swagger-lume.paths.format_to_use_for_docs') === 'json' ? config('swagger-lume.paths.docs_json') : config('swagger-lume.paths.docs_yaml')
4✔
26
        );
4✔
27

28
        $yaml = false;
4✔
29
        $parts = explode('.', $filePath);
4✔
30

31
        if (! empty($parts)) {
4✔
32
            $extension = array_pop($parts);
4✔
33
            $yaml = strtolower($extension) === 'yaml';
4✔
34
        }
35

36
        if (config('swagger-lume.generate_always') && ! File::exists($filePath)) {
4✔
37
            try {
38
                Generator::generateDocs();
×
39
            } catch (\Exception $e) {
×
40
                Log::error($e);
×
41

42
                abort(
×
43
                    404,
×
44
                    sprintf(
×
45
                        'Unable to generate documentation file to: "%s". Please make sure directory is writable. Error: %s',
×
46
                        $filePath,
×
47
                        $e->getMessage()
×
48
                    )
×
49
                );
×
50
            }
51
        }
52

53
        if (! File::exists($filePath)) {
4✔
54
            abort(404, 'Cannot find '.$filePath);
1✔
55
        }
56

57
        $content = File::get($filePath);
3✔
58

59
        if ($yaml) {
3✔
60
            return Response($content, 200, [
×
61
                'Content-Type' => 'application/yaml',
×
62
                'Content-Disposition' => 'inline',
×
63
                'filename' => config('swagger-lume.paths.docs_yaml'),
×
64
            ]);
×
65
        }
66

67
        return new Response($content, 200, ['Content-Type' => 'application/json']);
3✔
68
    }
69

70
    /**
71
     * Display Swagger API page.
72
     *
73
     * @return \Illuminate\Http\Response
74
     */
75
    public function api()
76
    {
77
        if (config('swagger-lume.generate_always')) {
3✔
78
            Generator::generateDocs();
3✔
79
        }
80

81
        //need the / at the end to avoid CORS errors on Homestead systems.
82
        return new Response(
3✔
83
            view('swagger-lume::index', [
3✔
84
                'secure' => RequestFacade::secure(),
3✔
85
                'urlToDocs' => route('swagger-lume.docs'),
3✔
86
                'operationsSorter' => config('swagger-lume.operations_sort'),
3✔
87
                'configUrl' => config('swagger-lume.additional_config_url'),
3✔
88
                'validatorUrl' => config('swagger-lume.validator_url'),
3✔
89
            ]),
3✔
90
            200,
3✔
91
            ['Content-Type' => 'text/html']
3✔
92
        );
3✔
93
    }
94

95
    /**
96
     * Display Oauth2 callback pages.
97
     *
98
     * @return string
99
     */
100
    public function oauth2Callback()
101
    {
102
        return File::get(swagger_ui_dist_path('oauth2-redirect.html'));
1✔
103
    }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc