Skip to content

Commit bbefd8e

Browse files
committed
Fix TODO
1 parent df315d4 commit bbefd8e

File tree

6 files changed

+210
-24
lines changed

6 files changed

+210
-24
lines changed

src/lib/items/FractalAction.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,19 @@ public function getRoute():string
104104

105105
public function getOptionsRoute():string
106106
{
107-
//@TODO: re-check
108107
if ($this->prefix && !empty($this->prefixSettings)) {
109-
// $prefix = $this->prefixSettings['module'] ?? $this->prefix;
110108
if (isset($this->prefixSettings['module'])) {
111109
$prefix = $this->prefixSettings['module'];
112-
return trim($prefix, '/') . '/' . $this->controllerId . '/options';
110+
return static::finalOptionsRoute($prefix, $this->controllerId);
113111
} elseif (isset($this->prefixSettings['namespace']) && str_contains($this->prefixSettings['namespace'], '\modules\\')) {
114112
$prefix = static::computeModule('\\', $this->prefixSettings['namespace']);
115113
if ($prefix) {
116-
return trim($prefix, '/') . '/' . $this->controllerId . '/options';
114+
return static::finalOptionsRoute($prefix, $this->controllerId);
117115
}
118116
} elseif (isset($this->prefixSettings['path']) && str_contains($this->prefixSettings['path'], '/modules/')) {
119117
$prefix = static::computeModule('/', $this->prefixSettings['path']);
120118
if ($prefix) {
121-
return trim($prefix, '/') . '/' . $this->controllerId . '/options';
119+
return static::finalOptionsRoute($prefix, $this->controllerId);
122120
}
123121
}
124122
}
@@ -289,4 +287,9 @@ public static function computeModule(string $separator, string $entity): ?string
289287
}
290288
return $result[0];
291289
}
290+
291+
public static function finalOptionsRoute(string $prefix, string $controllerId): string
292+
{
293+
return trim($prefix, '/') . '/' . $controllerId . '/options';
294+
}
292295
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
return [
4+
'openApiPath' => '@specs/issue_fix/35_resolve_todo_re_check_options_route_in_fractal_action/index.yaml',
5+
'generateUrls' => true,
6+
'generateModels' => false,
7+
'excludeModels' => [
8+
'Error',
9+
],
10+
'generateControllers' => true,
11+
'generateMigrations' => false,
12+
'useJsonApi' => true,
13+
'urlPrefixes' => [
14+
'animals' => '',
15+
'/info' => ['module' => 'petinfo', 'namespace' => '\app\modules\petinfo\controllers'],
16+
'/forum' => ['namespace' => '\app\modules\forum\controllers'], # namespace contains "\modules\"
17+
'/forum2' => ['path' => '@app/modules/forum2/controllers', 'namespace' => '\app\forum2\controllers'], # path contains "/modules/"
18+
'/api/v1' => ['path' => '@app/modules/some/controllers', 'namespace' => '\app\api\v1\controllers'], # namespace contains "\modules\"; module will be "api/v1"
19+
'/api/v2' => ['path' => '@app/modules/api/v2/controllers', 'namespace' => '\app\some\controllers'], # namespace contains "\modules\"; module will be "api/v2"
20+
]
21+
];
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
license:
6+
name: MIT
7+
servers:
8+
- url: http://petstore.swagger.io/v1
9+
paths:
10+
/api/v1/pets:
11+
get:
12+
summary: List all pets
13+
operationId: listPets
14+
tags:
15+
- pets
16+
parameters:
17+
- name: limit
18+
in: query
19+
description: How many items to return at one time (max 100)
20+
required: false
21+
schema:
22+
type: integer
23+
format: int32
24+
responses:
25+
'200':
26+
description: A paged array of pets
27+
headers:
28+
x-next:
29+
description: A link to the next page of responses
30+
schema:
31+
type: string
32+
content:
33+
application/json:
34+
schema:
35+
$ref: "#/components/schemas/Pets"
36+
default:
37+
description: unexpected error
38+
content:
39+
application/json:
40+
schema:
41+
$ref: "#/components/schemas/Error"
42+
post:
43+
summary: Create a pet
44+
operationId: createPets
45+
tags:
46+
- pets
47+
responses:
48+
'201':
49+
description: Null response
50+
default:
51+
description: unexpected error
52+
content:
53+
application/json:
54+
schema:
55+
$ref: "#/components/schemas/Error"
56+
/animals/pets/{id}:
57+
parameters:
58+
- name: id
59+
in: path
60+
required: true
61+
description: The id of the pet to update
62+
schema:
63+
type: string
64+
get:
65+
summary: Info for a specific pet
66+
operationId: showPetById
67+
tags:
68+
- pets
69+
responses:
70+
'200':
71+
description: Expected response to a valid request
72+
content:
73+
application/json:
74+
schema:
75+
$ref: "#/components/schemas/Pet"
76+
default:
77+
description: unexpected error
78+
content:
79+
application/json:
80+
schema:
81+
$ref: "#/components/schemas/Error"
82+
patch:
83+
summary: update a specific pet
84+
operationId: updatePetById
85+
tags:
86+
- pets
87+
responses:
88+
'200':
89+
description: The updated pet
90+
content:
91+
application/json:
92+
schema:
93+
$ref: "#/components/schemas/Pet"
94+
delete:
95+
summary: delete a specific pet
96+
operationId: deletePetById
97+
tags:
98+
- pets
99+
responses:
100+
'204':
101+
description: successfully deleted pet
102+
/petComments:
103+
get:
104+
description: list all pet comments
105+
responses:
106+
'200':
107+
description: list of comments
108+
/info/pet-details:
109+
get:
110+
description: list all pet details
111+
responses:
112+
'200':
113+
description: list of details
114+
/forum/pet2-details:
115+
get:
116+
description: list all pet details
117+
responses:
118+
'200':
119+
description: list of details
120+
/forum2/pet3-details:
121+
get:
122+
description: list all pet details
123+
responses:
124+
'200':
125+
description: list of details
126+
/api/v2/comments:
127+
get:
128+
description: list all pet details
129+
responses:
130+
'200':
131+
description: list of details
132+
133+
components:
134+
schemas:
135+
Pet:
136+
description: A Pet
137+
required:
138+
- id
139+
- name
140+
properties:
141+
id:
142+
type: integer
143+
format: int64
144+
readOnly: True
145+
name:
146+
type: string
147+
store:
148+
$ref: '#/components/schemas/Store'
149+
tag:
150+
type: string
151+
x-faker: "$faker->randomElement(['one', 'two', 'three', 'four'])"
152+
Store:
153+
description: A store's description
154+
required:
155+
- id
156+
- name
157+
properties:
158+
id:
159+
type: integer
160+
format: int64
161+
readOnly: True
162+
name:
163+
type: string
164+
Pets:
165+
type: array
166+
items:
167+
$ref: "#/components/schemas/Pet"
168+
Error:
169+
required:
170+
- code
171+
- message
172+
properties:
173+
code:
174+
type: integer
175+
format: int32
176+
message:
177+
type: string

tests/specs/petstore_urlprefixes.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
],
1010
'generateControllers' => true,
1111
'generateMigrations' => false,
12-
'useJsonApi' => true,
1312
'urlPrefixes' => [
1413
'animals' => '',
1514
'/info' => ['module' =>'petinfo','namespace' => '\app\modules\petinfo\controllers'],
16-
'/fgh' => ['namespace' => '\app\modules\fgh\controllers'],
17-
'/fgh2' => ['path' => '@app/modules/fgh2/controllers', 'namespace' => '\app\fgh2\controllers'],
1815
'/api/v1' => ['path' => '@app/modules/api/v1/controllers', 'namespace' => '\app\api\v1\controllers']
1916
]
2017
];

tests/specs/petstore_urlprefixes.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,6 @@ paths:
111111
responses:
112112
'200':
113113
description: list of details
114-
/fgh/pet-detail2s:
115-
get:
116-
description: list all pet details
117-
responses:
118-
'200':
119-
description: list of details
120-
/fgh2/pet-detail3s:
121-
get:
122-
description: list all pet details
123-
responses:
124-
'200':
125-
description: list of details
126114

127115
components:
128116
schemas:

tests/unit/IssueFixTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,15 @@ public function test158BugGiiapiGeneratedRulesEnumWithTrim()
362362
}
363363

364364

365-
public function testRecheckFractalActionsOptionsRoute()
365+
// https://github.com/php-openapi/yii2-openapi/issues/35
366+
public function test35ResolveTodoReCheckOptionsRouteInFractalAction()
366367
{
367-
$this->changeDbToMariadb();
368-
$testFile = Yii::getAlias("@specs/petstore_urlprefixes.php");
368+
$testFile = Yii::getAlias("@specs/issue_fix/35_resolve_todo_re_check_options_route_in_fractal_action/index.php");
369369
$this->runGenerator($testFile);
370370
// $actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
371371
// 'recursive' => true,
372372
// ]);
373-
// $expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/158_bug_giiapi_generated_rules_enum_with_trim/maria"), [
373+
// $expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/158_bug_giiapi_generated_rules_enum_with_trim/mysql"), [
374374
// 'recursive' => true,
375375
// ]);
376376
// $this->checkFiles($actualFiles, $expectedFiles);

0 commit comments

Comments
 (0)