Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#45: Add swagger spec validator to validate temp and additional doc format #82

Merged
merged 28 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
65982dc
feat: added swagger format validation when getting tmp doc file and g…
vitgrams Apr 5, 2023
25dcf9a
feat: improved validation mechanism and moved spec validation logic i…
vitgrams Apr 9, 2023
c46872d
fix: minor fixes;
vitgrams Apr 12, 2023
801549a
tests: added new test cases;
vitgrams Apr 14, 2023
30a7710
fix: minor fixes;
vitgrams Apr 17, 2023
da20b81
style: Format code with php-cs-fixer
deepsource-autofix[bot] Apr 17, 2023
9450fad
fix: fixed refs validation;
vitgrams Apr 18, 2023
b057d01
fix: fixed composer.lock;
vitgrams Apr 18, 2023
a1db0a2
fix: minor fixes;
vitgrams Apr 19, 2023
371a82c
fix: fixed code style, added test cases;
vitgrams Apr 24, 2023
1699855
style: fix code-style issue
Goodmain Sep 24, 2023
29b4d52
style: format code with PHP CS Fixer
deepsource-autofix[bot] Sep 24, 2023
bd9bdaa
Merge branch 'master' into 45_fix_exception_when_setting_invalid_addi…
Goodmain Sep 24, 2023
f94003a
Merge remote-tracking branch 'origin/45_fix_exception_when_setting_in…
Goodmain Sep 24, 2023
e00022f
test: fix tests after merge
Goodmain Sep 25, 2023
1d8a9cb
style: fix code-style issues
Goodmain Sep 25, 2023
de6fefb
style: format code with PHP CS Fixer
deepsource-autofix[bot] Sep 25, 2023
b672b96
style: fix code-style issues
Goodmain Sep 25, 2023
2b05267
Merge remote-tracking branch 'origin/45_fix_exception_when_setting_in…
Goodmain Sep 25, 2023
1b7fb35
test: increase code coverage
Goodmain Sep 25, 2023
1ef59da
refactor: remove not necessary function
Goodmain Sep 25, 2023
9ec90bf
style: fix code-style issues
Goodmain Sep 25, 2023
7a4c281
test: increase code coverage
Goodmain Sep 26, 2023
7d65f18
refactor: change code according to the comments
Goodmain Sep 27, 2023
4e1adb8
refactor: change code according to the comments
Goodmain Sep 27, 2023
f2503a9
refactor: change code according to the comments
Goodmain Sep 28, 2023
1e5a1fc
Update tests/SwaggerServiceTest.php
DenTray Oct 2, 2023
9b84277
Update tests/SwaggerServiceTest.php
DenTray Oct 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"require": {
"php": ">=7.3.0",
"laravel/framework": ">=5.3.0",
"phpunit/phpunit": ">=7.0"
"phpunit/phpunit": ">=7.0",
"ext-json": "*"
},
"require-dev": {
"orchestra/testbench": "^6.25",
Expand Down
209 changes: 95 additions & 114 deletions composer.lock

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions config/auto-doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
| Documentation Template
|--------------------------------------------------------------------------
|
| You can use your custom documentation view
| You can use your custom documentation view.
*/
'description' => 'auto-doc::swagger-description',
'version' => '0.0.0',
Expand All @@ -54,9 +54,6 @@
'url' => ''
]
],
'swagger' => [
'version' => '2.0'
],

