Skip to content

Commit

Permalink
Merge pull request #843 from tdakkota/feat/generate-set-null
Browse files Browse the repository at this point in the history
feat(gen): generate `SetNull` for nullables
  • Loading branch information
ernado authored Apr 6, 2023
2 parents 7e68fb8 + f493d05 commit 5904f36
Show file tree
Hide file tree
Showing 9 changed files with 1,338 additions and 0 deletions.
658 changes: 658 additions & 0 deletions examples/ex_github/oas_schemas_gen.go

Large diffs are not rendered by default.

443 changes: 443 additions & 0 deletions examples/ex_test_format/oas_schemas_gen.go

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions gen/_template/schema/generic.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ func (o *{{ $.Name }}) SetTo(v {{ $g.Go }}) {
{{- if $v.Nullable }}
// IsSet returns true if value is Null.
func (o {{ $.ReadOnlyReceiver }}) IsNull() bool { return o.Null }

// SetNull sets value to null.
func (o *{{ $.Name }}) SetToNull() {
{{- if $v.Optional }}
o.Set = true
{{- end }}
{{- if $v.Nullable }}
o.Null = true
{{- end }}
var v {{ $g.Go }}
o.Value = v
}
{{ end }}

// Get returns value and boolean that denotes whether value was set.
Expand Down
51 changes: 51 additions & 0 deletions internal/integration/sample_api/oas_schemas_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions internal/integration/sample_api_nc/oas_schemas_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions internal/integration/sample_api_ns/oas_schemas_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5904f36

Please sign in to comment.