-
-
Notifications
You must be signed in to change notification settings - Fork 214
fix(schema): proper array minItems, maxItems and doc reporting in generated schemas #485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(schema): proper array minItems, maxItems and doc reporting in generated schemas #485
Conversation
WalkthroughThe 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 Changes
Sequence Diagram(s)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
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range and nitpick comments (3)
registry.go (1)
Line range hint
145-145
: The//nolint:musttag
directive is unused and should be removed to clean up the code.- return json.Marshal(r.schemas) //nolint:musttag + return json.Marshal(r.schemas)schema_test.go (2)
Line range hint
1025-1025
: The//nolint:musttag
directive is unused and should be removed to clean up the code.- //nolint:musttag
Line range hint
1032-1032
: Similar to the previous comment, the//nolint:musttag
directive here is also unused and should be removed.- //nolint:musttag
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- registry.go (1 hunks)
- schema.go (1 hunks)
- schema_test.go (3 hunks)
Additional context used
golangci-lint
registry.go
145-145: directive
//nolint:musttag
is unused for linter "musttag" (nolintlint)schema_test.go
1025-1025: directive
//nolint:musttag
is unused for linter "musttag" (nolintlint)
1032-1032: directive
//nolint:musttag
is unused for linter "musttag" (nolintlint)
Additional comments not posted (5)
registry.go (1)
74-77
: The logic to handle pointers to arrays by decaying them to their non-pointer types is correct.schema.go (1)
562-567
: Properly handling theminItems
andmaxItems
tags based on the presence of these fields in the struct tag is a good addition for schema validation.schema_test.go (3)
69-74
: Ensure the custom description is applied correctly inTypedArrayWithCustomDesc
.
714-719
: The schema definition forRecursiveChildLoop
correctly setsminItems
andmaxItems
to 1 for thearray
field.
850-893
: The test casefield-custom-array
andfield-ptr-to-custom-array
correctly validate the schema generation forTypedArrayWithCustomDesc
and its pointer version. Both cases ensure that theminItems
andmaxItems
are set to 4, which aligns with the PR objectives to fix issues with these properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Grumpfy thank you!
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