forked from thephpleague/openapi-psr7-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add writeOnly/readOnly keywords, nullable keyword
- Loading branch information
Showing
27 changed files
with
298 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* @author Dmitry Lezhnev <[email protected]> | ||
* Date: 01 May 2019 | ||
*/ | ||
declare(strict_types=1); | ||
|
||
|
||
namespace OpenAPIValidation\Schema\Keywords; | ||
|
||
|
||
use cebe\openapi\spec\Schema as CebeSchema; | ||
use OpenAPIValidation\Schema\Validator; | ||
|
||
abstract class BaseKeyword | ||
{ | ||
/** @var CebeSchema */ | ||
protected $parentSchema; | ||
/** @var Validator */ | ||
protected $parentSchemaValidator; | ||
|
||
/** | ||
* @param CebeSchema $parentSchema | ||
* @param Validator $parentSchemaValidator | ||
*/ | ||
public function __construct(CebeSchema $parentSchema, Validator $parentSchemaValidator) | ||
{ | ||
$this->parentSchema = $parentSchema; | ||
$this->parentSchemaValidator = $parentSchemaValidator; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* @author Dmitry Lezhnev <[email protected]> | ||
* Date: 01 May 2019 | ||
*/ | ||
declare(strict_types=1); | ||
|
||
|
||
namespace OpenAPIValidation\Schema\Keywords; | ||
|
||
|
||
use OpenAPIValidation\Schema\Exception\ValidationKeywordFailed; | ||
use Respect\Validation\Validator; | ||
|
||
class Descriminator extends BaseKeyword | ||
{ | ||
/** | ||
* The value of this keyword MUST be an array. This array SHOULD have | ||
* at least one element. Elements in the array SHOULD be unique. | ||
* | ||
* Elements in the array MAY be of any type, including null. | ||
* | ||
* An instance validates successfully against this keyword if its value | ||
* is equal to one of the elements in this keyword's array value. | ||
* | ||
* @param $data | ||
* @param array $enum | ||
*/ | ||
public function validate($data, array $enum): void | ||
{ | ||
try { | ||
Validator::arrayType()->assert($enum); | ||
Validator::trueVal()->assert(count($enum) >= 1); | ||
|
||
if (!in_array($data, $enum, true)) { | ||
throw new \Exception(sprintf("Value must be present in the enum")); | ||
} | ||
|
||
} catch (\Throwable $e) { | ||
throw ValidationKeywordFailed::fromKeyword("enum", $data, $e->getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* @author Dmitry Lezhnev <[email protected]> | ||
* Date: 01 May 2019 | ||
*/ | ||
declare(strict_types=1); | ||
|
||
|
||
namespace OpenAPIValidation\Schema\Keywords; | ||
|
||
|
||
use OpenAPIValidation\Schema\Exception\ValidationKeywordFailed; | ||
|
||
class Nullable extends BaseKeyword | ||
{ | ||
/** | ||
* Allows sending a null value for the defined schema. Default value is false. | ||
* | ||
* @param $data | ||
* @param bool $nullable | ||
*/ | ||
public function validate($data, bool $nullable): void | ||
{ | ||
try { | ||
if (!$nullable && ($data === null)) { | ||
throw new \Exception("Value cannot be null"); | ||
} | ||
|
||
|
||
} catch (\Throwable $e) { | ||
throw ValidationKeywordFailed::fromKeyword("nullable", $data, $e->getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.