Skip to content

Commit

Permalink
Merge pull request #324 from dedoc/304-cannot-generate-request-docume…
Browse files Browse the repository at this point in the history
…ntation-call-to-undefined-method-appmodelsusersetmethod

Fixed the case when non-request class had rules method which resulted in error when extracting validation rules
  • Loading branch information
romalytvynenko authored Mar 3, 2024
2 parents 407ab08 + 9a15a33 commit f0331d5
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 f0331d5

Please sign in to comment.