From 4f2c0ec7b36acd503b370bb86d06080bdd14e469 Mon Sep 17 00:00:00 2001 From: Tigor Hutasuhut Date: Sun, 11 Aug 2024 16:55:53 +0700 Subject: [PATCH] reddit: update open api spec --- Makefile | 1 + flake.nix | 13 +++++++++++ schemas/openapi/reddit.yaml | 44 ++++++++++++++++++++++++------------- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index c9f5e24..242c9d8 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ run-web: generate-web generate-go: migrate rm -rf go/gen/* + ogen -target go/gen/reddit -package reddit -clean schemas/openapi/reddit.yaml (cd ./schemas/proto && buf generate --template buf.gen.go.yaml .) (cd go/gen && bobgen-sqlite --config ../bobgen.yaml) (cd go && goverter gen -g 'output:file ../gen/converter/converter.go' -g 'output:package github.com/tigorlazuardi/bluemage/go/gen/converter' ./converts) diff --git a/flake.nix b/flake.nix index ddded7a..13d5339 100644 --- a/flake.nix +++ b/flake.nix @@ -31,6 +31,18 @@ }; vendorHash = "sha256-9vLcyCAhW/Dq0zV8FhM0T3Ofn/8XsUhV5KlphNidGDw="; }; + ogen = pkgs.buildGoModule rec { + name = "ogen"; + version = "1.2.2"; + subPackages = [ "cmd/ogen" ]; + src = pkgs.fetchFromGitHub { + owner = "ogen-go"; + repo = "ogen"; + rev = "v${version}"; + sha256 = "sha256-8HIbMw3G5vuOJMpwfrSiecm9+kmsHDkVqAG6xucoZfs="; + }; + vendorHash = "sha256-sZiOo+ZhczWS7xMt2cxdqZM1C2omIYheZPLAJMLSw28="; + }; in { devShell.${system} = pkgs.mkShell { @@ -50,6 +62,7 @@ bobgen-sqlite air gopls + ogen ]; }; }; diff --git a/schemas/openapi/reddit.yaml b/schemas/openapi/reddit.yaml index 4fa4341..8b446fe 100644 --- a/schemas/openapi/reddit.yaml +++ b/schemas/openapi/reddit.yaml @@ -1,7 +1,10 @@ openapi: 3.0.3 info: title: Reddit JSON Listing API - description: JSON api listing for Subreddits and Users. + description: |- + JSON api listing for Subreddits and Users. + + Request must have `User-Agent` header set to custom values and not empty. version: v1 servers: - url: https://reddit.com @@ -22,19 +25,19 @@ paths: this endpoint will redirect to `/subreddits/search.json?q={name}` with this kind of response body: - ```json - { - "kind": "Listing", - "data": { - "after": null, - "dist": 0, - "modhash": "", - "geo_filter": "", - "children": [], - "before": null - } - } - ``` + ```json + { + "kind": "Listing", + "data": { + "after": null, + "dist": 0, + "modhash": "", + "geo_filter": "", + "children": [], + "before": null + } + } + ``` Currently, Best way to check wether the subreddit exists or not is the `data.after` and `data.before` is null, and `data.children` array is empty. @@ -111,7 +114,12 @@ paths: Maximum value to fetch is `100`. example: 25 - operationId: getSubredditListing + - in: header + name: User-Agent + schema: + type: string + default: bluemage/v1 + operationId: getListing responses: "200": description: success @@ -119,6 +127,12 @@ paths: application/json: schema: $ref: "#/components/schemas/ListingResponse" + "429": + description: Too many requests + content: + application/json: + schema: + type: object components: schemas: