Skip to content

Commit d02e665

Browse files
Merge pull request #175 from SoliDry/develop
Add relations OAS docs generation
2 parents 821d9be + ce57a4e commit d02e665

File tree

3 files changed

+258
-4
lines changed

3 files changed

+258
-4
lines changed

src/Blocks/Controllers.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace SoliDry\Blocks;
44

5+
use SoliDry\Documentation\Documentation;
56
use SoliDry\Extension\BaseController;
67
use SoliDry\Helpers\Classes;
78
use SoliDry\Helpers\Console;
@@ -15,8 +16,11 @@
1516
*/
1617
class Controllers extends Documentation implements ControllersInterface
1718
{
19+
1820
/**
1921
* Creates the DefaultController and outputs path to the console
22+
*
23+
* @throws \ReflectionException
2024
*/
2125
public function createDefault(): void
2226
{
@@ -66,6 +70,8 @@ protected function setContent()
6670

6771
/**
6872
* Sets the DefaultController content
73+
*
74+
* @throws \ReflectionException
6975
*/
7076
private function setDefaultContent()
7177
{

src/Blocks/Documentation.php renamed to src/Documentation/Documentation.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

3-
namespace SoliDry\Blocks;
3+
namespace SoliDry\Documentation;
44

55
use SoliDry\ApiGenerator;
6+
use SoliDry\Blocks\ContentManager;
67
use SoliDry\Controllers\BaseCommand;
78
use SoliDry\Helpers\Classes;
89
use SoliDry\Types\ApiInterface;
@@ -20,7 +21,7 @@
2021
abstract class Documentation
2122
{
2223

23-
use ContentManager;
24+
use ContentManager, RelationsDoc;
2425

2526
protected $generator;
2627
protected $sourceCode = '';
@@ -37,7 +38,7 @@ public function __construct($generator)
3738
$this->className = Classes::getClassName($this->generator->objectName);
3839
}
3940

40-
protected function setDefaultDocs()
41+
protected function setDefaultDocs(): void
4142
{
4243
$this->setComment(DefaultInterface::METHOD_START);
4344

@@ -146,9 +147,22 @@ protected function setControllersDocs(): void
146147

147148
$this->setDelete();
148149

150+
$this->setRelated();
151+
152+
$this->setRelations();
153+
154+
$this->setCreateRelation();
155+
156+
$this->setUpdateRelation();
157+
158+
$this->setDeleteRelation();
159+
149160
$this->setComment(DefaultInterface::METHOD_END);
150161
}
151162

163+
/**
164+
* Sets OAS documentation for an index method
165+
*/
152166
private function setIndex(): void
153167
{
154168
$this->openComment();
@@ -180,7 +194,7 @@ private function setIndex(): void
180194
'in' => '"query"',
181195
'name' => '"limit"',
182196
'required' => 'false',
183-
]);
197+
], 'integer');
184198

185199
$this->setParameter([
186200
'in' => '"query"',
@@ -217,6 +231,9 @@ private function setIndex(): void
217231
$this->setNewLines();
218232
}
219233

234+
/**
235+
* Sets OAS documentation for a view method
236+
*/
220237
private function setView(): void
221238
{
222239
$this->openComment();
@@ -254,6 +271,9 @@ private function setView(): void
254271
$this->setNewLines();
255272
}
256273

274+
/**
275+
* Sets OAS documentation for a create method
276+
*/
257277
private function setCreate(): void
258278
{
259279
$this->openComment();
@@ -279,6 +299,9 @@ private function setCreate(): void
279299
$this->setNewLines();
280300
}
281301

302+
/**
303+
* Sets OAS documentation for an update method
304+
*/
282305
private function setUpdate(): void
283306
{
284307
$this->openComment();
@@ -304,6 +327,9 @@ private function setUpdate(): void
304327
$this->setNewLines();
305328
}
306329

330+
/**
331+
* Sets OAS documentation for a delete method
332+
*/
307333
private function setDelete(): void
308334
{
309335
$this->openComment();

src/Documentation/RelationsDoc.php

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
<?php
2+
3+
namespace SoliDry\Documentation;
4+
5+
use SoliDry\Types\DefaultInterface;
6+
use SoliDry\Types\DocumentationInterface;
7+
use SoliDry\Types\PhpInterface;
8+
9+
trait RelationsDoc
10+
{
11+
/**
12+
* Sets OAS documentation for a related method
13+
*/
14+
private function setRelated(): void
15+
{
16+
$this->openComment();
17+
18+
$this->setStarredComment(DocumentationInterface::OA_GET . PhpInterface::OPEN_PARENTHESES);
19+
20+
$this->setStarredComment('path="' . PhpInterface::SLASH . $this->generator->version . PhpInterface::SLASH
21+
. strtolower($this->generator->objectName) . PhpInterface::SLASH . '{id}/{related}",', 1, 1);
22+
23+
$this->setStarredComment('summary="Get ' . $this->generator->objectName . ' related objects",', 1, 1);
24+
25+
$this->setStarredComment('tags={"' . $this->generator->objectName . DefaultInterface::CONTROLLER_POSTFIX
26+
. '"},', 1, 1);
27+
28+
$this->setParameter([
29+
'in' => '"query"',
30+
'name' => '"data"',
31+
'required' => 'false',
32+
]);
33+
34+
$this->setParameter([
35+
'in' => '"path"',
36+
'name' => '"id"',
37+
'required' => 'true',
38+
]);
39+
40+
$this->setParameter([
41+
'in' => '"path"',
42+
'name' => '"related"',
43+
'required' => 'true',
44+
]);
45+
46+
$this->setResponse([
47+
'response' => '200',
48+
'description' => '""',
49+
]);
50+
51+
$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES);
52+
53+
$this->closeComment();
54+
$this->setNewLines();
55+
}
56+
57+
/**
58+
* Sets OAS documentation for getting relations method
59+
*/
60+
private function setRelations(): void
61+
{
62+
$this->openComment();
63+
64+
$this->setStarredComment(DocumentationInterface::OA_GET . PhpInterface::OPEN_PARENTHESES);
65+
66+
$this->setStarredComment('path="' . PhpInterface::SLASH . $this->generator->version . PhpInterface::SLASH
67+
. strtolower($this->generator->objectName) . PhpInterface::SLASH . '{id}/relationships/{relations}",', 1, 1);
68+
69+
$this->setStarredComment('summary="Get ' . $this->generator->objectName . ' relations objects",', 1, 1);
70+
71+
$this->setStarredComment('tags={"' . $this->generator->objectName . DefaultInterface::CONTROLLER_POSTFIX
72+
. '"},', 1, 1);
73+
74+
$this->setParameter([
75+
'in' => '"query"',
76+
'name' => '"data"',
77+
'required' => 'false',
78+
]);
79+
80+
$this->setParameter([
81+
'in' => '"path"',
82+
'name' => '"id"',
83+
'required' => 'true',
84+
]);
85+
86+
$this->setParameter([
87+
'in' => '"path"',
88+
'name' => '"relations"',
89+
'required' => 'true',
90+
]);
91+
92+
$this->setResponse([
93+
'response' => '200',
94+
'description' => '""',
95+
]);
96+
97+
$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES);
98+
99+
$this->closeComment();
100+
$this->setNewLines();
101+
}
102+
103+
/**
104+
* Sets OAS documentation for creating relation method
105+
*/
106+
private function setCreateRelation(): void
107+
{
108+
$this->openComment();
109+
110+
$this->setStarredComment(DocumentationInterface::OA_POST . PhpInterface::OPEN_PARENTHESES);
111+
112+
$this->setStarredComment('path="' . PhpInterface::SLASH . $this->generator->version . PhpInterface::SLASH
113+
. strtolower($this->generator->objectName) . PhpInterface::SLASH . '{id}/relationships/{relations}",', 1, 1);
114+
115+
$this->setStarredComment('summary="Create ' . $this->generator->objectName . ' relation object",', 1, 1);
116+
117+
$this->setStarredComment('tags={"' . $this->generator->objectName . DefaultInterface::CONTROLLER_POSTFIX
118+
. '"},', 1, 1);
119+
120+
$this->setParameter([
121+
'in' => '"path"',
122+
'name' => '"id"',
123+
'required' => 'true',
124+
]);
125+
126+
$this->setParameter([
127+
'in' => '"path"',
128+
'name' => '"relations"',
129+
'required' => 'true',
130+
]);
131+
132+
$this->setResponse([
133+
'response' => '200',
134+
'description' => '""',
135+
]);
136+
137+
$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES);
138+
139+
$this->closeComment();
140+
$this->setNewLines();
141+
}
142+
143+
/**
144+
* Sets OAS documentation for updating relation method
145+
*/
146+
private function setUpdateRelation(): void
147+
{
148+
$this->openComment();
149+
150+
$this->setStarredComment(DocumentationInterface::OA_PATCH . PhpInterface::OPEN_PARENTHESES);
151+
152+
$this->setStarredComment('path="' . PhpInterface::SLASH . $this->generator->version . PhpInterface::SLASH
153+
. strtolower($this->generator->objectName) . PhpInterface::SLASH . '{id}/relationships/{relations}",', 1, 1);
154+
155+
$this->setStarredComment('summary="Update ' . $this->generator->objectName . ' relation object",', 1, 1);
156+
157+
$this->setStarredComment('tags={"' . $this->generator->objectName . DefaultInterface::CONTROLLER_POSTFIX
158+
. '"},', 1, 1);
159+
160+
$this->setParameter([
161+
'in' => '"path"',
162+
'name' => '"id"',
163+
'required' => 'true',
164+
]);
165+
166+
$this->setParameter([
167+
'in' => '"path"',
168+
'name' => '"relations"',
169+
'required' => 'true',
170+
]);
171+
172+
$this->setResponse([
173+
'response' => '200',
174+
'description' => '""',
175+
]);
176+
177+
$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES);
178+
179+
$this->closeComment();
180+
$this->setNewLines();
181+
}
182+
183+
/**
184+
* Sets OAS documentation for deleting relation method
185+
*/
186+
private function setDeleteRelation(): void
187+
{
188+
$this->openComment();
189+
190+
$this->setStarredComment(DocumentationInterface::OA_DELETE . PhpInterface::OPEN_PARENTHESES);
191+
192+
$this->setStarredComment('path="' . PhpInterface::SLASH . $this->generator->version . PhpInterface::SLASH
193+
. strtolower($this->generator->objectName) . PhpInterface::SLASH . '{id}/relationships/{relations}",', 1, 1);
194+
195+
$this->setStarredComment('summary="Delete ' . $this->generator->objectName . ' relation object",', 1, 1);
196+
197+
$this->setStarredComment('tags={"' . $this->generator->objectName . DefaultInterface::CONTROLLER_POSTFIX
198+
. '"},', 1, 1);
199+
200+
$this->setParameter([
201+
'in' => '"path"',
202+
'name' => '"id"',
203+
'required' => 'true',
204+
]);
205+
206+
$this->setParameter([
207+
'in' => '"path"',
208+
'name' => '"relations"',
209+
'required' => 'true',
210+
]);
211+
212+
$this->setResponse([
213+
'response' => '200',
214+
'description' => '""',
215+
]);
216+
217+
$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES);
218+
219+
$this->closeComment();
220+
$this->setNewLines();
221+
}
222+
}

0 commit comments

Comments
 (0)