Skip to content

Commit 49cd50e

Browse files
committed
Add message
1 parent 426fecb commit 49cd50e

File tree

5 files changed

+73
-4
lines changed

5 files changed

+73
-4
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,4 +779,3 @@ Professional support, consulting as well as software development services are av
779779
https://www.cebe.cc/en/contact
780780

781781
Development of this library is sponsored by [cebe.:cloud: "Your Professional Deployment Platform"](https://cebe.cloud).
782-

src/lib/generators/ControllersGenerator.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function generate():CodeFiles
5959
$controllerPath = $path;
6060
/**
6161
* @var RestAction|FractalAction $action
62-
**/
62+
**/
6363
$action = $actions[0];
6464
if ($action->prefix && !empty($action->prefixSettings)) {
6565
$controllerNamespace = trim($action->prefixSettings['namespace'], '\\');
@@ -126,15 +126,22 @@ protected function makeCustomController(
126126
];
127127
$reflection->addMethod('checkAccess', $params, AbstractMemberGenerator::FLAG_PUBLIC, '//TODO implement checkAccess');
128128
foreach ($abstractActions as $action) {
129+
130+
$responseHttpStatusCodes = '';
131+
foreach ($this->config->getOpenApi()->paths->getPaths()[$action->urlPath]->getOperations() as $verb => $operation) {
132+
if ($verb === strtolower($action->requestMethod)) {
133+
$responseHttpStatusCodes = implode(', ', array_keys($operation->responses->getResponses()));
134+
}
135+
}
136+
129137
$params = array_map(static function ($param) {
130138
return ['name' => $param];
131139
}, $action->getParamNames());
132-
133140
$reflection->addMethod(
134141
$action->actionMethodName,
135142
$params,
136143
AbstractMemberGenerator::FLAG_PUBLIC,
137-
'//TODO implement ' . $action->actionMethodName
144+
'// TODO implement ' . $action->actionMethodName . PHP_EOL . '// In order to conform with OpenAPI spec, response of this action must have one of the following HTTP status code: ' . $responseHttpStatusCodes
138145
);
139146
}
140147
$classFileGenerator->setClasses([$reflection]);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
return [
4+
'openApiPath' => '@specs/issue_fix/79_response_status_codes_are_not_the_codes_defined_in_spec/index.yml',
5+
'generateUrls' => false,
6+
'generateModels' => false,
7+
'excludeModels' => [
8+
'Error',
9+
],
10+
'generateControllers' => true,
11+
'generateMigrations' => false,
12+
'generateModelFaker' => false,
13+
];
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: 79_response_status_codes_are_not_the_codes_defined_in_spec
5+
paths:
6+
/mango/cake:
7+
get:
8+
responses:
9+
'200':
10+
description: The information
11+
'403':
12+
description: The information
13+
'404':
14+
description: The information
15+
post:
16+
responses:
17+
'201':
18+
description: The information
19+
'403':
20+
description: The information
21+
'404':
22+
description: The information
23+
'422':
24+
description: The information
25+
26+
components:
27+
schemas:
28+
Address:
29+
type: object
30+
description: desc
31+
properties:
32+
id:
33+
type: integer
34+
name:
35+
type: string
36+
maxLength: 64

tests/unit/IssueFixTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,4 +1014,18 @@ public function test22BugRulesRequiredIsGeneratedBeforeDefault()
10141014
]);
10151015
$this->checkFiles($actualFiles, $expectedFiles);
10161016
}
1017+
1018+
// https://github.com/php-openapi/yii2-openapi/issues/79
1019+
public function test79ResponseStatusCodesAreNotTheCodesDefinedInSpec()
1020+
{
1021+
$testFile = Yii::getAlias("@specs/issue_fix/79_response_status_codes_are_not_the_codes_defined_in_spec/index.php");
1022+
$this->runGenerator($testFile);
1023+
// $actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
1024+
// 'recursive' => true,
1025+
// ]);
1026+
// $expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/79_response_status_codes_are_not_the_codes_defined_in_spec/mysql"), [
1027+
// 'recursive' => true,
1028+
// ]);
1029+
// $this->checkFiles($actualFiles, $expectedFiles);
1030+
}
10171031
}

0 commit comments

Comments
 (0)