-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix rendering of nullable+omitempty slices and maps
- Loading branch information
Showing
5 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/resources/go/advanced/nullable-omitempty-map-slice/entities.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Package entities contains generated structures. | ||
package entities | ||
|
||
|
||
|
||
// RequiredNullable structure is generated from "#". | ||
type RequiredNullable struct { | ||
Slice *[]string `json:"slice,omitempty"` | ||
Map *map[string]string `json:"map,omitempty"` | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/resources/go/advanced/nullable-omitempty-map-slice/entities_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package entities | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/swaggest/assertjson" | ||
) | ||
|
||
func TestRequiredNullable_MarshalJSON_roundtrip(t *testing.T) { | ||
var ( | ||
jsonValue = []byte(`{"slice":["aeff"],"map":{"effefd":"dd"}}`) | ||
v RequiredNullable | ||
) | ||
|
||
require.NoError(t, json.Unmarshal(jsonValue, &v)) | ||
|
||
marshaled, err := json.Marshal(v) | ||
require.NoError(t, err) | ||
require.NoError(t, json.Unmarshal(marshaled, &v)) | ||
assertjson.Equal(t, jsonValue, marshaled) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters