Skip to content

Commit d89fe28

Browse files
committed
Refactor and fix failing test
1 parent 229c003 commit d89fe28

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

src/lib/generators/ControllersGenerator.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,19 @@ protected function makeCustomController(
126126
];
127127
$reflection->addMethod('checkAccess', $params, AbstractMemberGenerator::FLAG_PUBLIC, '//TODO implement checkAccess');
128128
foreach ($abstractActions as $action) {
129-
130129
$responseHttpStatusCodes = '';
131130
foreach ($this->config->getOpenApi()->paths->getPaths()[$action->urlPath]->getOperations() as $verb => $operation) {
132131
$codes = array_keys($operation->responses->getResponses());
133-
if ($verb === strtolower($action->requestMethod) && $codes !== [200]) {
132+
133+
$only200OrDefault = false;
134+
if ($codes === [200] || $codes === ['default']) {
135+
$only200OrDefault = true;
136+
}
137+
if (in_array('default', $codes) && in_array(200, $codes) && count($codes) === 2) {
138+
$only200OrDefault = true;
139+
}
140+
141+
if ($verb === strtolower($action->requestMethod) && !$only200OrDefault) {
134142
$responseHttpStatusCodes = implode(', ', $codes);
135143
}
136144
}

tests/specs/blog_v2/controllers/CommentController.php

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function actionListForPost($postId)
1818
public function actionCreateForPost($postId)
1919
{
2020
//TODO implement actionCreateForPost
21+
// In order to conform with OpenAPI spec, response of this action must have one of the following HTTP status code: 201, default
2122
}
2223

2324
public function actionViewForPost($slug, $id)
@@ -28,6 +29,7 @@ public function actionViewForPost($slug, $id)
2829
public function actionDeleteForPost($slug, $id)
2930
{
3031
//TODO implement actionDeleteForPost
32+
// In order to conform with OpenAPI spec, response of this action must have one of the following HTTP status code: 204
3133
}
3234

3335
public function actionUpdateForPost($slug, $id)

tests/specs/issue_fix/163_generator_crash_when_using_reference_inside_an_object/pgsql/controllers/ContactController.php

+2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ public function checkAccess($action, $model = null, $params = [])
1313
public function actionListForAccount($accountId)
1414
{
1515
//TODO implement actionListForAccount
16+
// In order to conform with OpenAPI spec, response of this action must have one of the following HTTP status code: 200, 403
1617
}
1718

1819
public function actionViewForAccount($accountId, $contactId)
1920
{
2021
//TODO implement actionViewForAccount
22+
// In order to conform with OpenAPI spec, response of this action must have one of the following HTTP status code: 200, 403
2123
}
2224

2325

tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/controllers/AccountController.php

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public function checkAccess($action, $model = null, $params = [])
1313
public function actionView($id)
1414
{
1515
//TODO implement actionView
16+
// In order to conform with OpenAPI spec, response of this action must have one of the following HTTP status code: 200, 404
1617
}
1718

1819

tests/specs/issue_fix/79_response_status_codes_are_not_the_codes_defined_in_spec/mysql/controllers/MangoController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ public function checkAccess($action, $model = null, $params = [])
1212

1313
public function actionCake()
1414
{
15-
// TODO implement actionCake
15+
//TODO implement actionCake
1616
// In order to conform with OpenAPI spec, response of this action must have one of the following HTTP status code: 200, 403, 404
1717
}
1818

1919
public function actionCreateCake()
2020
{
21-
// TODO implement actionCreateCake
21+
//TODO implement actionCreateCake
2222
// In order to conform with OpenAPI spec, response of this action must have one of the following HTTP status code: 201, 403, 404, 422
2323
}
2424

0 commit comments

Comments
 (0)