Skip to content

Commit 32c7a44

Browse files
committed
feat: add version path parameter and middleware for raw API routes
1 parent 6d90017 commit 32c7a44

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

Diff for: src/middlewares/version.ts

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import { createError, getAvailableVersions } from "../utils";
33

44
const DEFAULT_FALLBACK_VERSION = "15.1";
55

6+
export const VERSION_PATH_PARAMETER = {
7+
in: "path" as const,
8+
name: "version",
9+
required: true,
10+
example: "latest",
11+
schema: {
12+
type: "string" as const,
13+
},
14+
};
15+
616
export const versionMiddleware = createMiddleware(async (c, next) => {
717
const version = c.req.param("version");
818
const fullPath = c.req.path;

Diff for: src/routes/v1_categories.openapi.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
import { createRoute, z } from "@hono/zod-openapi";
2+
import { VERSION_PATH_PARAMETER } from "../middlewares/version";
23
import { ApiErrorSchema, EmojiCategorySchema } from "../schemas";
34

4-
const VERSION_PATH_PARAMETER = {
5-
in: "path" as const,
6-
name: "version",
7-
required: true,
8-
example: "latest",
9-
schema: {
10-
type: "string" as const,
11-
},
12-
};
135
export const ALL_CATEGORIES_ROUTE = createRoute({
146
method: "get",
157
path: "/",

Diff for: src/routes/v1_raw/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import type { HonoContext } from "../../types";
22
import { OpenAPIHono } from "@hono/zod-openapi";
3+
import { versionMiddleware } from "../../middlewares/version";
34

4-
export const V1_RAW_ROUTER = new OpenAPIHono<HonoContext>().basePath("/api/v1/raw");
5+
export const V1_RAW_ROUTER = new OpenAPIHono<HonoContext>().basePath("/api/v1/raw/:version");
6+
7+
V1_RAW_ROUTER.use(versionMiddleware);

0 commit comments

Comments
 (0)