Skip to content

Commit 4d7175d

Browse files
committed
Initial attempt at adding Swagger annotations
1 parent 440baee commit 4d7175d

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

API.php

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,43 @@
1717
/**
1818
*
1919
* @method static \Piwik\Plugins\CustomAlerts\API getInstance()
20+
*
21+
* @OA\Schema(
22+
* schema="alert",
23+
* title="Alert",
24+
* type="object",
25+
* @OA\Property(
26+
* property="idAlert",
27+
* description="ID of the alert",
28+
* type="integer",
29+
* ),
30+
* @OA\Property(
31+
* property="name",
32+
* description="Name of the alert",
33+
* type="string",
34+
* ),
35+
* @OA\Property(
36+
* property="login",
37+
* description="Name of the login or username to which the alert belongs",
38+
* type="string",
39+
* ),
40+
* @OA\Property(
41+
* property="period",
42+
* description="Name of the period such as day, week, or month",
43+
* type="string",
44+
* ),
45+
* @OA\Property(
46+
* property="report",
47+
* description="Name of the report which the alert monitors",
48+
* type="string",
49+
* ),
50+
* @OA\Property(
51+
* property="idSites",
52+
* description="IDs of the sites",
53+
* type="array",
54+
* @OA\Items(type="integer")
55+
* )
56+
* )
2057
*/
2158
class API extends \Piwik\Plugin\API
2259
{
@@ -41,6 +78,59 @@ public function __construct(Processor $processor, Validator $validator)
4178
* @param int $subPeriodN
4279
*
4380
* @return array
81+
*
82+
* @OA\Get(
83+
* path="/index.php?method=CustomAlerts.getValuesForAlertInPast",
84+
* operationId="CustomAlerts.getValuesForAlertInPast",
85+
* tags={"CustomAlerts"},
86+
* @OA\Parameter(ref="#/components/parameters/module"),
87+
* @OA\Parameter(ref="#/components/parameters/format"),
88+
* @OA\Parameter(
89+
* name="idAlert",
90+
* in="query",
91+
* description="The ID of the alert",
92+
* required=true,
93+
* @OA\Schema(
94+
* type="integer"
95+
* )
96+
* ),
97+
* @OA\Parameter(
98+
* name="subPeriodN",
99+
* in="query",
100+
* description="The number to subtract from the current (0) period",
101+
* required=true,
102+
* @OA\Schema(
103+
* type="integer"
104+
* )
105+
* ),
106+
* @OA\Response(
107+
* response="200",
108+
* description="The collection of sites their the matching result for the specified period",
109+
* @OA\JsonContent(
110+
* type="array",
111+
* @OA\Items(
112+
* type="object",
113+
* @OA\Property(
114+
* property="idSite",
115+
* description="ID of the site",
116+
* type="integer",
117+
* ),
118+
* @OA\Property(
119+
* property="value",
120+
* description="Value of the alert for specific site",
121+
* type="array",
122+
* @OA\Items(
123+
* oneOf={
124+
* @OA\Schema(type="string"),
125+
* @OA\Schema(type="integer"),
126+
* @OA\Schema(type="object")
127+
* }
128+
* )
129+
* )
130+
* )
131+
* )
132+
* )
133+
* )
44134
*/
45135
public function getValuesForAlertInPast($idAlert, $subPeriodN)
46136
{
@@ -64,6 +154,28 @@ public function getValuesForAlertInPast($idAlert, $subPeriodN)
64154
*
65155
* @return array
66156
* @throws \Exception In case alert does not exist or user has no permission to access alert.
157+
*
158+
* @OA\Get(
159+
* path="/index.php?method=CustomAlerts.getAlert",
160+
* operationId="CustomAlerts.getAlert",
161+
* tags={"CustomAlerts"},
162+
* @OA\Parameter(ref="#/components/parameters/module"),
163+
* @OA\Parameter(ref="#/components/parameters/format"),
164+
* @OA\Parameter(
165+
* name="idAlert",
166+
* in="query",
167+
* description="The ID of the alert",
168+
* required=true,
169+
* @OA\Schema(
170+
* type="integer"
171+
* )
172+
* ),
173+
* @OA\Response(
174+
* response="200",
175+
* description="The properties of the requested alert",
176+
* @OA\JsonContent(ref="#/components/schemas/alert")
177+
* )
178+
* )
67179
*/
68180
public function getAlert($idAlert)
69181
{
@@ -90,6 +202,32 @@ private function getModel()
90202
* @param bool $ifSuperUserReturnAllAlerts
91203
*
92204
* @return array
205+
*
206+
* @OA\Get(
207+
* path="/index.php?method=CustomAlerts.getAlerts",
208+
* operationId="CustomAlerts.getAlerts",
209+
* tags={"CustomAlerts"},
210+
* @OA\Parameter(ref="#/components/parameters/module"),
211+
* @OA\Parameter(ref="#/components/parameters/format"),
212+
* @OA\Parameter(
213+
* name="idSites",
214+
* in="query",
215+
* description="The IDs of the sites to filter alerts by",
216+
* required=true,
217+
* @OA\Schema(
218+
* type="array",
219+
* @OA\Items(type="integer")
220+
* )
221+
* ),
222+
* @OA\Response(
223+
* response="200",
224+
* description="A collection of alerts matching the sites",
225+
* @OA\JsonContent(
226+
* type="array",
227+
* @OA\Items(ref="#/components/schemas/alert")
228+
* )
229+
* )
230+
* )
93231
*/
94232
public function getAlerts($idSites, $ifSuperUserReturnAllAlerts = false)
95233
{

0 commit comments

Comments
 (0)