/*
|--------------------------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions src/Exceptions/SpecValidation/DuplicateFieldException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace RonasIT\Support\AutoDoc\Exceptions\SpecValidation;

class DuplicateFieldException extends InvalidSwaggerSpecException
{
public function __construct(string $fieldName, array $fieldValue)
{
$fieldValueString = implode(', ', $fieldValue);

parent::__construct("Found multiple fields '{$fieldName}' with values: {$fieldValueString}.");
}
}
11 changes: 11 additions & 0 deletions src/Exceptions/SpecValidation/DuplicateParamException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace RonasIT\Support\AutoDoc\Exceptions\SpecValidation;

class DuplicateParamException extends InvalidSwaggerSpecException
{
public function __construct(string $in, string $name, string $operationId)
{
parent::__construct("Operation '{$operationId}' has multiple in:{$in} parameters with name:{$name}.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace RonasIT\Support\AutoDoc\Exceptions\SpecValidation;

class DuplicatePathPlaceholderException extends InvalidSwaggerSpecException
{
public function __construct(array $placeholders, string $path)
{
$placeholdersString = implode(', ', $placeholders);

parent::__construct("Path '{$path}' has multiple path placeholders with name: {$placeholdersString}.");
}
}
16 changes: 16 additions & 0 deletions src/Exceptions/SpecValidation/InvalidFieldValueException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace RonasIT\Support\AutoDoc\Exceptions\SpecValidation;

class InvalidFieldValueException extends InvalidSwaggerSpecException
{
public function __construct(string $fieldName, array $allowedValues, array $invalidValues)
{
$allowedValuesString = implode(', ', $allowedValues);
$invalidValuesString = implode(', ', $invalidValues);

parent::__construct(
"Field '{$fieldName}' has an invalid value: {$invalidValuesString}. Allowed values: {$allowedValuesString}."
);
}
}
11 changes: 11 additions & 0 deletions src/Exceptions/SpecValidation/InvalidPathException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace RonasIT\Support\AutoDoc\Exceptions\SpecValidation;

class InvalidPathException extends InvalidSwaggerSpecException
{
public function __construct(string $path)
{
parent::__construct("Incorrect '{$path}'. Paths should only have path names that starts with `/`.");
}
}
14 changes: 14 additions & 0 deletions src/Exceptions/SpecValidation/InvalidStatusCodeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace RonasIT\Support\AutoDoc\Exceptions\SpecValidation;

class InvalidStatusCodeException extends InvalidSwaggerSpecException
{
public function __construct(string $responseId)
{
parent::__construct(
"Operation at '{$responseId}' should only have three-digit status codes, `default`, "
. "and vendor extensions (`x-*`) as properties."
);
}
}
13 changes: 13 additions & 0 deletions src/Exceptions/SpecValidation/InvalidSwaggerSpecException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace RonasIT\Support\AutoDoc\Exceptions\SpecValidation;

use Exception;

class InvalidSwaggerSpecException extends Exception
{
public function __construct($message = '')
{
parent::__construct('Validation failed. '. $message);
}
}
15 changes: 15 additions & 0 deletions src/Exceptions/SpecValidation/InvalidSwaggerVersionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace RonasIT\Support\AutoDoc\Exceptions\SpecValidation;

use RonasIT\Support\AutoDoc\Services\SwaggerService;

class InvalidSwaggerVersionException extends InvalidSwaggerSpecException
{
public function __construct(string $version)
{
$expectedVersion = SwaggerService::SWAGGER_VERSION;

parent::__construct("Unrecognized Swagger version '{$version}'. Expected {$expectedVersion}.");
}
}
11 changes: 11 additions & 0 deletions src/Exceptions/SpecValidation/MissingExternalRefException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace RonasIT\Support\AutoDoc\Exceptions\SpecValidation;

class MissingExternalRefException extends InvalidSwaggerSpecException
{
public function __construct(string $ref, string $filename)
{
parent::__construct("Ref '{$ref}' is used in \$ref but not defined in '{$filename}' file.");
}
}
13 changes: 13 additions & 0 deletions src/Exceptions/SpecValidation/MissingFieldException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace RonasIT\Support\AutoDoc\Exceptions\SpecValidation;

class MissingFieldException extends InvalidSwaggerSpecException
{
public function __construct(array $missingFields, string $parentField = null)
{
$fieldsString = implode(', ', $missingFields);

parent::__construct("'{$parentField}' should have required fields: {$fieldsString}.");
}
}
11 changes: 11 additions & 0 deletions src/Exceptions/SpecValidation/MissingLocalRefException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace RonasIT\Support\AutoDoc\Exceptions\SpecValidation;

class MissingLocalRefException extends InvalidSwaggerSpecException
{
public function __construct(string $ref, string $parentField)
{
parent::__construct("Ref '{$ref}' is used in \$ref but not defined in '{$parentField}' field.");
}
}
13 changes: 13 additions & 0 deletions src/Exceptions/SpecValidation/MissingPathParamException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace RonasIT\Support\AutoDoc\Exceptions\SpecValidation;

class MissingPathParamException extends InvalidSwaggerSpecException
{
public function __construct(string $operationId, array $placeholders)
{
$placeholdersString = implode(', ', $placeholders);

parent::__construct("Operation '{$operationId}' has no params for placeholders: {$placeholdersString}.");
}
}
13 changes: 13 additions & 0 deletions src/Exceptions/SpecValidation/MissingPathPlaceholderException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace RonasIT\Support\AutoDoc\Exceptions\SpecValidation;

class MissingPathPlaceholderException extends InvalidSwaggerSpecException
{
public function __construct(string $operationId, array $params)
{
$paramsString = implode(', ', $params);

parent::__construct("Operation '{$operationId}' has no placeholders for params: {$paramsString}.");
}
}
11 changes: 11 additions & 0 deletions src/Exceptions/SpecValidation/MissingRefFileException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace RonasIT\Support\AutoDoc\Exceptions\SpecValidation;

class MissingRefFileException extends InvalidSwaggerSpecException
{
public function __construct(string $filename)
{
parent::__construct("Filename '{$filename}' is used in \$ref but file doesn't exist.");
}
}
Loading