Skip to content

Commit

Permalink
fixes for the case when non-request class has rules method
Browse files Browse the repository at this point in the history
  • Loading branch information
romalytvynenko committed Mar 3, 2024
1 parent 407ab08 commit 9a15a33
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public function extract(Route $route)

/** @var Request $request */
$request = (new $requestClassName);

if (! method_exists($request, 'setMethod')) {
return [];
}

$request->setMethod($route->methods()[0]);

return $request->rules();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@ public function foo(ModelWithCustomRouteKeyName $model)
}
}

it('correctly handles not request class with rules method', function () {
$openApiDocument = generateForRoute(function () {
return RouteFacade::get('api/test/{model}', [Foo_RequestRulesTest_Controller::class, 'foo']);
});

expect($openApiDocument['paths']['/test/{model}']['get']['parameters'][0])
->toHaveKey('schema.type', 'integer')
->toHaveKey('description', 'The model ID');
});
class ModelWithRulesMethod extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'users';

public function rules()
{
return [];
}
}
class Foo_RequestRulesTest_Controller
{
public function foo(ModelWithRulesMethod $model)
{
}
}

it('handles custom key from route to determine model route key type', function () {
$openApiDocument = generateForRoute(function () {
return RouteFacade::get('api/test/{user:name}', [CustomKey_RequestEssentialsExtensionTest_Controller::class, 'foo']);
Expand Down

0 comments on commit 9a15a33

Please sign in to comment.