Skip to content

Commit

Permalink
Merge branch 'main' into feat/improve-error-responses
Browse files Browse the repository at this point in the history
  • Loading branch information
romalytvynenko committed Jun 20, 2024
2 parents b51deeb + daf8ac9 commit cf4f883
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Support/OperationExtensions/RulesExtractor/RulesMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,29 @@ 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 $_)
{
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 $_)
Expand Down
15 changes: 15 additions & 0 deletions tests/ValidationRulesDocumentingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand Down

0 comments on commit cf4f883

Please sign in to comment.