Skip to content

Commit 2db89d1

Browse files
authored
fix: fix the docs about schema, global schema using guard
1 parent 26cd55e commit 2db89d1

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

docs/essential/schema.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ The response should be listed as follows:
6969

7070
Register hook into **every** handler that came after.
7171

72-
To add a global hook, you can use `.schema` followed by a life cycle event in camelCase:
72+
To add a global hook, you can use `.guard` and provide the schema for each of the properties (body, query, params, etc as listed above) to be validated:
7373

7474
```typescript
7575
import { Elysia, t } from 'elysia'
7676

7777
new Elysia()
7878
.get('/none', () => 'hi')
79-
.schema({ // [!code ++]
79+
.guard({ // [!code ++]
8080
query: t.Object({ // [!code ++]
8181
name: t.String() // [!code ++]
8282
}) // [!code ++]
@@ -85,7 +85,7 @@ new Elysia()
8585
.listen(3000)
8686
```
8787

88-
The response should be listed as follows:
88+
This code ensures that the query must have **name** with a string value for every handler after it. The response should be listed as follows:
8989

9090
| Path | Response |
9191
| ------------- | -------- |
@@ -94,6 +94,4 @@ The response should be listed as follows:
9494
| /query | error |
9595
| /query?name=a | a |
9696

97-
As Lifecycle Event, it is important to remember that the order of Elysia's schema is stored as same as lifecycle, a queue, or first-in-first-out.
98-
99-
Elysia **always** respects the order of code from top to bottom followed by the order of life-cycle event and validation schema.
97+
If multiple global schemas are defined for same property, the latest one will have the preference. If both local and global schemas are defined, the local one will have the preference.

0 commit comments

Comments
 (0)