Features/2182 zod exclusive #2500
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Support for
exclusiveMinimumandexclusiveMaximumin Zod schema generationFixes #2182
Problem
Currently, Orval's Zod client generates only basic primitives (
z.number(),z.string(), etc.) and does not translate JSON Schema numeric constraints (minimum,exclusiveMinimum,maximum,exclusiveMaximum) into Zod refinements. This means numeric constraints declared in OpenAPI definitions are lost in the generated schemas, creating gaps between backend validation (e.g., Pydantic'sgt=0) and frontend validation in libraries like React Hook Form.Example:
Given an OpenAPI schema with
exclusiveMinimum: 0, the current implementation generates:Instead of:
Solution
Added support for both OpenAPI 3.0 and 3.1 formats:
exclusiveMinimumandexclusiveMaximumare boolean flags indicating whetherminimum/maximumshould be exclusiveexclusiveMinimumandexclusiveMaximumare numeric values themselvesThe implementation automatically detects the format and generates the appropriate Zod constraints:
minimum: n→.min(n)(inclusive)exclusiveMinimum: norexclusiveMinimum: true→.gt(n)(exclusive)maximum: n→.max(n)(inclusive)exclusiveMaximum: norexclusiveMaximum: true→.lt(n)(exclusive)Changes
Enhanced field extraction in
generateZodValidationSchemaDefinition():exclusiveMinimumandexclusiveMaximumfrom schemaUpdated constraint generation logic:
.gt()and.lt()instead of.min()and.max()Comprehensive test coverage: