From a82fd6128ececda55d3ad91f9e9cc7152a4d171a Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 3 May 2024 23:31:38 +0100 Subject: [PATCH] Added stats API Signed-off-by: Matthew --- components/schemas/Event.yaml | 28 ++++++++++++++++++++++++ openapi.yaml | 7 ++++++ paths/stats/event.yaml | 40 +++++++++++++++++++++++++++++++++++ paths/stats/health.yaml | 16 ++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 components/schemas/Event.yaml create mode 100644 paths/stats/event.yaml create mode 100644 paths/stats/health.yaml diff --git a/components/schemas/Event.yaml b/components/schemas/Event.yaml new file mode 100644 index 0000000..dbe90aa --- /dev/null +++ b/components/schemas/Event.yaml @@ -0,0 +1,28 @@ +# SPDX-FileCopyrightText: 2024 Sidings Media +# SPDX-License-Identifier: MIT + +type: object +properties: + domain: + type: string + description: Domain of site + name: + type: string + description: Name of event to log. + url: + type: string + format: uri + description: URL of page that triggered event + referrer: + type: string + description: Referrer for this event + props: + type: object + description: | + Custom properties for the event. Note maximum of 30 key value + pairs. If more than 30 are provided the exceeding keys will be + ignored. +required: + - domain + - name + - url diff --git a/openapi.yaml b/openapi.yaml index 8a966e4..f4d66a7 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -29,6 +29,7 @@ info: | `/terms` | `static` | https://github.com/SidingsMedia/static.git | | `/openapi` | `openapi` | https://github.com/SidingsMedia/openapi.git | | `/openapi.json` | `openapi` | https://github.com/SidingsMedia/openapi.git | + | `/stats` | stats | https://github.com/plausible/analytics.git | Each service will expose a health check endpoint that will return a plaintext `200 OK` response when called. This is documented by this @@ -85,4 +86,10 @@ paths: /terms: $ref: paths/terms.yaml + + /stats/event: + $ref: paths/stats/event.yaml + + /stats/health: + $ref: paths/stats/health.yaml \ No newline at end of file diff --git a/paths/stats/event.yaml b/paths/stats/event.yaml new file mode 100644 index 0000000..20194a4 --- /dev/null +++ b/paths/stats/event.yaml @@ -0,0 +1,40 @@ +# SPDX-FileCopyrightText: 2024 Sidings Media +# SPDX-License-Identifier: MIT + +post: + description: Log an analytics event + summary: Log an event + operationId: logEvent + tags: + - stats + parameters: + - in: header + name: User-Agent + schema: + type: string + example: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1 + required: true + requestBody: + required: true + content: + application/json: + schema: + $ref: ../../components/schemas/Event.yaml + example: + domain: sidingsmedia.com + event: pageview + url: https://sidingsmedia.com + responses: + '202': + content: + text/plain: + schema: + type: string + example: + value: ok + '400': + $ref: ../../components/responses/BadRequest.yaml + '429': + $ref: ../../components/responses/TooManyRequests.yaml + 5XX: + $ref: ../../components/responses/ServerError.yaml \ No newline at end of file diff --git a/paths/stats/health.yaml b/paths/stats/health.yaml new file mode 100644 index 0000000..6f15e87 --- /dev/null +++ b/paths/stats/health.yaml @@ -0,0 +1,16 @@ +# SPDX-FileCopyrightText: 2024 Sidings Media +# SPDX-License-Identifier: MIT + +get: + description: Stats service health check + summary: Health check + operationId: statsHealth + tags: + - stats + responses: + '200': + $ref: ../../components/responses/HealthCheckOK.yaml + '429': + $ref: ../../components/responses/TooManyRequests.yaml + 5XX: + $ref: ../../components/responses/ServerError.yaml \ No newline at end of file