diff --git a/src/Support/OperationExtensions/RulesExtractor/RulesMapper.php b/src/Support/OperationExtensions/RulesExtractor/RulesMapper.php index f3e0a3f6..1d8269e4 100644 --- a/src/Support/OperationExtensions/RulesExtractor/RulesMapper.php +++ b/src/Support/OperationExtensions/RulesExtractor/RulesMapper.php @@ -24,14 +24,14 @@ public function __construct(TypeTransformer $openApiTransformer) $this->openApiTransformer = $openApiTransformer; } - public function string(Type $_) + public function string(Type $prevType) { - return new StringType; + return (new StringType)->addProperties($prevType); } - public function bool(Type $_) + public function bool(Type $prevType) { - return new BooleanType; + return (new BooleanType)->addProperties($prevType); } public function boolean(Type $_) @@ -39,14 +39,14 @@ public function boolean(Type $_) return $this->bool($_); } - public function numeric(Type $_) + public function numeric(Type $prevType) { - return new NumberType; + return (new NumberType)->addProperties($prevType); } - public function int(Type $_) + public function int(Type $prevType) { - return new IntegerType; + return (new IntegerType)->addProperties($prevType); } public function integer(Type $_) diff --git a/tests/ValidationRulesDocumentingTest.php b/tests/ValidationRulesDocumentingTest.php index 5c091f0b..c26b423b 100644 --- a/tests/ValidationRulesDocumentingTest.php +++ b/tests/ValidationRulesDocumentingTest.php @@ -212,6 +212,21 @@ ->toHaveKey('maxItems', 8); }); +it('documents nullable uri rule', function () { + $rules = [ + 'page_url' => ['nullable', 'url'], + ]; + + $params = app()->make(RulesToParameters::class, ['rules' => $rules])->handle(); + + expect($params = collect($params)->all()) + ->toHaveCount(1) + ->and($params[0]->schema->type) + ->toBeInstanceOf(\Dedoc\Scramble\Support\Generator\Types\StringType::class) + ->toHaveProperty('format', 'uri') + ->toHaveProperty('nullable', true); +}); + it('extracts rules from request->validate call', function () { RouteFacade::get('api/test', [ValidationRulesDocumenting_Test::class, 'index']);