From 7e0a14493e4b6b4db945adb45a82caf5fbb0b499 Mon Sep 17 00:00:00 2001
From: Alejandro Celaya <alejandro@alejandrocelaya.com>
Date: Fri, 8 May 2020 10:14:38 +0200
Subject: [PATCH] Documented updates on the tags endpoint to return more
 detailed information

---
 docs/swagger/definitions/TagInfo.json         | 17 +++++++++++++++
 docs/swagger/paths/v1_tags.json               | 21 +++++++++++++++++++
 .../Core/src/{Service => }/Tag/TagService.php |  0
 .../{Service => }/Tag/TagServiceInterface.php |  0
 4 files changed, 38 insertions(+)
 create mode 100644 docs/swagger/definitions/TagInfo.json
 rename module/Core/src/{Service => }/Tag/TagService.php (100%)
 rename module/Core/src/{Service => }/Tag/TagServiceInterface.php (100%)

diff --git a/docs/swagger/definitions/TagInfo.json b/docs/swagger/definitions/TagInfo.json
new file mode 100644
index 00000000..e881ce02
--- /dev/null
+++ b/docs/swagger/definitions/TagInfo.json
@@ -0,0 +1,17 @@
+{
+    "type": "object",
+    "properties": {
+        "tag": {
+            "type": "string",
+            "description": "The unique tag name"
+        },
+        "shortUrlsCount": {
+            "type": "number",
+            "description": "The amount of short URLs using this tag"
+        },
+        "userAgent": {
+            "type": "number",
+            "description": "The combined amount of visits received by short URLs with this tag"
+        }
+    }
+}
diff --git a/docs/swagger/paths/v1_tags.json b/docs/swagger/paths/v1_tags.json
index 5e7fd71c..83bc7d68 100644
--- a/docs/swagger/paths/v1_tags.json
+++ b/docs/swagger/paths/v1_tags.json
@@ -14,6 +14,19 @@
         "parameters": [
             {
                 "$ref": "../parameters/version.json"
+            },
+            {
+                "name": "withStats",
+                "description": "Whether you want to include also a list with general stats by tag or not.",
+                "in": "query",
+                "required": false,
+                "schema": {
+                    "type": "string",
+                    "enum": [
+                        "true",
+                        "false"
+                    ]
+                }
             }
         ],
         "responses": {
@@ -26,12 +39,20 @@
                             "properties": {
                                 "tags": {
                                     "type": "object",
+                                    "required": ["data"],
                                     "properties": {
                                         "data": {
                                             "type": "array",
                                             "items": {
                                                 "type": "string"
                                             }
+                                        },
+                                        "stats": {
+                                            "description": "The tag stats will be returned only if the withStats param was provided with value 'true'",
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": "../definitions/TagInfo.json"
+                                            }
                                         }
                                     }
                                 }
diff --git a/module/Core/src/Service/Tag/TagService.php b/module/Core/src/Tag/TagService.php
similarity index 100%
rename from module/Core/src/Service/Tag/TagService.php
rename to module/Core/src/Tag/TagService.php
diff --git a/module/Core/src/Service/Tag/TagServiceInterface.php b/module/Core/src/Tag/TagServiceInterface.php
similarity index 100%
rename from module/Core/src/Service/Tag/TagServiceInterface.php
rename to module/Core/src/Tag/TagServiceInterface.php