Skip to content

feat: manage null - #4

Merged
cowan-macady merged 1 commit into
masterfrom
null-management
Jul 23, 2026
Merged

feat: manage null#4
cowan-macady merged 1 commit into
masterfrom
null-management

Conversation

@cowan-macady

@cowan-macady cowan-macady commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

implement ENG-8921

improve null management

@deepsource-io

deepsource-io Bot commented Jul 22, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in f74f60c...5e1535f on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 items schemas 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.

Comment thread gen/schema.go Outdated
Comment on lines +56 to +58
// 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)}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment thread gen/schema.go
Comment on lines +638 to +640
if len(s.AnyOf) == 2 && isPureNull(s.AnyOf[1]) {
return s.AnyOf[0]
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment thread gen/schema.go
Comment on lines 326 to +330
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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copilot AI review requested due to automatic review settings July 22, 2026 16:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 22, 2026 17:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 22, 2026 17:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread gen/constrain.go
Comment on lines +45 to +55
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Copilot AI review requested due to automatic review settings July 22, 2026 17:43
implement [ENG-8921]

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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{}
		}

Copilot AI review requested due to automatic review settings July 22, 2026 17:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread gen/schema.go
Comment on lines +654 to +657
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
}
Comment thread gen/yaml.go
Comment on lines +34 to 37
// 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)
@cowan-macady
cowan-macady merged commit b6d74dc into master Jul 23, 2026
9 checks passed
@cowan-macady
cowan-macady deleted the null-management branch July 23, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants