Skip to content

Commit

Permalink
date rule support
Browse files Browse the repository at this point in the history
  • Loading branch information
romalytvynenko committed Feb 12, 2025
1 parent 2eaa33c commit f1710f9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,13 @@ public function url(Type $type)

return $type->format('uri');
}

public function date(Type $type)
{
if ($type instanceof UnknownType) {
$type = $this->string($type);
}

return $type->format('date-time');
}
}
14 changes: 14 additions & 0 deletions tests/ValidationRulesDocumentingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,20 @@ function validationRulesToDocumentationWithDeep($rulesToParameters)
->toHaveProperty('nullable', true);
});

it('documents date rule', function () {
$rules = [
'some_date' => 'date',
];

$params = ($this->buildRulesToParameters)($rules)->handle();

expect($params = collect($params)->all())
->toHaveCount(1)
->and($params[0]->schema->type)
->toBeInstanceOf(\Dedoc\Scramble\Support\Generator\Types\StringType::class)
->toHaveProperty('format', 'date-time');
});

it('extracts rules from request->validate call', function () {
RouteFacade::get('api/test', [ValidationRulesDocumenting_Test::class, 'index']);

Expand Down

0 comments on commit f1710f9

Please sign in to comment.