Fix: enum with nullable property to automatically include null value in validation#240
Merged
daveshanley merged 2 commits intopb33f:mainfrom Feb 14, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #240 +/- ##
=======================================
Coverage 97.61% 97.62%
=======================================
Files 56 56
Lines 5289 5300 +11
=======================================
+ Hits 5163 5174 +11
Misses 126 126
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
daveshanley
approved these changes
Feb 14, 2026
Member
daveshanley
left a comment
There was a problem hiding this comment.
Cool! Which model did this? was it claude or codex?
Contributor
Author
The planning, the majority of the code, and the pull request description were generated by Claude Haiku 4.5, while the tests added at the end were generated by Claude Sonnet 4.5. 😃 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Overview
This pull request fixes an issue where OpenAPI 3.0 schemas with both
nullable: trueandenumproperties fail validation whennullis returned in the response, even though the schema definition allows null values.Problem Statement
When validating a response against an OpenAPI 3.0 specification with the following schema definition, a validation error occurred if the field value was
null:{ "status": { "type": "string", "enum": [ "active", "inactive", "pending", "archived" ], "nullable": true } }Error Message:
Root Cause Analysis
During the investigation phase, we analyzed the OpenAPI 3.0 to JSON Schema conversion process and identified the following:
Investigation Findings
Nullable Transformation Process
helpers/schema_compiler.go-transformOpenAPI30Schema()functiontransformNullableSchema()function converts OpenAPI 3.0'snullable: truekeyword to JSON Schema compatible format by converting thetypefield to an array, e.g.,"string"→["string", "null"]Missing Enum Handling
transformNullableSchema()function had complete type handling (lines 169-191) including:"string"→["string", "null"]["string", "number"]→["string", "number", "null"]Schema Validation Behavior
schema_validation/validate_schema.goExisting Test Coverage Gap
schema_validation/validate_schema_test.go-TestValidateSchema_NullableEnumnullin the enum definition:enum: [value1, value2, ..., null]nullable: truebut enum doesn't contain nullDecision Rationale
We decided to automatically add null to the enum values when
nullable: trueis present and null is not already in the enum for the following reasons:OpenAPI 3.0 Specification Alignment
Principle of Least Surprise
nullable: true, they intuitively expect null to be validDefensive Duplication Prevention
Type vs Enum Consistency
Implementation
Changes Made
File:
helpers/schema_compiler.go-transformNullableSchema()functionAdded enum handling logic after the existing allOf handling:
Logic Flow:
Test Coverage
File:
helpers/schema_compiler_test.go- Added two test casesTestTransformNullableSchema_EnumWithoutNull
nullable: truewith enum lacking null valueTestTransformNullableSchema_EnumWithNull
nullable: truewith enum already containing nullVerification
All tests pass:
Backward Compatibility
Edge Cases Handled
Related Issues
Fixes issue where response validation fails for nullable enum fields when null value is returned, applying the improvements outlined in OpenAPI 3.0 nullable handling best practices.