Skip to content

Commit b4d67e3

Browse files
authored
Merge pull request #16 from gravitational/roman/emptymap
Empty map should not be set as nil
2 parents 93c7897 + 6fc33c9 commit b4d67e3

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

jsonschema/schema.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ func setDefaults(ischema interface{}, ivars interface{}) interface{} {
115115
}
116116
out[key] = defval
117117
}
118-
if len(out) == 0 {
119-
return nil
120-
}
121118
return out
122119
case "array":
123120
var vars []interface{}

jsonschema/schema_test.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (s *SchemaSuite) TestDefaults(c *C) {
4747
},
4848
{
4949
schema: `{
50-
"type": "object",
50+
"type": "object",
5151
"properties": {
5252
"value": {"type": "string", "default": "hello"},
5353
"value2": {"type": "string"}
@@ -60,9 +60,9 @@ func (s *SchemaSuite) TestDefaults(c *C) {
6060
},
6161
{
6262
schema: `{
63-
"type": "array",
63+
"type": "array",
6464
"items": {
65-
"type": "string",
65+
"type": "string",
6666
"default": "hello"
6767
}
6868
}`,
@@ -71,9 +71,9 @@ func (s *SchemaSuite) TestDefaults(c *C) {
7171
},
7272
{
7373
schema: `{
74-
"type": "array",
74+
"type": "array",
7575
"items": {
76-
"type": "object",
76+
"type": "object",
7777
"properties": {
7878
"val": {"type": "string", "default": "hello"}
7979
}
@@ -84,7 +84,7 @@ func (s *SchemaSuite) TestDefaults(c *C) {
8484
},
8585
{
8686
schema: `{
87-
"type": "object",
87+
"type": "object",
8888
"default": {},
8989
"properties": {
9090
"values": {
@@ -105,12 +105,12 @@ func (s *SchemaSuite) TestDefaults(c *C) {
105105
},
106106
{
107107
schema: `{
108-
"type": "object",
108+
"type": "object",
109109
"properties": {
110110
"values": {
111-
"type": "array",
111+
"type": "array",
112112
"items": {
113-
"type": "object",
113+
"type": "object",
114114
"properties": {
115115
"val": {"type": "string", "default": "hello"}
116116
}
@@ -131,6 +131,16 @@ func (s *SchemaSuite) TestDefaults(c *C) {
131131
},
132132
},
133133
},
134+
{
135+
schema: `{
136+
"type": "object",
137+
"properties": {
138+
"value": {"type": "string"}
139+
}
140+
}`,
141+
input: map[string]interface{}{},
142+
output: map[string]interface{}{},
143+
},
134144
}
135145
for i, tc := range tcs {
136146
comment := Commentf("test #%d", i+1)

0 commit comments

Comments
 (0)