Skip to content

Path params are not using Schema Types #159

@WilliamABradley

Description

@WilliamABradley

It seems these get inlined instead of using the shared schema type.

Current:

const endpoints = makeApi([
    {
        method: "get",
        path: "/users/:id",
        requestFormat: "json",
        parameters: [
            {
                name: "id",
                type: "Path",
                schema: z.string().regex(/^user_[a-z0-9]{25,27}$/),
            },
        ],
        response: z.union([
            z.object({ success: z.literal(true), item: User }),
            z.object({
                success: z.literal(false),
                message: z.string().optional(),
                issues: z.array(APIIssue).optional(),
            }),
        ]),
        errors: [
            {
                status: 400,
                description: `Bad Request`,
                schema: z.object({
                    success: z.literal(false),
                    message: z.string().optional(),
                    issues: z.array(APIIssue).optional(),
                }),
            },
        ],
    },
]);

Expected:

const UserId = z.string().regex(/^user_[a-z0-9]{25,27}$/);

const User = z.object({
    _id: UserId,
    full_name: z.string().optional(),
    email: z.string().optional(),
});

const endpoints = makeApi([
    {
        method: "get",
        path: "/users/:id",
        requestFormat: "json",
        parameters: [
            {
                name: "id",
                type: "Path",
                schema: UserId,
            },
        ],
        response: z.union([
            z.object({ success: z.literal(true), item: User }),
            z.object({
                success: z.literal(false),
                message: z.string().optional(),
                issues: z.array(APIIssue).optional(),
            }),
        ]),
        errors: [
            {
                status: 400,
                description: `Bad Request`,
                schema: z.object({
                    success: z.literal(false),
                    message: z.string().optional(),
                    issues: z.array(APIIssue).optional(),
                }),
            },
        ],
    },
]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions