Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't reference component.response in operation.response #274

Closed
artsiommiksiuk opened this issue Nov 25, 2024 · 4 comments
Closed

Can't reference component.response in operation.response #274

artsiommiksiuk opened this issue Nov 25, 2024 · 4 comments

Comments

@artsiommiksiuk
Copy link

Defining operation object doesn't allow refs in responses:

export const BadRequestResponseZ = registry.registerComponent("responses", "BadRequest", {
    description: "BadRequest",
    content: {
        "application/json": {
            schema: ErrorSchema,
        }
    }
});

const getUser = (): RouteConfig => ({
        summary: "Get user of an organization",
        tags,
        method: "get",
        operationId: "getOrganizationUser",
        path: "/organization/{organizationId}/users",
        request: {
            params: z.object({
                organizationId: z.string().uuid(),
            })
        },
        responses: {
            "400": { '$ref': '#/components/responses/BadRequest' },
        }
    }),

I see BadRequest registered in components.responses, but neither hardcoded, or referenced properly components allowed on RouteConfig. Not on typing level (TS error), neither in runtime (400 response simply discarded from the output).

@artsiommiksiuk
Copy link
Author

My fault. I overlooked the place where I've been testing this.

@artsiommiksiuk
Copy link
Author

artsiommiksiuk commented Nov 25, 2024

Typing is not allowing to write something as BadRequestResponseZ.ref though.

@AGalabov
Copy link
Collaborator

AGalabov commented Dec 3, 2024

@artsiommiksiuk thank you for that. I agree that the responses should allow a $ref object (which is what BadRequestResponseZ.ref would be). I can fix that soon.

However schema: ErrorSchema, would not work in your example since we do not support zod schemas there (only raw JSON).

@AGalabov
Copy link
Collaborator

AGalabov commented Dec 6, 2024

I've added the type change in Release v7.3.0. As mentioned we do not plan to support zod schemas within custom components for the forseeable future

@AGalabov AGalabov closed this as completed Dec 6, 2024
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

No branches or pull requests

2 participants