From 985bc444f46cd6beead1ebb6ecc48e2d71045b2d Mon Sep 17 00:00:00 2001 From: Basavaraj PB Date: Thu, 12 Mar 2026 11:51:51 +0530 Subject: [PATCH 1/3] Add +k8s:maxBytes and +k8s:minBytes OpenAPI representation Signed-off-by: Basavaraj PB --- pkg/generators/markers.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pkg/generators/markers.go b/pkg/generators/markers.go index a8af60b6c..32496ca0e 100644 --- a/pkg/generators/markers.go +++ b/pkg/generators/markers.go @@ -113,6 +113,8 @@ type commentTags struct { ExclusiveMinimum *bool `json:"exclusiveMinimum,omitempty"` MaxLength *int64 `json:"maxLength,omitempty"` MinLength *int64 `json:"minLength,omitempty"` + MaxBytes *int64 `json:"maxBytes,omitempty"` + MinBytes *int64 `json:"minBytes,omitempty"` Pattern *string `json:"pattern,omitempty"` MaxItems *int64 `json:"maxItems,omitempty"` MinItems *int64 `json:"minItems,omitempty"` @@ -187,7 +189,13 @@ func (c *commentTags) ValidationSchema() (*spec.Schema, error) { } transformedAdditionalProperties = &spec.SchemaOrBool{Schema: additionalProperties, Allows: true} } + if c.MaxBytes != nil && c.MaxLength == nil { + c.MaxLength = c.MaxBytes + } + if c.MinBytes != nil && c.MinLength == nil { + c.MinLength = c.MinBytes + } res := spec.Schema{ SchemaProps: spec.SchemaProps{ Nullable: isNullable, @@ -249,6 +257,18 @@ func (c commentTags) Validate() error { if c.MaxLength != nil && *c.MaxLength < 0 { err = errors.Join(err, fmt.Errorf("maxLength cannot be negative")) } + if c.MinBytes != nil && *c.MinBytes < 0 { + err = errors.Join(err, fmt.Errorf("minBytes cannot be negative")) + } + if c.MaxBytes != nil && *c.MaxBytes < 0 { + err = errors.Join(err, fmt.Errorf("maxBytes cannot be negative")) + } + if c.MaxLength != nil && c.MaxBytes != nil { + err = errors.Join(err, fmt.Errorf("maxLength and maxBytes cannot both be specified")) + } + if c.MinLength != nil && c.MinBytes != nil { + err = errors.Join(err, fmt.Errorf("minLength and minBytes cannot both be specified")) + } if c.MinItems != nil && *c.MinItems < 0 { err = errors.Join(err, fmt.Errorf("minItems cannot be negative")) } @@ -270,6 +290,9 @@ func (c commentTags) Validate() error { if c.MinLength != nil && c.MaxLength != nil && *c.MinLength > *c.MaxLength { err = errors.Join(err, fmt.Errorf("minLength %d is greater than maxLength %d", *c.MinLength, *c.MaxLength)) } + if c.MinBytes != nil && c.MaxBytes != nil && *c.MinBytes > *c.MaxBytes { + err = errors.Join(err, fmt.Errorf("minBytes %d is greater than maxBytes %d", *c.MinBytes, *c.MaxBytes)) + } if c.MinItems != nil && c.MaxItems != nil && *c.MinItems > *c.MaxItems { err = errors.Join(err, fmt.Errorf("minItems %d is greater than maxItems %d", *c.MinItems, *c.MaxItems)) } From 677e646cac233caa06e3aa3ac08ceae8085cea61 Mon Sep 17 00:00:00 2001 From: Basavaraj PB Date: Sat, 9 May 2026 23:04:29 +0530 Subject: [PATCH 2/3] Address review feedback for maxBytes markers --- pkg/generators/markers.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/generators/markers.go b/pkg/generators/markers.go index 32496ca0e..eb09663d2 100644 --- a/pkg/generators/markers.go +++ b/pkg/generators/markers.go @@ -260,12 +260,6 @@ func (c commentTags) Validate() error { if c.MinBytes != nil && *c.MinBytes < 0 { err = errors.Join(err, fmt.Errorf("minBytes cannot be negative")) } - if c.MaxBytes != nil && *c.MaxBytes < 0 { - err = errors.Join(err, fmt.Errorf("maxBytes cannot be negative")) - } - if c.MaxLength != nil && c.MaxBytes != nil { - err = errors.Join(err, fmt.Errorf("maxLength and maxBytes cannot both be specified")) - } if c.MinLength != nil && c.MinBytes != nil { err = errors.Join(err, fmt.Errorf("minLength and minBytes cannot both be specified")) } @@ -375,6 +369,9 @@ func (c commentTags) ValidateType(t *types.Type) error { if c.MaxLength != nil && !isString { err = errors.Join(err, fmt.Errorf("maxLength can only be used on string types")) } + if c.MaxBytes != nil && !isString { + err = errors.Join(err, fmt.Errorf("maxBytes can only be used on string types")) + } if c.Pattern != nil && !isString { err = errors.Join(err, fmt.Errorf("pattern can only be used on string types")) } From 3a2d2594266e9f65904495497acdfbbaae4bf9cb Mon Sep 17 00:00:00 2001 From: Basavaraj PB Date: Tue, 12 May 2026 21:51:29 +0530 Subject: [PATCH 3/3] removed min/max length validations --- pkg/generators/markers.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pkg/generators/markers.go b/pkg/generators/markers.go index eb09663d2..46d81169a 100644 --- a/pkg/generators/markers.go +++ b/pkg/generators/markers.go @@ -189,13 +189,7 @@ func (c *commentTags) ValidationSchema() (*spec.Schema, error) { } transformedAdditionalProperties = &spec.SchemaOrBool{Schema: additionalProperties, Allows: true} } - if c.MaxBytes != nil && c.MaxLength == nil { - c.MaxLength = c.MaxBytes - } - - if c.MinBytes != nil && c.MinLength == nil { - c.MinLength = c.MinBytes - } + res := spec.Schema{ SchemaProps: spec.SchemaProps{ Nullable: isNullable,