diff --git a/src/Support/Generator/Types/ArrayType.php b/src/Support/Generator/Types/ArrayType.php index be81dfa4..0f864e25 100644 --- a/src/Support/Generator/Types/ArrayType.php +++ b/src/Support/Generator/Types/ArrayType.php @@ -12,11 +12,11 @@ class ArrayType extends Type /** @var Type|Schema */ public $prefixItems = []; - private $minItems = null; + public $minItems = null; - private $maxItems = null; + public $maxItems = null; - private $additionalItems = null; + public $additionalItems = null; public function __construct() { diff --git a/src/Support/Generator/Types/NumberType.php b/src/Support/Generator/Types/NumberType.php index 4d560fe5..fd11bf56 100644 --- a/src/Support/Generator/Types/NumberType.php +++ b/src/Support/Generator/Types/NumberType.php @@ -4,9 +4,9 @@ class NumberType extends Type { - private $min = null; + public $min = null; - private $max = null; + public $max = null; public function __construct($type = 'number') { diff --git a/src/Support/Generator/Types/StringType.php b/src/Support/Generator/Types/StringType.php index ea326094..ee863ca3 100644 --- a/src/Support/Generator/Types/StringType.php +++ b/src/Support/Generator/Types/StringType.php @@ -4,8 +4,34 @@ class StringType extends Type { + public $min = null; + + public $max = null; + public function __construct() { parent::__construct('string'); } + + public function setMin($min) + { + $this->min = $min; + + return $this; + } + + public function setMax($max) + { + $this->max = $max; + + return $this; + } + + public function toArray() + { + return array_merge(parent::toArray(), array_filter([ + 'minLength' => $this->min, + 'maxLength' => $this->max, + ], fn ($v) => $v !== null)); + } } diff --git a/src/Support/OperationExtensions/RulesExtractor/RulesMapper.php b/src/Support/OperationExtensions/RulesExtractor/RulesMapper.php index 1d8269e4..ac47f824 100644 --- a/src/Support/OperationExtensions/RulesExtractor/RulesMapper.php +++ b/src/Support/OperationExtensions/RulesExtractor/RulesMapper.php @@ -115,7 +115,11 @@ public function required(Type $type) public function min(Type $type, $params) { - if ($type instanceof NumberType || $type instanceof ArrayType) { + if ( + $type instanceof NumberType + || $type instanceof ArrayType + || $type instanceof StringType + ) { $type->setMin((float) $params[0]); } @@ -124,7 +128,11 @@ public function min(Type $type, $params) public function max(Type $type, $params) { - if ($type instanceof NumberType || $type instanceof ArrayType) { + if ( + $type instanceof NumberType + || $type instanceof ArrayType + || $type instanceof StringType + ) { $type->setMax((float) $params[0]); }