Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
#156 Allow built-in type ANY (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-georgiev authored Sep 1, 2019
1 parent 1e8183c commit 0e431da
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/ApiDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ public static function getStraightForwardTypes()
'file',
'array',
'object',
'any',
];
}

Expand Down
14 changes: 10 additions & 4 deletions src/NamedParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class NamedParameter implements ArrayInstantiationInterface
{
// Type constants

/**
* @var string
*/
const TYPE_ANY = 'any';

/**
* @var string
*/
Expand Down Expand Up @@ -140,6 +145,7 @@ class NamedParameter implements ArrayInstantiationInterface
* @var string[]
*/
protected $validTypes = [
self::TYPE_ANY,
self::TYPE_STRING,
self::TYPE_NUMBER,
self::TYPE_INTEGER,
Expand Down Expand Up @@ -602,12 +608,12 @@ public function getMinimum()
*
* @param int $minimum
*
* @throws \Exception
* @throws \InvalidArgumentException
*/
public function setMinimum($minimum)
{
if (!\in_array($this->type, [self::TYPE_INTEGER, self::TYPE_NUMBER], true)) {
throw new \Exception('minimum can only be set on type "integer" or "number');
throw new \InvalidArgumentException('minimum can only be set on type "integer" or "number');
}

$this->minimum = (int) $minimum;
Expand All @@ -630,12 +636,12 @@ public function getMaximum()
*
* @param int $maximum
*
* @throws \Exception
* @throws \InvalidArgumentException
*/
public function setMaximum($maximum)
{
if (!\in_array($this->type, [self::TYPE_INTEGER, self::TYPE_NUMBER], true)) {
throw new \Exception('maximum can only be set on type "integer" or "number');
throw new \InvalidArgumentException('maximum can only be set on type "integer" or "number');
}

$this->maximum = (int) $maximum;
Expand Down
4 changes: 2 additions & 2 deletions src/Types/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static function createFromArray($name, array $data = [])
}

/**
* @param string $value
* @param array $value
* @return bool
*/
public function discriminate($value)
Expand Down Expand Up @@ -153,7 +153,7 @@ public function setProperties(array $properties)
* Returns a property by name
*
* @param string $name
* @return null|Type
* @return void|Type
*/
public function getPropertyByName($name)
{
Expand Down
1 change: 1 addition & 0 deletions tests/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ public function shouldThrowExceptionOnBadQueryParameter()
$this->assertEquals('invalid', $e->getType());
$this->assertEquals(
[
'any',
'string',
'number',
'integer',
Expand Down

0 comments on commit 0e431da

Please sign in to comment.