-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathmerge_schemas_test.go
More file actions
68 lines (53 loc) · 2.01 KB
/
merge_schemas_test.go
File metadata and controls
68 lines (53 loc) · 2.01 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package codegen
import (
"testing"
"github.com/getkin/kin-openapi/openapi3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMergeOpenapiSchemas_DiscriminatorPropagation(t *testing.T) {
disc := &openapi3.Discriminator{
PropertyName: "type",
}
t.Run("allOf with single discriminator on s1 propagates it", func(t *testing.T) {
s1 := openapi3.Schema{Discriminator: disc}
s2 := openapi3.Schema{}
result, err := mergeOpenapiSchemas(s1, s2, true, make(map[string]bool))
require.NoError(t, err)
assert.Equal(t, disc, result.Discriminator)
})
t.Run("allOf with single discriminator on s2 propagates it", func(t *testing.T) {
s1 := openapi3.Schema{}
s2 := openapi3.Schema{Discriminator: disc}
result, err := mergeOpenapiSchemas(s1, s2, true, make(map[string]bool))
require.NoError(t, err)
assert.Equal(t, disc, result.Discriminator)
})
t.Run("allOf with discriminators on both schemas errors", func(t *testing.T) {
disc2 := &openapi3.Discriminator{PropertyName: "kind"}
s1 := openapi3.Schema{Discriminator: disc}
s2 := openapi3.Schema{Discriminator: disc2}
_, err := mergeOpenapiSchemas(s1, s2, true, make(map[string]bool))
require.Error(t, err)
assert.Contains(t, err.Error(), "discriminators")
})
t.Run("allOf with no discriminators succeeds with nil discriminator", func(t *testing.T) {
s1 := openapi3.Schema{}
s2 := openapi3.Schema{}
result, err := mergeOpenapiSchemas(s1, s2, true, make(map[string]bool))
require.NoError(t, err)
assert.Nil(t, result.Discriminator)
})
t.Run("non-allOf with discriminator on s1 errors", func(t *testing.T) {
s1 := openapi3.Schema{Discriminator: disc}
s2 := openapi3.Schema{}
_, err := mergeOpenapiSchemas(s1, s2, false, make(map[string]bool))
require.Error(t, err)
})
t.Run("non-allOf with discriminator on s2 errors", func(t *testing.T) {
s1 := openapi3.Schema{}
s2 := openapi3.Schema{Discriminator: disc}
_, err := mergeOpenapiSchemas(s1, s2, false, make(map[string]bool))
require.Error(t, err)
})
}