Zod: Runtime validation and output schemas are missing for primitive response types
Description
When runtimeValidation: true is enabled, primitive response schemas such as number and integer do not generate corresponding Zod schemas or runtime validation. Additionally, the generated Zod output types for error responses are not imported or used by the generated client.
Output client
zod
Configuration (orval.config)
export default defineConfig({
example: {
input: `../docs/source/openapi/example_openapi.yml`,
output: {
target: `${outputDir}/example/client.ts`,
packageJson: "package.json5",
mode: "single",
client: "react-query",
httpClient: "fetch",
formatter: "oxfmt",
clean: true,
schemas: {
path: `${outputDir}/example/schemas`,
type: "zod",
mode: "single",
},
override: {
fetch: {
runtimeValidation: true,
}
},
},
}
});and
export default defineConfig({
example: {
input: `../docs/source/openapi/example_openapi.yml`,
output: {
target: `${outputDir}/example/client.ts`,
packageJson: "package.json5",
mode: "single",
client: "react-query",
httpClient: "fetch",
formatter: "oxfmt",
clean: true,
schemas: {
path: `${outputDir}/example/schemas`,
type: "zod",
mode: "single",
},
override: {
query: {
runtimeValidation: true,
}
},
},
}
});
Environment
System: OS: Linux 7.0 Ubuntu 26.04.1 LTS 26.04.1 LTS (Resolute Raccoon) CPU: (14) x64 Intel(R) Core(TM) Ultra 7 155U Memory: 19.52 GB / 30.85 GB Container: Yes Shell: 5.3.9 - /bin/bash
Expected behavior
Primitive response schemas should generate corresponding Zod schemas and use them for runtime validation. The generated client should also import and use the corresponding Output types where applicable.
Actual behavior
The generated client has the same behavior for GET, POST, and PUT endpoints with primitive response schemas. In each case, the response is only deserialized with JSON.parse() and is not validated against a generated Zod schema.
// GET
const data: getCurrentTemperatureResponse["data"] = body
? JSON.parse(body)
: {};
// POST
const data: postTriggerResponse["data"] = body
? JSON.parse(body)
: {};
// PUT
const data: putTemperatureResponse["data"] = body
? JSON.parse(body)
: {};No corresponding Zod schemas are generated for the primitive number or integer responses, so there is no .parse() call for these responses.
The same issue occurs when runtimeValidation: true is configured for React Query:
override: {
query: {
runtimeValidation: true,
},
},For GET, POST, and PUT endpoints with primitive response schemas such as number or integer, the generated client does not generate or use a corresponding Zod schema for runtime validation.
Instead, the response is only deserialized with JSON.parse():
const data = body
? JSON.parse(body)
: {};Additionally, Output types generated for other response schemas are not imported or used by the generated client.
OpenAPI document (minimal, if applicable)
openapi: 3.1.0
info:
title: example
version: 1.0.0
paths:
/current-temperature:
get:
summary: Get Current Temperature
operationId: get_current_temperature
responses:
"200":
description: Successful Response
content:
application/json:
schema:
title: Response Get Current Temperature
type: number
"500":
description: Internal Server Error
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
/trigger:
post:
summary: Trigger Camera
operationId: post_trigger
responses:
"200":
description: Successful Response
content:
application/json:
schema:
title: Response Post Trigger
type: integer
"500":
description: Internal Server Error
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
/temperature:
put:
summary: Set Temperature
operationId: put_temperature
responses:
"200":
description: Successful Response
content:
application/json:
schema:
title: Response Put Temperature
type: number
"500":
description: Internal Server Error
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
components:
schemas:
ErrorResponse:
type: object
required:
- message
- code
properties:
message:
type: string
code:
type: integerAdditional context
Small other bug: The React Query runtime validation documentation describes the runtimeValidation option in the context of the Angular client rather than the React Query client.
Source: orval-labs/orval