feat(angular): add opt-in runtime validation for Angular request bodies with generated Zod schemas
Acknowledgement
- I acknowledge that issues using this template may be closed without further explanation at the maintainers' discretion.
Comment
Add optional runtime parsing for Angular request bodies
Problem
Orval's Angular generator types request bodies at compile time, but it does not parse them against the generated request schema before sending them. A caller can pass a value from a form, JavaScript, or another untrusted source that does not match the schema. TypeScript types do not validate values at runtime.
The Angular guide documents this limitation: Request bodies are typed but not auto-parsed.
Response validation does not protect outgoing requests. Today, applications that want runtime request validation must parse the body themselves before calling the generated client.
Proposed feature
Add an opt-in setting for the Angular generator to parse eligible JSON request bodies with the matching generated Zod request schema before dispatching the request.
Keep the feature disabled by default so existing generated clients retain their current behavior. The setting name and location in the Orval configuration are open for discussion.
When enabled, the generated client should:
- Parse the body before calling
HttpClientor a custom transport. - Send the parsed schema output, including defaults, stripping, or transforms applied by the schema.
- Accept the schema input type at the method boundary and preserve the distinction between
z.inputandz.outputwhen they differ. - Surface validation errors through the returned Observable's normal error path.
- Avoid sending a request when parsing fails.
Apply this only when Orval has a generated request schema for a JSON body. Do not parse FormData, blobs, text, array buffers, or other non-JSON bodies. Custom mutators should remain unchanged by default, or have a clear opt-in path if Orval can safely wrap them.
Expected behavior
With the setting disabled, generated code behaves as it does today.
With the setting enabled, a valid body is parsed and the parsed output is sent. An invalid body produces a schema validation error and no HTTP request. A schema transform that changes the body must affect the value sent over the network, not only the inferred TypeScript type.
Testing
Please cover the generated Angular client at runtime, not only by asserting on generated source text. A transport-level test should prove that valid input sends the parsed output and invalid input sends no request. Also cover transformed schemas and confirm that non-JSON bodies and custom-mutator paths remain unaffected.
Compatibility
The option should be off by default. Applications that enable it may see validation errors for bodies that previously reached the server, and schema transforms may change the serialized body. Please document this behavior and the input/output type semantics.
Source: orval-labs/orval