Skip to content

Commit

Permalink
Add Swagger annotations on MetricController
Browse files Browse the repository at this point in the history
  • Loading branch information
nalysius committed Jun 2, 2018
1 parent d2bbbad commit 153fb9a
Showing 1 changed file with 243 additions and 49 deletions.
292 changes: 243 additions & 49 deletions app/Http/Controllers/Api/MetricController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,34 @@ class MetricController extends AbstractApiController
* Get all metrics.
*
* @return \Illuminate\Database\Eloquent\Collection
*
* @SWG\Get(
* path="/metrics",
* summary="List all metrics.",
* operationId="Metric@index",
* tags={"Metrics"},
* produces={"application/json"},
* @SWG\Parameter(
* description="Attribute name on which apply 'order'.",
* in="query",
* name="sort",
* required=false,
* type="integer",
* format="int64"
* ),
* @SWG\Parameter(
* description="Order in which order the results, ASC or DESC.",
* in="query",
* name="order",
* required=false,
* type="integer",
* format="int64"
* ),
* @SWG\Response(
* response=200,
* description="A list with all metrics."
* )
* )
*/
public function index()
{
Expand All @@ -50,15 +78,28 @@ public function index()
/**
* Get a single metric.
*
* **Path params:**
*
* Name | Type | Required | Description
* -----|------|----------|------------
* metric | int32 | Y | Metric ID
*
* @param \CachetHQ\Cachet\Models\Metric $metric
*
* @return \Illuminate\Http\JsonResponse
*
* @SWG\Get(
* path="/metrics/{metric}",
* summary="Get a single metric.",
* tags={"Metrics"},
* operationId="Metric@show",
* @SWG\Parameter(
* description="ID of metric to return.",
* in="path",
* name="metric",
* required=true,
* type="integer",
* format="int64"
* ),
* @SWG\Response(
* response=200,
* description="A single metric."
* )
* )
*/
public function show(Metric $metric)
{
Expand All @@ -68,22 +109,95 @@ public function show(Metric $metric)
/**
* Create a new metric.
*
* **Body params:**
*
* Name | Type | Required | Description
* -----|------|----------|------------
* name | string | Y | Name of metric
* suffix | string | Y | Measurments in
* description | string | Y | Description of what the metric is measuring
* default_value | int32 | Y | The default value to use when a point is added
* display_chart | int32 | Y | Whether to display the chart on the status page
* calc_type | int32 | N | The calc type. 0 for sum, 1 for average
* default_view | int32 | N | The default view
* threshold | int32 | N | The threshold
* order | int32 | N | The order
* visible | int32 | N | Whether the graph should be visible
*
* @return \Illuminate\Http\JsonResponse
*
* @SWG\Post(
* path="/metrics",
* tags={"Metrics"},
* operationId="Metric@store",
* summary="Add a new metric.",
* description="",
* consumes={"multipart/form-data"},
* produces={"application/json"},
* @SWG\Parameter(
* name="name",
* in="formData",
* type="string",
* description="Name of the metric.",
* required=true
* ),
* @SWG\Parameter(
* name="suffix",
* in="formData",
* type="string",
* description="Measurments in. Usually '%', 'ms' for example.",
* required=true
* ),
* @SWG\Parameter(
* name="description",
* in="formData",
* type="string",
* description="Description of the metric.",
* required=true
* ),
* @SWG\Parameter(
* name="default_value",
* in="formData",
* type="integer",
* description="The default value when a point is added.",
* required=true
* ),
* @SWG\Parameter(
* name="display_chart",
* in="formData",
* type="integer",
* description="Whether to display the chart on the status page.",
* required=true
* ),
* @SWG\Parameter(
* name="calc_type",
* in="formData",
* type="integer",
* description="The calc type. 0 for sum, 1 for average. Default 0.",
* required=false
* ),
* @SWG\Parameter(
* name="default_view",
* in="formData",
* type="integer",
* description="The default view (24h, week, ...). Default 24h.",
* required=false
* ),
* @SWG\Parameter(
* name="threshold",
* in="formData",
* type="integer",
* description="The threshold. Default 5.",
* required=false
* ),
* @SWG\Parameter(
* name="order",
* in="formData",
* type="integer",
* description="The order.",
* required=false
* ),
* @SWG\Parameter(
* name="visible",
* in="formData",
* type="integer",
* description="Whether the graph should be visible. Default visible.",
* required=false
* ),
* @SWG\Response(
* response=200,
* description="The metric."
* ),
* @SWG\Response(
* response=400,
* description="Invalid metric."
* )
* )
*/
public function store()
{
Expand Down Expand Up @@ -111,31 +225,97 @@ public function store()
/**
* Update an existing metric.
*
* **Path params:**
*
* Name | Type | Required | Description
* -----|------|----------|------------
* metric | int32 | Y | Metric ID
*
* **Body params:**
*
* Name | Type | Required | Description
* -----|------|----------|------------
* name | string | Y | Name of metric
* suffix | string | Y | Measurments in
* description | string | Y | Description of what the metric is measuring
* default_value | int32 | Y | The default value to use when a point is added
* display_chart | int32 | Y | Whether to display the chart on the status page
* calc_type | int32 | Y | Metric type. 0 for sum, 1 for average
* places | int32 | Y | Decimal places
* threshold | int32 | Y | Number of minutes of threshold between metric points
* order | int32 | Y | The order of the metric
* visible | int32 | Y | Whether the metrics should be visible on the status page
* default_view | int32 | N | The default view
*
* @param \CachetHQ\Cachet\Models\Metric $metric
*
* @return \Illuminate\Http\JsonResponse
*
* @SWG\Put(
* path="/metrics/{metric}",
* tags={"Metrics"},
* operationId="Metric@update",
* summary="update a metric.",
* description="",
* consumes={"multipart/form-data"},
* produces={"application/json"},
* @SWG\Parameter(
* name="name",
* in="formData",
* type="string",
* description="Name of the metric.",
* required=true
* ),
* @SWG\Parameter(
* name="suffix",
* in="formData",
* type="string",
* description="Measurments in. Usually '%', 'ms' for example.",
* required=true
* ),
* @SWG\Parameter(
* name="description",
* in="formData",
* type="string",
* description="Description of the metric.",
* required=true
* ),
* @SWG\Parameter(
* name="default_value",
* in="formData",
* type="integer",
* description="The default value when a point is added.",
* required=true
* ),
* @SWG\Parameter(
* name="display_chart",
* in="formData",
* type="integer",
* description="Whether to display the chart on the status page.",
* required=true
* ),
* @SWG\Parameter(
* name="calc_type",
* in="formData",
* type="integer",
* description="The calc type. 0 for sum, 1 for average.",
* required=true
* ),
* @SWG\Parameter(
* name="default_view",
* in="formData",
* type="integer",
* description="The default view (24h, week, ...). Default 24h.",
* required=false
* ),
* @SWG\Parameter(
* name="threshold",
* in="formData",
* type="integer",
* description="The threshold.",
* required=true
* ),
* @SWG\Parameter(
* name="order",
* in="formData",
* type="integer",
* description="The order.",
* required=false
* ),
* @SWG\Parameter(
* name="visible",
* in="formData",
* type="integer",
* description="Whether the graph should be visible.",
* required=true
* ),
* @SWG\Response(
* response=200,
* description="The metric."
* ),
* @SWG\Response(
* response=400,
* description="Invalid metric."
* )
* )
*/
public function update(Metric $metric)
{
Expand Down Expand Up @@ -164,15 +344,29 @@ public function update(Metric $metric)
/**
* Delete an existing metric.
*
* **Path params:**
*
* Name | Type | Required | Description
* -----|------|----------|------------
* metric | int32 | Required | int32
*
* @param \CachetHQ\Cachet\Models\Metric $metric
*
* @return \Illuminate\Http\JsonResponse
*
* @SWG\Delete(
* path="/metrics/{metric}",
* summary="Deletes a metric.",
* description="",
* operationId="Metric@destroy",
* tags={"Metrics"},
* @SWG\Parameter(
* description="Metric ID to delete.",
* in="path",
* name="metric",
* required=true,
* type="integer",
* format="int64"
* ),
* @SWG\Response(
* response=204,
* description="Ok."
* ),
* )
*/
public function destroy(Metric $metric)
{
Expand Down

0 comments on commit 153fb9a

Please sign in to comment.