Skip to content

Commit df7d1c6

Browse files
committed
go: Emit null instead of {} for when struct enum config field is nil
1 parent e3313a4 commit df7d1c6

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

go/models/ingest_source_in.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ var IngestSourceInTypeWithNoConfig = map[string]bool{
145145
func (i IngestSourceIn) MarshalJSON() ([]byte, error) {
146146
type Alias IngestSourceIn
147147
if _, found := IngestSourceInTypeWithNoConfig[string(i.Type)]; found {
148-
i.Config = emptyMap{}
148+
i.Config = nil
149149
}
150150
return json.Marshal(&struct{ Alias }{Alias: (Alias)(i)})
151151
}

go/models/ingest_source_out.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ var IngestSourceOutTypeWithNoConfig = map[string]bool{
150150
func (i IngestSourceOut) MarshalJSON() ([]byte, error) {
151151
type Alias IngestSourceOut
152152
if _, found := IngestSourceOutTypeWithNoConfig[string(i.Type)]; found {
153-
i.Config = emptyMap{}
153+
i.Config = nil
154154
}
155155
return json.Marshal(&struct{ Alias }{Alias: (Alias)(i)})
156156
}

go/svix_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ func TestStructEnumWithFields(t *testing.T) {
685685
}
686686

687687
func TestStructEnumWithNoFields(t *testing.T) {
688-
expectedJson := `{"name":"Mendy","uid":"very unique","type":"generic-webhook","config":{}}`
688+
expectedJson := `{"name":"Mendy","uid":"very unique","type":"generic-webhook","config":null}`
689689
uid := "very unique"
690690
sourceIn := models.IngestSourceIn{
691691
Name: "Mendy",
@@ -702,7 +702,7 @@ func TestStructEnumWithNoFields(t *testing.T) {
702702
}
703703

704704
func TestStructEnumWithNoFieldsNilConfig(t *testing.T) {
705-
expectedJson := `{"name":"Mendy","uid":"very unique","type":"generic-webhook","config":{}}`
705+
expectedJson := `{"name":"Mendy","uid":"very unique","type":"generic-webhook","config":null}`
706706
uid := "very unique"
707707
sourceIn := models.IngestSourceIn{
708708
Name: "Mendy",

openapi-templates/go/types/struct_enum.go.jinja

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (i {{ ty_name }}) MarshalJSON() ([]byte, error) {
9393
type Alias {{ ty_name }}
9494
{% if has_variant_with_no_schema_ref -%}
9595
if _, found := {{ ty_name }}{{ discriminator_field }}WithNo{{ content_field }}[string(i.{{ discriminator_field }})]; found {
96-
i.{{ content_field }} = emptyMap{}
96+
i.{{ content_field }} = nil
9797
}
9898
{% endif -%}
9999
return json.Marshal(&struct {Alias}{Alias: (Alias)(i)})

0 commit comments

Comments
 (0)