fix: preserve CRD schema min* validation constraints#18
Draft
jtligon wants to merge 1 commit into
Draft
Conversation
CRD OpenAPI schemas were incorrectly stripping minimum validation constraints (minLength, minItems, minProperties, minimum) when set to 0. In JSON Schema, minLength: 0 has semantic meaning - it explicitly allows empty values. This is different from omitting minLength entirely, which means 'no constraint'. This fix: - Preserves minLength: 0, minItems: 0, etc. as they are meaningful - Only strips obvious sentinel values (negative or very large numbers) - Keeps maximum constraints stripped when 0 (less common use case) This should fix CRD conformance tests that validate schema constraints are properly reflected in /openapi/v2 endpoint. Kubernetes reference: - k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation - JSONSchemaProps allows minLength: 0 as valid constraint Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.
Problem
CRD OpenAPI schemas were incorrectly stripping minimum validation constraints (, , , ) when set to 0.
This caused conformance test failures in the "CRD OpenAPI publishing" category where CRD schema definitions were missing validation fields in the endpoint after CRD creation or update.
Root Cause
In JSON Schema/OpenAPI,
minLength: 0has semantic meaning - it explicitly allows empty values. This is different from omittingminLengthentirely.The code was treating all zero-value constraints as "unset" and stripping them per Go's
omitemptybehavior. However, for minimum constraints, 0 is a valid and meaningful value.Fix
minLength: 0,minItems: 0,minProperties: 0,minimum: 0as they are semantically meaningfulmaxLength: 0)Testing
Kubernetes Reference
k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validationJSONSchemaPropsallowsminLength: 0as a valid constraintomitemptyapplies to pointer types, but 0 is still a valid dereferenced valueRelated Category
Part of fixing CRD OpenAPI publishing failures (~9 tests in Round 147).
🤖 Generated with Claude Code