Skip to content

feat(endpoint): support regex in endpoint parameters#66

Open
nicolamacoir wants to merge 1 commit intoevertdespiegeleer:mainfrom
nicolamacoir:feat/support-for-regex-in-endpoints
Open

feat(endpoint): support regex in endpoint parameters#66
nicolamacoir wants to merge 1 commit intoevertdespiegeleer:mainfrom
nicolamacoir:feat/support-for-regex-in-endpoints

Conversation

@nicolamacoir
Copy link
Copy Markdown

Currently, regular expressions are not supported in the path of endpoints in zhttp.

Example:

controller.endpoint(
  get('/:code([a-Z]{3})')
    .input(
      z.object({
        params: z.object({
          code: z.string(),
        }),
      }),
    )
    .handler(async ({ params: { code } }, req, res) => {
    }),
);

Will throw a typing error:

Argument of type 'ZodObject<{ params: ZodObject<{ code: ZodString; }, "strip", ZodTypeAny, { code: string; }, { code: string; }>; }, "strip", ZodTypeAny, { ...; }, { ...; }>' is not assignable to parameter of type 'InputValidationSchema<"/:code([a-Z]{3})">'.
  Type '{ params: z.ZodObject<{ code: z.ZodString; }, "strip", z.ZodTypeAny, { code: string; }, { code: string; }>; }' is not assignable to type '{ params?: ZodObject<{ "code([a-Z]{3})": ZodString; }, UnknownKeysParam, ZodTypeAny, { "code([a-Z]{3})": string; }, { ...; }> | undefined; query?: ZodObject<...> | undefined; body?: ZodType<...> | undefined; }'.
    Types of property 'params' are incompatible.
      Type 'ZodObject<{ code: ZodString; }, "strip", ZodTypeAny, { code: string; }, { code: string; }>' is not assignable to type 'ZodObject<{ "code([a-Z]{3})": ZodString; }, UnknownKeysParam, ZodTypeAny, { "code([a-Z]{3})": string; }, { ...; }>'.
        Property '"code([a-Z]{3})"' is missing in type '{ code: z.ZodString; }' but required in type '{ "code([a-Z]{3})": ZodString; }'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant