Skip to content

Commit 34ab296

Browse files
committed
2 parents 716ca68 + b8bdbf9 commit 34ab296

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ Laravel Swagger Docs works based on recommended practices by Laravel. It will pa
3333
One thing to note is this library leans on being explicit. It will choose to include keys even if they have a default. For example it chooses to say a route has a deprecated value of false rather than leaving it out. I believe this makes reading the documentation easier by not leaving important information out. The file can be easily cleaned up afterwards if the user chooses to leave out the defaults.
3434

3535
### Command line
36-
Generating the swagger documentation is easy, simply run `php artisan laravel-swagger:generate` in your project root. The output of the command will be stored in your storage path linked in config file.
36+
Generating the swagger documentation is easy, simply run `php artisan swagger:generate` in your project root. The output of the command will be stored in your storage path linked in config file.
3737

38-
If you wish to generate docs for a subset of your routes, you can pass a filter using `--filter`, for example: `php artisan laravel-swagger:generate --filter="/api"`
38+
If you wish to generate docs for a subset of your routes, you can pass a filter using `--filter`, for example: `php artisan swagger:generate --filter="/api"`
3939

4040
You can also configure your swagger.php file to always generate schema when accessing Swagger UI or just by adding this line in your .env: `SWAGGER_GENERATE_ALWAYS=true`
4141

src/Definitions/DefinitionGenerator.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,23 @@ function generateSchemas(): array {
9494
->all();
9595

9696
$table = $obj->getTable();
97-
$list = Schema::getColumnListing($table);
97+
$list = Schema::connection($obj->getConnectionName())->getColumnListing($table);
9898
$list = array_diff($list, $obj->getHidden());
9999

100100
$properties = [];
101101
$required = [];
102102

103-
foreach ($list as $item) {
103+
/**
104+
* @var \Illuminate\Database\Connection
105+
*/
106+
$conn = $obj->getConnection();
107+
$prefix = $conn->getTablePrefix();
104108

105-
/**
106-
* @var object
107-
*/
108-
$conn = DB::connection();
109+
if ($prefix !== '') {
110+
$table = $prefix . $table;
111+
}
112+
113+
foreach ($list as $item) {
109114

110115
/**
111116
* @var \Doctrine\DBAL\Schema\Column

src/Parameters/BodyParametersGenerator.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php namespace Mezatsong\SwaggerDocs\Parameters;
22

3+
use Exception;
34
use Illuminate\Support\Arr;
45
use Mezatsong\SwaggerDocs\Parameters\Traits\GeneratesFromRules;
56
use Mezatsong\SwaggerDocs\Parameters\Interfaces\ParametersGenerator;
7+
use TypeError;
68

79
/**
810
* Class BodyParametersGenerator
@@ -42,12 +44,17 @@ public function getParameters(): array {
4244
$schema = [];
4345

4446
foreach ($this->rules as $parameter => $rule) {
45-
$parameterRules = $this->splitRules($rule);
46-
$nameTokens = explode('.', $parameter);
47-
$this->addToProperties($properties, $nameTokens, $parameterRules);
48-
49-
if ($this->isParameterRequired($parameterRules)) {
50-
$required[] = $parameter;
47+
try {
48+
$parameterRules = $this->splitRules($rule);
49+
$nameTokens = explode('.', $parameter);
50+
$this->addToProperties($properties, $nameTokens, $parameterRules);
51+
52+
if ($this->isParameterRequired($parameterRules)) {
53+
$required[] = $parameter;
54+
}
55+
} catch (TypeError $e) {
56+
$ruleStr = json_encode($rule);
57+
throw new Exception("Rule `$parameter => $ruleStr` is not well formated", 0, $e);
5158
}
5259
}
5360

@@ -159,3 +166,4 @@ protected function createNewPropertyObject(string $type, array $rules): array {
159166
return $propertyObject;
160167
}
161168
}
169+

0 commit comments

Comments
 (0)