Skip to content

Commit f2bf249

Browse files
Jamie Tannajamietanna
authored andcommitted
chore(examples): add nested type to tests
This builds on top of the previous commit's fix to ensure that it gets generated correctly.
1 parent fad490f commit f2bf249

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

examples/output-options/preferskipoptionalpointer/api.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ components:
3131
description: This field should have an optional pointer, as the field-level definition of `x-go-type-skip-optional-pointer` overrides the `prefer-skip-optional-pointer` Output Option.
3232
# NOTE that this overrides the global preference
3333
x-go-type-skip-optional-pointer: false
34+
NestedType:
35+
type: object
36+
properties:
37+
client:
38+
description: This field is optional, but the `prefer-skip-optional-pointer` Output Option ensures that this should not have an optional pointer.
39+
$ref: '#/components/schemas/Client'

examples/output-options/preferskipoptionalpointer/gen.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/output-options/preferskipoptionalpointer/gen_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,32 @@ func TestClient(t *testing.T) {
5454
})
5555
}
5656

57+
func TestNestedType(t *testing.T) {
58+
t.Run("zero value (empty struct) on Client is not omitted", func(t *testing.T) {
59+
nestedType := NestedType{
60+
Client: Client{},
61+
}
62+
63+
b, err := json.Marshal(nestedType)
64+
require.NoError(t, err)
65+
66+
assert.True(t, jsonContainsKey(b, "client"))
67+
})
68+
69+
t.Run("value on Client is not omitted", func(t *testing.T) {
70+
nestedType := NestedType{
71+
Client: Client{
72+
Name: "foo",
73+
},
74+
}
75+
76+
b, err := json.Marshal(nestedType)
77+
require.NoError(t, err)
78+
79+
assert.True(t, jsonContainsKey(b, "client"))
80+
})
81+
}
82+
5783
// jsonContainsKey checks if the given JSON object contains the specified key at the top level.
5884
func jsonContainsKey(b []byte, key string) bool {
5985
var m map[string]any

0 commit comments

Comments
 (0)