Skip to content

Commit 8b103af

Browse files
committed
add a hint to error handling for path-params
1 parent cdaedf0 commit 8b103af

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@omer-x/next-openapi-route-handler",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "a Next.js plugin to generate OpenAPI documentation from route handlers",
55
"keywords": [
66
"next.js",

src/core/path-params.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { safeParse } from "./zod-error-handler";
22
import type { ZodError, ZodType, ZodTypeDef } from "zod";
33

44
export default function parsePathParams<I, O>(source?: I, schema?: ZodType<O, ZodTypeDef, I>) {
5-
if (!schema || !source) return null;
5+
if (!schema) return null;
6+
if (!source) throw new Error("UNNECESSARY_PATH_PARAMS");
67
try {
78
return safeParse(schema, source as Record<string, unknown>);
89
} catch (error) {

src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ function createRoute<M extends HttpMethod, PPI, PPO, QPI, QPO, RBI, RBO>(input:
6363
return new Response(null, { status: 400 });
6464
case "PARSE_PATH_PARAMS":
6565
return new Response(null, { status: 404 });
66+
case "UNNECESSARY_PATH_PARAMS": {
67+
if (process.env.NODE_ENV !== "production") {
68+
console.log([
69+
"[Next OpenAPI Route Handler]",
70+
"You tried to add pathParams to a route which doesn't have any dynamic params.",
71+
"Maybe you meant queryParams instead?",
72+
].join(" "));
73+
}
74+
}
6675
}
6776
}
6877
return new Response(null, { status: 500 });

0 commit comments

Comments
 (0)