Skip to content

Commit

Permalink
fix: indicate which elements are supported
Browse files Browse the repository at this point in the history
  • Loading branch information
su8ru committed Nov 18, 2022
1 parent 09603dc commit a45e1cb
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions docs/reference/validation/zod.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ Frourio uses zod for validation; see the documentation at the link above for a d
## Two Types of validators {#two-types-of-validators}

Frourio provides two types of validators: **Controller-level Validators** and **Directory-level Validators**.
The elements that can be validated in each are different.

- **Controller-level Validators**: called at the current endpoints.
- **Controller-level Validators**: called at the current endpoints. **`params` cannot be validated.**
- `query`
- `headers`
- `body`
- **Directory-level Validators**: called at the current _and subordinate_ endpoints. **Only `params` can be validated.**
- `params`

:::note

Expand Down Expand Up @@ -103,16 +108,28 @@ export default defineValidators(() => ({

#### Argument Type {#definevalidators-argument-type}

- function `(fastify: FastifyInstance) => { params: z.ZodType<{ (params type) }> }`
- `{ (params type) }` : URL parameters type defined in `./index.ts`.
- function `(fastify: FastifyInstance) => { params: (zod object schema) }`

The actial type difinition of `(zod object schema)` is `z.ZodType<{ (params type) }>`, but there is no need to be aware of this.
This ensures consistency with the API type difinitions.

\* `{ (params type) }` : The type difinition of the URL parameter that the directory has.
It does not include that of the upper-level directory.
If unspecified, it will be `string`, but as noted on [Automatic Validation page](/docs/reference/validation/automatic#path-parameter), it is recommended that it be specified.

</TabItem>
<TabItem value="express">

#### Argument Type {#definevalidators-argument-type}

- function `(app: Express) => { params: z.ZodType<{ (params type) }> }`
- `{ (params type) }` : URL parameters type defined in `./index.ts`.
- function `(app: Express) => { params: (zod object schema) }`

The actial type difinition of `(zod object schema)` is `z.ZodType<{ (params type) }>`, but there is no need to be aware of this.
This ensures consistency with the API type difinitions.

\* `{ (params type) }` : The type difinition of the URL parameter that the directory has.
It does not include that of the upper-level directory.
If unspecified, it will be `string`, but as noted on [Automatic Validation page](/docs/reference/validation/automatic#path-parameter), it is recommended that it be specified.

</TabItem>
</Tabs>

0 comments on commit a45e1cb

Please sign in to comment.