cloudflare / cloudflare/chanfana

Custom request body validation

Open
#97 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
766
Forks
70
Avg merge
25m
Merged PRs (30d)
4

Description

Is there a way to make use of the zod `Schema.strict` in the automatic validation of a request body? Or override/disable the automatic validation?

At the moment if I create a schema
```typescript
const TestSchema = z.object({
foo: z.string()
})

class TestPost extends OpenAPIRoute {
static schema = {
requestBody: TestSchema,
}
...
}
```

And then send this payload to the route
```json
{
"foo": "example",
"bar": "example"
}
```

this will be accepted as valid even though "bar" is not a valid property on `TestSchema`
`TestSchema.strict(...)` is how I would handle this manually but unsure how/if the default validation behaviour would be modified. Or is the only way to handle this to parse the data again in the handler?

Contributor guide

Open the contributing guide

Research direction

No source file, test, or entry point is named. Start by locating the automatic request-body validation used by OpenAPIRoute and its existing tests; then determine how strict unknown-property rejection and validation override or disabling should be represented. Done means the documented behavior is covered for the shown schema and payload, including the chosen handler behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.