Skip to content

#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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

yogyrton
Copy link
Contributor

@yogyrton yogyrton commented Jan 17, 2025

Copy link
Collaborator

@DenTray DenTray left a 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

@@ -644,7 +644,7 @@ public function getConcreteRequest()
$explodedController = explode('@', $controller);

$class = $explodedController[0];
$method = $explodedController[1];
$method = $explodedController[1] ?? '__invoke';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$method = $explodedController[1] ?? '__invoke';
$method = Arr::get($explodedController, 1, '__invoke');

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not fixed

@DenTray DenTray assigned yogyrton and unassigned DenTray Jan 22, 2025
@@ -644,7 +644,7 @@ public function getConcreteRequest()
$explodedController = explode('@', $controller);

$class = $explodedController[0];
$method = $explodedController[1];
$method = $explodedController[1] ?? '__invoke';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not fixed

return $request->setRouteResolver(function () use ($uri, $request, $controllerMethod, $routeConditions) {
return $request->setRouteResolver(function () use ($isInvokeController, $uri, $request, $controllerMethod, $routeConditions) {
$action = $isInvokeController
? TestInvokableController::class . '@__invoke'
Copy link
Collaborator

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

Suggested change
? TestInvokableController::class . '@__invoke'
? TestInvokableController::class


class TestInvokableController
{
public function __invoke(TestEmptyRequest $request)
Copy link
Collaborator

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?

$headers = [],
$routeConditions = [],
$controllerMethod = 'test',
$isInvokeController = false,
Copy link
Collaborator

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

Copy link

sonarqubecloud bot commented Apr 4, 2025

@NikitaYakovlev NikitaYakovlev assigned DenTray and unassigned yogyrton Apr 4, 2025
Comment on lines +927 to +939
$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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Comment on lines +119 to +125
$type,
$uri,
$data = [],
$pathParams = [],
$headers = [],
$routeConditions = [],
$controllerMethod = 'test',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add typehints

@DenTray DenTray assigned yogyrton and unassigned DenTray Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants