From 84d3dbdbf959831b5d8eb5d0baa3fabe4b46dfa4 Mon Sep 17 00:00:00 2001 From: Nagarajan Ganesan Date: Fri, 29 Sep 2023 12:55:31 +0000 Subject: [PATCH] Add a simple OpenAPI spec --- internal/api/handler.go | 6 +++--- spec/ytstat-openapi.yaml | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 spec/ytstat-openapi.yaml diff --git a/internal/api/handler.go b/internal/api/handler.go index 8990bd1..29de62a 100644 --- a/internal/api/handler.go +++ b/internal/api/handler.go @@ -22,10 +22,10 @@ func handleVideoInfo(w http.ResponseWriter, r *http.Request) { _, span := tracer.Start(r.Context(), "handleVideoInfo") defer span.End() - videoID := r.URL.Query().Get("video_id") + videoID := r.URL.Query().Get("videoid") if videoID == "" { - hlog.FromRequest(r).Error().Msg("video_id parameter is missing") - http.Error(w, "video_id parameter is missing", http.StatusBadRequest) + hlog.FromRequest(r).Error().Msg("videoid parameter is missing") + http.Error(w, "videoid parameter is missing", http.StatusBadRequest) return } diff --git a/spec/ytstat-openapi.yaml b/spec/ytstat-openapi.yaml new file mode 100644 index 0000000..e537a8c --- /dev/null +++ b/spec/ytstat-openapi.yaml @@ -0,0 +1,23 @@ +penapi: 3.0.0 +info: + title: Youtube Statistics API + description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML. + version: 0.1.9 +servers: + - url: http://api.example.com/v1 + description: Optional server description, e.g. Main (production) server + - url: http://staging-api.example.com + description: Optional server description, e.g. Internal staging server for testing +paths: + /videoid: + get: + summary: Returns stats for the give video id. + description: Optional extended description in CommonMark or HTML. + responses: + '200': # status code + description: JSON document with stats for the video + content: + application/json: + schema: + type: object + \ No newline at end of file