-
Notifications
You must be signed in to change notification settings - Fork 0
/
discriminator_test.go
47 lines (43 loc) · 1.01 KB
/
discriminator_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package chioas
import (
"github.com/go-andiamo/chioas/yaml"
"github.com/stretchr/testify/assert"
"testing"
)
func TestDiscriminator_WriteYaml(t *testing.T) {
d := &Discriminator{}
w := yaml.NewWriter(nil)
d.writeYaml(w)
_, err := w.Bytes()
assert.Error(t, err)
d = &Discriminator{
PropertyName: "foo",
Additional: &testAdditional{},
Extensions: map[string]any{"foo": "bar"},
Comment: "this is a comment",
}
w = yaml.NewWriter(nil)
d.writeYaml(w)
data, err := w.Bytes()
assert.NoError(t, err)
const expect = `discriminator:
#this is a comment
propertyName: foo
x-foo: bar
foo: bar
`
assert.Equal(t, expect, string(data))
d = &Discriminator{
PropertyName: "foo",
Mapping: map[string]string{
"a": "my-schema1",
"b": "my-schema2",
},
}
w = yaml.NewWriter(nil)
d.writeYaml(w)
data, err = w.Bytes()
assert.NoError(t, err)
assert.Contains(t, string(data), ` a: "#/components/schemas/my-schema1"`)
assert.Contains(t, string(data), ` b: "#/components/schemas/my-schema2"`)
}