feat: manage null - #4
Conversation
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| Go | Jul 22, 2026 5:45p.m. | Review ↗ |
Important
AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.
There was a problem hiding this comment.
Pull request overview
Implements improved nullability handling in the OpenAPI schema generator to better align generated schemas with intended Go/validation semantics.
Changes:
- Emit non-nullable
itemsschemas for slices whose element token starts with*(e.g.[]*T). - For
validate:"required"/binding:"required"fields, remove the nullable branch introduced by pointer types. - Update generator tests to reflect the new slice-item nullability behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
gen/schema.go |
Adjusts schema generation to strip nullability for slice pointer elements and for required pointer fields; adds helper functions to remove nullability. |
gen/gen_test.go |
Updates expectations for named slice types whose element is a pointer so array items are no longer emitted as nullable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Pointer elements ([]*T) are a Go implementation detail; a JSON null | ||
| // element is never valid input, so items are emitted non-nullable. | ||
| return &Schema{Type: []string{"array"}, Items: r.schemaForToken(strings.TrimPrefix(tok[2:], "*"), ctx)} |
| if len(s.AnyOf) == 2 && isPureNull(s.AnyOf[1]) { | ||
| return s.AnyOf[0] | ||
| } |
| if hasTag(tag, "validate", "required") || hasTag(tag, "binding", "required") { | ||
| schema.Required = append(schema.Required, name) | ||
| // A required pointer field rejects JSON null at validation time, | ||
| // so drop the null branch the pointer type added. | ||
| schema.Properties[name] = stripNullable(fieldSchema) |
2accc27 to
63645ba
Compare
63645ba to
199c1fc
Compare
199c1fc to
6fb2145
Compare
6fb2145 to
02fe894
Compare
| case "array": | ||
| item := s.Items | ||
| if item == nil { | ||
| item = &Schema{} | ||
| } | ||
| parts := strings.Split(v, ",") | ||
| arr := make([]any, 0, len(parts)) | ||
| for _, p := range parts { | ||
| arr = append(arr, coerceScalar(strings.TrimSpace(p), item)) | ||
| } | ||
| return arr |
implement [ENG-8921]
02fe894 to
5e1535f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
gen/constrain.go:49
- The new array handling in coerceScalar (comma-splitting examples/defaults/enums for array schemas) isn't covered by a regression test. Since coerceScalar already has a table test, add a couple of cases asserting that an array schema (e.g. []string and []integer) turns "a,b" / "1,2" into a []any with correctly coerced item types.
case "array":
item := s.Items
if item == nil {
item = &Schema{}
}
| func isPureNull(s *Schema) bool { | ||
| return s != nil && len(s.Type) == 1 && s.Type[0] == "null" && | ||
| s.Ref == "" && len(s.Properties) == 0 && len(s.AnyOf) == 0 | ||
| } |
| // Document start marker, so the output survives yamlfmt-style formatters | ||
| // (include_document_start) without churn on regeneration. | ||
| b.WriteString("---\n") | ||
| writeYAMLMap(&b, api.Emit(opt), 0, false) |
implement ENG-8921
improve null management