Closed Grumpfy closed 2 weeks ago
The recent changes introduce enhancements in handling schema generation for collections and pointers to arrays within a Go-based schema registry. The updates include modifications to accurately process arrays and conditionally set schema properties like MinItems
and MaxItems
, leveraging struct tags. Additionally, new test cases have been added to ensure these functionalities are verified comprehensively, especially focusing on custom descriptions and pointer handling.
File | Change Summary |
---|---|
registry.go |
Updated Schema function to handle pointers to arrays by mapping them to arrays before further processing. |
schema.go |
Enhanced SchemaFromField function to conditionally set MinItems and MaxItems based on struct tags. |
schema_test.go |
Added various test cases, including a new type with custom descriptions and tests for array-related schema fields. |
sequenceDiagram
participant Developer
participant Registry
participant Schema
Developer->>Registry: Call Schema(t reflect.Type, ...)
loop Check Type
Registry->>Registry: t.Kind() == reflect.Ptr
Registry->>Registry: Check if t.Elem() is Array or Slice
Registry->>Schema: Decayed Pointer, Process Array
end
Developer->>Schema: Call SchemaFromField with struct field
Schema->>Schema: Check for minItems and maxItems tags
Schema->>Schema: Set MinItems and MaxItems conditionally
Developer->>Tests: Run schema tests on new functionality
Tests->>Results: Validate custom descriptions and array handling
In a code enchanted grove, arrays bloom,
Pointers find their rightful room.
Min and Max, tags now decoded,
Schema's charm’s further loaded.
Tested fields, both near and far,
Shine their light, like a coding star.🌟✨🐇
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Hi!
We have a use case that can be summarised by:
Expected schema:
Actual schema:
We're currently missing the minItems and maxItems for both fields and the custom description is missing if the field is a pointer to the Color4f type.
This PR try to address this issue.
Summary by CodeRabbit
New Features
minItems
andmaxItems
tags for better validation.Tests