├── .github
└── workflows
│ ├── run-linting.yml
│ └── run-tests.yml
├── .php-cs-fixer.php
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE.md
├── README.md
├── UPGRADING.md
├── composer.json
├── config
└── swagger-ui.php
├── phpcs.xml
├── resources
└── views
│ └── index.blade.php
├── src
├── Console
│ └── InstallCommand.php
├── Http
│ ├── Controllers
│ │ ├── OpenApiJsonController.php
│ │ ├── SwaggerOAuth2RedirectController.php
│ │ └── SwaggerViewController.php
│ └── Middleware
│ │ └── EnsureUserIsAuthorized.php
└── SwaggerUiServiceProvider.php
└── stubs
└── SwaggerUiServiceProvider.stub
/.github/workflows/run-linting.yml:
--------------------------------------------------------------------------------
1 | name: run-linting
2 |
3 | on:
4 | push:
5 | pull_request:
6 |
7 | jobs:
8 | run-linting:
9 | runs-on: ubuntu-latest
10 |
11 | steps:
12 | - name: Checkout code
13 | uses: actions/checkout@v3
14 |
15 | - name: Setup PHP
16 | uses: shivammathur/setup-php@v2
17 | with:
18 | php-version: 8.4
19 |
20 | - name: Get Composer cache cirectory
21 | id: composer-cache
22 | run: |
23 | echo "::set-output name=dir::$(composer config cache-files-dir)"
24 |
25 | - name: Cache Composer packages
26 | uses: actions/cache@v3
27 | with:
28 | path: ${{ steps.composer-cache.outputs.dir }}
29 | key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
30 | restore-keys: |
31 | ${{ runner.os }}-composer-
32 |
33 | - name: Install dependencies
34 | run: composer install --prefer-dist --no-interaction --no-suggest
35 |
36 | - name: Execute linting
37 | run: |
38 | PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --dry-run
39 | vendor/bin/phpcs --colors --report-full
40 |
--------------------------------------------------------------------------------
/.github/workflows/run-tests.yml:
--------------------------------------------------------------------------------
1 | name: run-tests
2 |
3 | on:
4 | push:
5 | pull_request:
6 |
7 | jobs:
8 | run-tests:
9 | runs-on: ubuntu-latest
10 |
11 | strategy:
12 | fail-fast: false
13 | matrix:
14 | php: [8.1, 8.2, 8.3, 8.4]
15 | laravel: ['9.*', '10.*', '11.*', '12.*']
16 | dependency-version: [prefer-lowest, prefer-stable]
17 | exclude:
18 | - php: 8.4
19 | laravel: 11.*
20 | dependency-version: prefer-lowest
21 | - php: 8.4
22 | laravel: 10.*
23 | - php: 8.4
24 | laravel: 9.*
25 | - php: 8.3
26 | laravel: 9.*
27 | dependency-version: prefer-lowest
28 | - php: 8.2
29 | laravel: 9.*
30 | dependency-version: prefer-lowest
31 | - php: 8.1
32 | laravel: 11.*
33 | - laravel: 12.*
34 | php: 8.1
35 |
36 | name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.dependency-version }}
37 |
38 | steps:
39 | - name: Update apt
40 | run: sudo apt-get update --fix-missing
41 |
42 | - name: Checkout code
43 | uses: actions/checkout@v3
44 |
45 | - name: Setup PHP
46 | uses: shivammathur/setup-php@v2
47 | with:
48 | php-version: ${{ matrix.php }}
49 | coverage: xdebug
50 | extensions: yaml
51 |
52 | - name: Get Composer cache cirectory
53 | id: composer-cache
54 | run: |
55 | echo "::set-output name=dir::$(composer config cache-files-dir)"
56 |
57 | - name: Cache Composer packages
58 | uses: actions/cache@v3
59 | with:
60 | path: ${{ steps.composer-cache.outputs.dir }}
61 | key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
62 | restore-keys: |
63 | ${{ runner.os }}-composer-
64 |
65 | - name: Install dependencies
66 | run: |
67 | composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
68 | composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
69 |
70 | - name: Execute tests
71 | run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
72 |
--------------------------------------------------------------------------------
/.php-cs-fixer.php:
--------------------------------------------------------------------------------
1 | true,
9 | // Each line of multi-line DocComments must have an asterisk [PSR-5] and must be aligned with the first one.
10 | // 'align_multiline_comment' => true,
11 | // Each element of an array must be indented exactly once.
12 | 'array_indentation' => true,
13 | // PHP arrays should be declared using the configured syntax.
14 | 'array_syntax' => ['syntax' => 'short'],
15 | // Binary operators should be surrounded by space as configured.
16 | 'binary_operator_spaces' => true,
17 | // Ensure there is no code on the same line as the PHP open tag and it is followed by a blank line.
18 | 'blank_line_after_opening_tag' => true,
19 | // An empty line feed must precede any configured statement.
20 | 'blank_line_before_statement' => true,
21 | // A single space or none should be between cast and variable.
22 | 'cast_spaces' => true,
23 | // Class, trait and interface elements must be separated with one blank line.
24 | 'class_attributes_separation' => true,
25 | // Remove extra spaces in a nullable typehint.
26 | 'compact_nullable_typehint' => true,
27 | // Concatenation should be spaced according configuration.
28 | 'concat_space' => ['spacing' => 'one'],
29 | // Add curly braces to indirect variables to make them clear to understand.
30 | // Requires PHP >= 7.0.
31 | 'explicit_indirect_variable' => true,
32 | // Converts implicit variables into explicit ones in double-quoted strings or heredoc syntax.
33 | 'explicit_string_variable' => true,
34 | // Transforms imported FQCN parameters and return types in function arguments to short version.
35 | 'fully_qualified_strict_types' => true,
36 | // Add missing space between function's argument and its typehint.
37 | 'function_typehint_space' => true,
38 | // Pre- or post-increment and decrement operators should be used if possible.
39 | 'increment_style' => ['style' => 'post'],
40 | // Ensure there is no code on the same line as the PHP open tag.
41 | 'linebreak_after_opening_tag' => true,
42 | // Cast should be written in lower case.
43 | 'lowercase_cast' => true,
44 | // Class static references `self`, `static` and `parent` MUST be in lower case.
45 | 'lowercase_static_reference' => true,
46 | // Magic constants should be referred to using the correct casing.
47 | 'magic_constant_casing' => true,
48 | // Magic method definitions and calls must be using the correct casing.
49 | 'magic_method_casing' => true,
50 | // Method chaining MUST be properly indented.
51 | // Method chaining with different levels of indentation is not supported.
52 | 'method_chaining_indentation' => true,
53 | // DocBlocks must start with two asterisks, multiline comments must start with a single asterisk, after the opening slash.
54 | // Both must end with a single asterisk before the closing slash.
55 | 'multiline_comment_opening_closing' => true,
56 | // Forbid multi-line whitespace before the closing semicolon or move the semicolon to the new line for chained calls.
57 | 'multiline_whitespace_before_semicolons' => true,
58 | // Function defined by PHP should be called using the correct casing.
59 | 'native_function_casing' => true,
60 | // All instances created with new keyword must be followed by braces.
61 | 'new_with_braces' => true,
62 | // Replace control structure alternative syntax to use braces.
63 | 'no_alternative_syntax' => true,
64 | // There should be no empty lines after class opening brace.
65 | 'no_blank_lines_after_class_opening' => true,
66 | // There should not be blank lines between docblock and the documented element.
67 | 'no_blank_lines_after_phpdoc' => true,
68 | // There should not be empty PHPDoc blocks.
69 | 'no_empty_phpdoc' => true,
70 | // Remove useless semicolon statements.
71 | 'no_empty_statement' => true,
72 | // Removes extra blank lines and/or blank lines following configuration.
73 | 'no_extra_blank_lines' => ['tokens' => ['break', 'continue', 'curly_brace_block', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'throw', 'use', 'use_trait', 'switch', 'case', 'default']],
74 | // Remove leading slashes in `use` clauses.
75 | 'no_leading_import_slash' => true,
76 | // The namespace declaration line shouldn't contain leading whitespace.
77 | 'no_leading_namespace_whitespace' => true,
78 | // Operator `=>` should not be surrounded by multi-line whitespaces.
79 | 'no_multiline_whitespace_around_double_arrow' => true,
80 | // Short cast `bool` using double exclamation mark should not be used.
81 | 'no_short_bool_cast' => true,
82 | // Single-line whitespace before closing semicolon are prohibited.
83 | 'no_singleline_whitespace_before_semicolons' => true,
84 | // There MUST NOT be spaces around offset braces.
85 | 'no_spaces_around_offset' => true,
86 | // Remove trailing commas in list function calls.
87 | 'no_trailing_comma_in_list_call' => true,
88 | // PHP single-line arrays should not have trailing comma.
89 | 'no_trailing_comma_in_singleline_array' => true,
90 | // Removes unneeded parentheses around control statements.
91 | 'no_unneeded_control_parentheses' => true,
92 | // Unused `use` statements must be removed.
93 | 'no_unused_imports' => true,
94 | // There should not be useless `else` cases.
95 | 'no_useless_else' => true,
96 | // There should not be an empty `return` statement at the end of a function.
97 | 'no_useless_return' => true,
98 | // In array declaration, there MUST NOT be a whitespace before each comma.
99 | 'no_whitespace_before_comma_in_array' => true,
100 | // Remove trailing whitespace at the end of blank lines.
101 | 'no_whitespace_in_blank_line' => true,
102 | // Array index should always be written by using square braces.
103 | 'normalize_index_brace' => true,
104 | // Logical NOT operators (`!`) should have one trailing whitespace.
105 | 'not_operator_with_successor_space' => true,
106 | // There should not be space before or after object `T_OBJECT_OPERATOR` `->`.
107 | 'object_operator_without_whitespace' => true,
108 | // Ordering `use` statements.
109 | 'ordered_imports' => ['sort_algorithm' => 'alpha'],
110 | // Enforce camel (or snake) case for PHPUnit test methods, following configuration.
111 | 'php_unit_method_casing' => ['case' => 'snake_case'],
112 | // All items of the given phpdoc tags must be either left-aligned or (by default) aligned vertically.
113 | 'phpdoc_align' => ['align' => 'left'],
114 | // PHPDoc annotation descriptions should not be a sentence.
115 | 'phpdoc_annotation_without_dot' => true,
116 | // Docblocks should have the same indentation as the documented subject.
117 | 'phpdoc_indent' => true,
118 | // Fix PHPDoc inline tags, make `@inheritdoc` always inline.
119 | // `@access` annotations should be omitted from PHPDoc.
120 | 'phpdoc_no_access' => true,
121 | // No alias PHPDoc tags should be used.
122 | 'phpdoc_no_alias_tag' => true,
123 | // `@package` and `@subpackage` annotations should be omitted from PHPDoc.
124 | 'phpdoc_no_package' => true,
125 | // Classy that does not inherit must not have `@inheritdoc` tags.
126 | 'phpdoc_no_useless_inheritdoc' => true,
127 | // Annotations in PHPDoc should be ordered so that `@param` annotations come first, then `@throws` annotations, then `@return` annotations.
128 | 'phpdoc_order' => true,
129 | // The type of `@return` annotations of methods returning a reference to itself must the configured one.
130 | 'phpdoc_return_self_reference' => true,
131 | // Scalar types should always be written in the same form.
132 | // `int` not `integer`, `bool` not `boolean`, `float` not `real` or `double`.
133 | 'phpdoc_scalar' => true,
134 | // Annotations in PHPDoc should be grouped together so that annotations of the same type immediately follow each other, and annotations of a different type are separated by a single blank line.
135 | 'phpdoc_separation' => true,
136 | // Single line `@var` PHPDoc should have proper spacing.
137 | 'phpdoc_single_line_var_spacing' => true,
138 | // PHPDoc summary should end in either a full stop, exclamation mark, or question mark.
139 | 'phpdoc_summary' => true,
140 | // Docblocks should only be used on structural elements.
141 | 'phpdoc_to_comment' => true,
142 | // PHPDoc should start and end with content, excluding the very first and last line of the docblocks.
143 | 'phpdoc_trim' => true,
144 | // Removes extra blank lines after summary and after description in PHPDoc.
145 | 'phpdoc_trim_consecutive_blank_line_separation' => true,
146 | // The correct case must be used for standard PHP types in PHPDoc.
147 | 'phpdoc_types' => true,
148 | // Sorts PHPDoc types.
149 | 'phpdoc_types_order' => ['null_adjustment' => 'always_last'],
150 | // `@var` and `@type` annotations should not contain the variable name.
151 | 'phpdoc_var_without_name' => true,
152 | // There should be one or no space before colon, and one space after it in return type declarations, according to configuration.
153 | 'return_type_declaration' => ['space_before' => 'one'],
154 | // Instructions must be terminated with a semicolon.
155 | 'semicolon_after_instruction' => true,
156 | // Cast `(boolean)` and `(integer)` should be written as `(bool)` and `(int)`, `(double)` and `(real)` as `(float)`, `(binary)` as `(string)`.
157 | 'short_scalar_cast' => true,
158 | // There should be exactly one blank line before a namespace declaration.
159 | 'single_blank_line_before_namespace' => true,
160 | // Convert double quotes to single quotes for simple strings.
161 | 'single_quote' => ['strings_containing_single_quote_chars' => true],
162 | // Fix whitespace after a semicolon.
163 | 'space_after_semicolon' => true,
164 | // Increment and decrement operators should be used if possible.
165 | 'standardize_increment' => true,
166 | // Replace all `<>` with `!=`.
167 | 'standardize_not_equals' => true,
168 | // Standardize spaces around ternary operator.
169 | 'ternary_operator_spaces' => true,
170 | // Use `null` coalescing operator `??` where possible.
171 | // Requires PHP >= 7.0.
172 | 'ternary_to_null_coalescing' => true,
173 | // PHP multi-line arrays should have a trailing comma.
174 | 'trailing_comma_in_multiline' => true,
175 | // Arrays should be formatted like function/method arguments, without leading or trailing single line space.
176 | 'trim_array_spaces' => true,
177 | // Unary operators should be placed adjacent to their operands.
178 | 'unary_operator_spaces' => true,
179 | // In array declaration, there MUST be a whitespace after each comma.
180 | 'whitespace_after_comma_in_array' => true,
181 | // Force Fully-Qualified Class Name in docblocks
182 | 'AdamWojs/phpdoc_force_fqcn_fixer' => true,
183 | ];
184 |
185 | $finder = Finder::create()
186 | ->notPath('bootstrap')
187 | ->notPath('storage')
188 | ->notPath('vendor')
189 | ->in(__DIR__)
190 | ->name('*.php')
191 | ->name('_ide_helper')
192 | ->notName('*.blade.php')
193 | ->ignoreDotFiles(true)
194 | ->ignoreVCS(true);
195 |
196 | return (new Config())
197 | ->registerCustomFixers([
198 | new ForceFQCNFixer(),
199 | ])
200 | ->setRules($rules)
201 | ->setFinder($finder);
202 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to `laravel-swagger-ui` will be documented in this file
4 |
5 | ## 1.2.0 - 2025-03-05
6 |
7 | - Added: Laravel v12 support ([#42](https://github.com/wotzebra/laravel-swagger-ui/pull/42))
8 |
9 | ## 1.1.0 - 2024-12-12
10 |
11 | - Added: PHP 8.4 support ([#39](https://github.com/wotzebra/laravel-swagger-ui/pull/39))
12 | - Added: Option to set the server url that will be used in the swagger file ([#38](https://github.com/wotzebra/laravel-swagger-ui/pull/38))
13 |
14 | ## 1.0.0 - 2024-09-26
15 |
16 | - Changed: Change namespace from 'NextApps' to 'Wotz' ([#36](https://github.com/wotzebra/laravel-swagger-ui/pull/36))
17 |
18 | ## 0.10.1 - 2024-07-25
19 |
20 | - Added: Option to set page title ([#33](https://github.com/wotzebra/laravel-swagger-ui/pull/33))
21 |
22 | ## 0.10.0 - 2024-07-09
23 |
24 | - Added: Support swagger-ui's oauth2 redirect ([#32](https://github.com/wotzebra/laravel-swagger-ui/pull/32))
25 |
26 | ## 0.9.2 - 2024-03-20
27 |
28 | - Fixed: Use full url for swagger ui bundles urls ([#29](https://github.com/wotzebra/laravel-swagger-ui/pull/29))
29 |
30 | ## 0.9.1 - 2024-03-15
31 |
32 | - Added: Laravel 11 support ([#30](https://github.com/wotzebra/laravel-swagger-ui/pull/30))
33 |
34 | ## 0.9.0 - 2023-12-15
35 |
36 | - Added: PHP 8.3 support ([#25](https://github.com/wotzebra/laravel-swagger-ui/pull/25))
37 | - Added: Config option to set validator url ([#27](https://github.com/wotzebra/laravel-swagger-ui/pull/27))
38 |
39 | ## 0.8.2 - 2023-10-30
40 |
41 | - Added: Config option to add CSS to customize swagger-ui ([#24](https://github.com/wotzebra/laravel-swagger-ui/pull/24))
42 |
43 | ## 0.8.1 - 2023-10-30
44 |
45 | - Added: Allow base path to contain multiple segments ([#23](https://github.com/wotzebra/laravel-swagger-ui/pull/23))
46 |
47 | ## 0.8.0 - 2023-03-30
48 |
49 | - Added: Support for multiple API versions and multiple swagger routes and files ([#21](https://github.com/wotzebra/laravel-swagger-ui/pull/21))
50 |
51 | ## 0.7.0 - 2023-02-15
52 |
53 | - Added: PHP 8.2 and Laravel 10 support ([#20](https://github.com/wotzebra/laravel-swagger-ui/pull/20))
54 |
55 | ## 0.6.0 - 2022-05-12
56 |
57 | - Added: Middleware array to config file ([#14](https://github.com/wotzebra/laravel-swagger-ui/pull/14))
58 |
59 | ## 0.5.0 - 2022-02-25
60 |
61 | - Added: Support for external OpenAPI files ([#11](https://github.com/wotzebra/laravel-swagger-ui/pull/11))
62 |
63 | ## 0.4.0 - 2022-02-16
64 |
65 | - Added: PHP 8.1 and Laravel 9 support ([#10](https://github.com/wotzebra/laravel-swagger-ui/pull/10))
66 |
67 | ## 0.3.0 - 2021-10-03
68 |
69 | - Added: Support for OpenAPI YAML files ([#6](https://github.com/wotzebra/laravel-swagger-ui/pull/6))
70 | - Changed: Linting (and removal of docblocks) ([#7](https://github.com/wotzebra/laravel-swagger-ui/pull/7))
71 |
72 | ## 0.2.0 - 2021-02-15
73 |
74 | - Added: PHP 8 support and switch to github actions ([#3](https://github.com/wotzebra/laravel-swagger-ui/pull/3))
75 |
76 | ## 0.1.0 - 2020-10-16
77 |
78 | - Initial release
79 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Contributions are **welcome** and will be fully **credited**.
4 |
5 | Please read and understand the contribution guide before creating an issue or pull request.
6 |
7 | ## Etiquette
8 |
9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code
10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be
11 | extremely unfair for them to suffer abuse or anger for their hard work.
12 |
13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
14 | world that developers are civilized and selfless people.
15 |
16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
18 |
19 | ## Viability
20 |
21 | When requesting or submitting new features, first consider whether it might be useful to others. Open
22 | source projects are used by many developers, who may have entirely different needs to your own. Think about
23 | whether or not your feature is likely to be used by other users of the project.
24 |
25 | ## Procedure
26 |
27 | Before filing an issue:
28 |
29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
30 | - Check to make sure your feature suggestion isn't already present within the project.
31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
32 | - Check the pull requests tab to ensure that the feature isn't already in progress.
33 |
34 | Before submitting a pull request:
35 |
36 | - Check the codebase to ensure that your feature doesn't already exist.
37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
38 |
39 | ## Requirements
40 |
41 | If the project maintainer has any additional requirements, you will find them listed here.
42 |
43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
44 |
45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests.
46 |
47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
48 |
49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
50 |
51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
52 |
53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
54 |
55 | **Happy coding**!
56 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Next Apps
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Laravel Swagger UI
2 |
3 | [](https://packagist.org/packages/wotz/laravel-swagger-ui)
4 | [](https://packagist.org/packages/wotz/laravel-swagger-ui)
5 |
6 | This package makes it easy to make your project's Swagger (OpenAPI v3 JSON or YAML) file accessible in a Swagger UI right in your Laravel application.
7 |
8 | The Swagger UI will automatically use your current project environment. It will set your api's base url to the active base url. Possible oauth2 configuration, such as urls and client-id/client-secret, can also be injected in Swagger UI via the configuration file.
9 |
10 | ## Installation
11 |
12 | You can install the package via composer:
13 |
14 | ```bash
15 | composer require wotz/laravel-swagger-ui
16 | ```
17 |
18 | After installing Laravel Swagger UI, publish its service provider and configuration file using the `swagger-ui:install` Artisan command.
19 |
20 | ```bash
21 | php artisan swagger-ui:install
22 | ```
23 |
24 | ## Usage
25 |
26 | The Swagger UI is exposed at `/swagger`. By default, you will only be able to access it in the local environment. Within your `app/Providers/SwaggerUiServiceProvider.php` file, there is a `gate` method. This authorization gate controls access to Swagger UI in non-local environments. You can modify this gate as needed to restrict access to your Swagger UI and Swagger (OpenAPI v3) file:
27 |
28 | ```php
29 | /**
30 | * Register the Swagger UI gate.
31 | *
32 | * This gate determines who can access Swagger UI in non-local environments.
33 | *
34 | * @return void
35 | */
36 | protected function gate()
37 | {
38 | Gate::define('viewSwaggerUI', function ($user = null) {
39 | return in_array(optional($user)->email, [
40 | //
41 | ]);
42 | });
43 | }
44 | ```
45 |
46 | In the published `config/swagger-ui.php` file, you edit the path to the Swagger UI and the location of the Swagger (OpenAPI v3) file. By default, the package expects to find the OpenAPI file in 'resources/swagger' directory. You can also provide an url if the OpenAPI file is not present in the Laravel project itself.
47 | This is also where you can define multiple versions for the same api.
48 |
49 | ```php
50 | // in config/swagger-ui.php
51 |
52 | return [
53 | // ...
54 |
55 | 'path' => 'swagger',
56 |
57 | 'versions' => [
58 | 'v1' => resource_path('swagger/openapi.json')
59 | ],
60 |
61 | // ...
62 | ];
63 | ```
64 |
65 | By default the package will customize the server url and the oauth urls in the OpenAPI file to the base url of the Laravel application. This can be disabled in the config.
66 |
67 | ```php
68 | // in config/swagger-ui.php
69 |
70 | return [
71 | // ...
72 |
73 | 'modify_file' => true,
74 |
75 | // ...
76 | ];
77 | ```
78 |
79 | You can also set an oauth client ID and client secret. These values will be automatically prefilled in the authentication view in Swagger UI.
80 |
81 | ```php
82 | // in config/swagger-ui.php
83 |
84 | return [
85 | // ...
86 |
87 | 'oauth' => [
88 | 'token_path' => 'oauth/token',
89 | 'refresh_path' => 'oauth/token',
90 | 'authorization_path' => 'oauth/authorize',
91 |
92 | 'client_id' => env('SWAGGER_UI_OAUTH_CLIENT_ID'),
93 | 'client_secret' => env('SWAGGER_UI_OAUTH_CLIENT_SECRET'),
94 | ];
95 |
96 | // ...
97 | ];
98 | ```
99 |
100 | ### Testing
101 |
102 | ```bash
103 | composer test
104 | ```
105 |
106 | ## Linting
107 |
108 | ```bash
109 | composer lint
110 | ```
111 |
112 | ### Changelog
113 |
114 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
115 |
116 | ## Contributing
117 |
118 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
119 |
120 | ### Security
121 |
122 | If you discover any security related issues, please email gunther.debrauwer@whoownsthezebra.be instead of using the issue tracker.
123 |
124 | ## Credits
125 |
126 | - [Günther Debrauwer](https://github.com/gdebrauwer)
127 | - [All Contributors](../../contributors)
128 |
129 | ## License
130 |
131 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
132 |
--------------------------------------------------------------------------------
/UPGRADING.md:
--------------------------------------------------------------------------------
1 | # Upgrading
2 |
3 | ## From v0.10 to v1
4 |
5 | - Install `wotz/laravel-swagger-ui` instead of `nextapps/laravel-swagger-ui`
6 | - Replace all occurrences of `NextApps\SwaggerUi` namespace with new `Wotz\SwaggerUi` namespace
7 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "wotz/laravel-swagger-ui",
3 | "description": "Add Swagger UI to a Laravel application.",
4 | "keywords": [
5 | "laravel",
6 | "swagger",
7 | "swagger-ui",
8 | "openapi"
9 | ],
10 | "homepage": "https://github.com/wotzebra/laravel-swagger-ui",
11 | "license": "MIT",
12 | "type": "library",
13 | "authors": [
14 | {
15 | "name": "Günther Debrauwer",
16 | "email": "gunther.debrauwer@whoownsthezebra.be",
17 | "role": "Developer"
18 | }
19 | ],
20 | "require": {
21 | "php": "^8.1|^8.2|^8.3|^8.4",
22 | "ext-json": "*",
23 | "laravel/framework": "^9.0|^10.0|^11.0|^12.0"
24 | },
25 | "suggest": {
26 | "ext-yaml": "*"
27 | },
28 | "require-dev": {
29 | "adamwojs/php-cs-fixer-phpdoc-force-fqcn": "^2.0",
30 | "friendsofphp/php-cs-fixer": "^3.0",
31 | "guzzlehttp/guzzle": "^7.5",
32 | "jasonmccreary/laravel-test-assertions": "^2.3",
33 | "orchestra/testbench": "^7.0|^8.0|^9.0|^10.0",
34 | "phpunit/phpunit": "^9.5|^10.0|^11.5.3",
35 | "squizlabs/php_codesniffer": "^3.6"
36 | },
37 | "autoload": {
38 | "psr-4": {
39 | "Wotz\\SwaggerUi\\": "src"
40 | }
41 | },
42 | "autoload-dev": {
43 | "psr-4": {
44 | "Wotz\\SwaggerUi\\Tests\\": "tests"
45 | }
46 | },
47 | "scripts": {
48 | "test": "vendor/bin/phpunit",
49 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage",
50 | "lint": "vendor/bin/php-cs-fixer fix && vendor/bin/phpcs --colors --report-full",
51 | "lint-dry": "vendor/bin/php-cs-fixer fix --dry-run --diff-format=udiff && vendor/bin/phpcs --colors --report-full"
52 | },
53 | "config": {
54 | "sort-packages": true
55 | },
56 | "extra": {
57 | "laravel": {
58 | "providers": [
59 | "Wotz\\SwaggerUi\\SwaggerUiServiceProvider"
60 | ]
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/config/swagger-ui.php:
--------------------------------------------------------------------------------
1 | [
7 | [
8 | /*
9 | * The path where the swagger file is served.
10 | */
11 | 'path' => 'swagger',
12 |
13 | /*
14 | * The title of the page where the swagger file is served.
15 | */
16 | 'title' => env('APP_NAME') . ' - Swagger',
17 |
18 | /*
19 | * The versions of the swagger file. The key is the version name and the value is the path to the file.
20 | */
21 | 'versions' => [
22 | 'v1' => resource_path('swagger/openapi.json'),
23 | ],
24 |
25 | /*
26 | * The default version that is loaded when the route is accessed.
27 | */
28 | 'default' => 'v1',
29 |
30 | /*
31 | * The middleware that is applied to the route.
32 | */
33 | 'middleware' => [
34 | 'web',
35 | EnsureUserIsAuthorized::class,
36 | ],
37 |
38 | /*
39 | * Specify the validator URL. Set to false to disable validation.
40 | */
41 | 'validator_url' => env('SWAGGER_UI_VALIDATOR_URL'),
42 |
43 | /*
44 | * If enabled the file will be modified to set the server url and oauth urls.
45 | */
46 | 'modify_file' => true,
47 |
48 | /*
49 | * The server URL configuration for the swagger file.
50 | */
51 | 'server_url' => env('APP_URL'),
52 |
53 | /*
54 | * The oauth configuration for the swagger file.
55 | */
56 | 'oauth' => [
57 | 'token_path' => 'oauth/token',
58 | 'refresh_path' => 'oauth/token',
59 | 'authorization_path' => 'oauth/authorize',
60 |
61 | 'client_id' => env('SWAGGER_UI_OAUTH_CLIENT_ID'),
62 | 'client_secret' => env('SWAGGER_UI_OAUTH_CLIENT_SECRET'),
63 | ],
64 |
65 | /*
66 | * Path to a custom stylesheet file if you want to customize the look and feel of swagger-ui.
67 | * The content of the file will be read and added into a style-tag on the swagger-ui page.
68 | */
69 | 'stylesheet' => null,
70 | ],
71 | ],
72 | ];
73 |
--------------------------------------------------------------------------------
/phpcs.xml:
--------------------------------------------------------------------------------
1 |
2 |