-
Notifications
You must be signed in to change notification settings - Fork 32
Fix null type in openapi31 parameter schemas for non-pointer types #158
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -432,6 +432,13 @@ func (r *Reflector) parseParametersIn( | |
| propertySchema := params.PropertySchema | ||
| field := params.Field | ||
|
|
||
| // HTTP parameters cannot be null (only absent), so remove null type | ||
| // for non-pointer, non-ref fields. This mirrors the openapi3 reflector behavior | ||
| // (s.Schema != nil && s.Schema.Nullable != nil && field.Type.Kind() != reflect.Ptr). | ||
| if propertySchema.Ref == nil && field.Type.Kind() != reflect.Ptr { | ||
| propertySchema.RemoveType(jsonschema.Null) | ||
| } | ||
|
Comment on lines
+435
to
+440
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 | Confidence: High Speculative: The fix correctly removes the "null" type from the OpenAPI 3.1 schema for non-pointer parameter fields, aligning with OpenAPI 3 behavior. However, the condition propertySchema.Ref == nil && field.Type.Kind() != reflect.Ptr is slightly broader than the OpenAPI 3 version, which also checks s.Schema.Nullable != nil. The current logic will call RemoveType(jsonschema.Null) on every non-pointer, non-ref field, even if the schema's type array doesn't actually contain jsonschema.Null. While the RemoveType method is likely idempotent, this represents a conceptual mismatch and a minor, unnecessary performance overhead for many fields. The more precise condition would check if the type array includes jsonschema.Null before attempting removal. Code Suggestion: if propertySchema.Ref == nil && field.Type.Kind() != reflect.Ptr && propertySchema.Type.Includes(jsonschema.Null) {
propertySchema.RemoveType(jsonschema.Null)
}Evidence: symbol:jsonschema.Null, method:RemoveType, path:openapi3/reflect.go |
||
|
|
||
| sm, err := propertySchema.ToSchemaOrBool().ToSimpleMap() | ||
| if err != nil { | ||
| return err | ||
|
|
||
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.
[Contextual Comment]
This comment refers to code near real line 426. Anchored to nearest_changed(432) line 432.
P2 | Confidence: Medium
Speculative: The fix is applied within a callback function triggered by internal.ReflectParametersIn. This function's logic and the InterceptPropParams structure are shared with the OpenAPI 3 reflector. While the provided test updates confirm the fix works for the specific test cases, there is no new unit test directly validating the logic of the null-removal condition itself (e.g., for pointer vs. non-pointer fields, or for referenced schemas). Adding a targeted unit test would ensure the behavior is explicitly documented, protected against future regressions, and clarifies the expected interaction between the jsonschema-go library's nullability and the OpenAPI reflector's parameter-specific logic.