-
Notifications
You must be signed in to change notification settings - Fork 45
#158: ability to generate documentation for invokable controllers #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
#158: ability to generate documentation for invokable controllers #159
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yogyrton please cover new code by autotests
src/Services/SwaggerService.php
Outdated
@@ -644,7 +644,7 @@ public function getConcreteRequest() | |||
$explodedController = explode('@', $controller); | |||
|
|||
$class = $explodedController[0]; | |||
$method = $explodedController[1]; | |||
$method = $explodedController[1] ?? '__invoke'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$method = $explodedController[1] ?? '__invoke'; | |
$method = Arr::get($explodedController, 1, '__invoke'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not fixed
|
src/Services/SwaggerService.php
Outdated
@@ -644,7 +644,7 @@ public function getConcreteRequest() | |||
$explodedController = explode('@', $controller); | |||
|
|||
$class = $explodedController[0]; | |||
$method = $explodedController[1]; | |||
$method = $explodedController[1] ?? '__invoke'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not fixed
tests/TestCase.php
Outdated
return $request->setRouteResolver(function () use ($uri, $request, $controllerMethod, $routeConditions) { | ||
return $request->setRouteResolver(function () use ($isInvokeController, $uri, $request, $controllerMethod, $routeConditions) { | ||
$action = $isInvokeController | ||
? TestInvokableController::class . '@__invoke' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for invokable controller the action should be a controller name only
? TestInvokableController::class . '@__invoke' | |
? TestInvokableController::class |
|
||
class TestInvokableController | ||
{ | ||
public function __invoke(TestEmptyRequest $request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we use already existed mock request?
tests/TestCase.php
Outdated
$headers = [], | ||
$routeConditions = [], | ||
$controllerMethod = 'test', | ||
$isInvokeController = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not good solution make it as argument, cause we already has the controllerMethod argument which will onflict with this one. Please implement separate method generateInvokableRequest
simple helper
|
$service = app(SwaggerService::class); | ||
|
||
$request = $this->generateRequest( | ||
type: 'get', | ||
uri: 'users', | ||
controllerMethod: '__invoke', | ||
); | ||
|
||
$response = $this->generateResponse('example_success_user_response.json', 200, [ | ||
'Content-type' => 'application/json', | ||
]); | ||
|
||
$service->addData($request, $response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$service = app(SwaggerService::class); | |
$request = $this->generateRequest( | |
type: 'get', | |
uri: 'users', | |
controllerMethod: '__invoke', | |
); | |
$response = $this->generateResponse('example_success_user_response.json', 200, [ | |
'Content-type' => 'application/json', | |
]); | |
$service->addData($request, $response); | |
$request = $this->generateRequest( | |
type: 'get', | |
uri: 'users', | |
controllerMethod: '__invoke', | |
); | |
$response = $this->generateResponse('example_success_user_response.json', 200, [ | |
'Content-type' => 'application/json', | |
]); | |
app(SwaggerService::class)->addData($request, $response); |
@@ -10,6 +10,7 @@ | |||
use Orchestra\Testbench\TestCase as BaseTest; | |||
use RonasIT\AutoDoc\AutoDocServiceProvider; | |||
use RonasIT\AutoDoc\Tests\Support\Mock\TestController; | |||
use RonasIT\AutoDoc\Tests\Support\Mock\TestInvokableController; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
$type, | ||
$uri, | ||
$data = [], | ||
$pathParams = [], | ||
$headers = [], | ||
$routeConditions = [], | ||
$controllerMethod = 'test', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add typehints
#158