Skip to content

Commit

Permalink
Add new properties to BaseValueDescribed (minimum, maximum, minLeng…
Browse files Browse the repository at this point in the history
…th, maxLength, nullable)
  • Loading branch information
digitv committed Sep 13, 2021
1 parent 5dc7f18 commit 82acc30
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Swagger yaml generator",
"keywords": ["api", "swagger", "open auth"],
"license": "MIT",
"version": "1.0.10",
"version": "1.0.11",
"authors": [
{
"name": "Digit",
Expand Down
28 changes: 26 additions & 2 deletions oa/BaseValueDescribed.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ abstract class BaseValueDescribed extends BaseAnnotation
* @var string Format for swagger
*/
public $format;
/**
* @var bool Value may be null
*/
public $nullable;
/**
* @var float|int Minimum value of number value
*/
public $minimum;
/**
* @var float|int Maximum value of number value
*/
public $maximum;
/**
* @var int Min length of string value
*/
public $minLength;
/**
* @var int Min length of string value
*/
public $maxLength;
/**
* @var array Array of possible values
*/
Expand Down Expand Up @@ -123,7 +143,11 @@ public function toArray()
$data = [
'type' => $swType,
];
$optional = ['format', 'name', 'required', 'example' => 'exampleProcessed', 'description', 'enum'];
$optional = [
'format', 'name', 'required', 'description', 'enum',
'nullable', 'minimum', 'maximum', 'minLength', 'maxLength',
'example' => 'exampleProcessed',
];
foreach ($optional as $arrKey => $optKey) {
$arrKey = is_numeric($arrKey) ? $optKey : $arrKey;
$optValue = $this->{$optKey};
Expand All @@ -146,7 +170,7 @@ public function toArray()
}
// Write example if needed
if ($this->isExampleRequired()
&& !isset($data['example'])
&& ! isset($data['example'])
&& ($example = $this->describer()->example($this->type, $this->name)) !== null
) {
$data['example'] = Arr::get($data, 'format') !== Variable::SW_FORMAT_BINARY ? $example : 'binary';
Expand Down

0 comments on commit 82acc30

Please sign in to comment.