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

Guard group break responses validation #1158

Open
zoriya opened this issue Apr 5, 2025 · 0 comments
Open

Guard group break responses validation #1158

zoriya opened this issue Apr 5, 2025 · 0 comments

Comments

@zoriya
Copy link
Contributor

zoriya commented Apr 5, 2025

With the following code (and elysia v1.2.25)

import { Elysia, t } from "elysia";

new Elysia()
	.guard(
		{
			response: {
				403: t.String()
			},
		},
		(app) =>
			app
				.get("/foo", () => "bar", { response: { 200: t.String() } })
				.get("/bar", () => 12, { response: { 200: t.Integer() } }),
	)
	.listen(3500);

doing curl localhost:3500/foo gives

{
  "type": "validation",
  "on": "response",
  "summary": "Value should be one of 'integer', 'integer'",
  "property": "root",
  "message": "Expected union value",
  "expected": 0,
  "found": "bar",
  "errors": [
    {
      "type": 62,
      "schema": {
        "anyOf": [
          {
            "format": "integer",
            "default": 0,
            "type": "string"
          },
          {
            "type": "integer"
          }
        ]
      },
      "path": "",
      "value": "bar",
      "message": "Expected union value",
      "errors": [
        {
          "iterator": {}
        },
        {
          "iterator": {}
        }
      ],
      "summary": "Value should be one of 'integer', 'integer'"
    }
  ]
}

while /bar works. Removing the response: { 403: t.String() } from the guard also makes this validation error go away.

It seems like the last response from the guard is used for every routes of it.

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

1 participant