elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.27k stars 219 forks source link

Normalize option wrong documentation #746

Closed kravetsone closed 1 month ago

kravetsone commented 2 months ago

What version of Elysia.JS is running?

1.1.3

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

    /**
     * If enabled, the handlers will run a [clean](https://github.com/sinclairzx81/typebox?tab=readme-ov-file#clean) on incoming and outgoing bodies instead of failing directly.
     * This allows for sending unknown or disallowed properties in the bodies. These will simply be filtered out instead of failing the request.
     * This has no effect when the schemas allow additional properties.
     * Since this uses dynamic schema it may have an impact on performance.
     *
     * @default false
     */
    normalize?: boolean;

also lies about it https://elysiajs.com/validation/schema-type.html#constructor

import Elysia, { t } from "elysia";

const child = new Elysia({ normalize: false }).get("/", () => ({ a: 1, b: 2 }), {
    response: t.Object({ a: t.Number() }),
});

const main = new Elysia().use(child);

const resp = await main.handle(new Request("http://localhost/"));
console.log(resp, await resp.json());
Response (0 KB) {
  ok: true,
  url: "",
  status: 200,
  statusText: "",
  headers: Headers {
    "content-type": "application/json;charset=utf-8",
  },
  redirected: false,
  bodyUsed: true
} {
  a: 1,
}

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

SaltyAom commented 2 months ago

normalize is a top-level configuration that works only if set on the root instance.

kravetsone commented 2 months ago

normalize is a top-level configuration that works only if set on the root instance.

Oh yeah

but it also false by default in JS Doc and its lie