Skip to content

Commit 897e883

Browse files
committed
Allow empty lists
1 parent bfaf10b commit 897e883

File tree

2 files changed

+120
-67
lines changed

2 files changed

+120
-67
lines changed

loader/loader_test.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,27 @@ services:
697697
image: busybox
698698
environment: "FOO=1"
699699
`)
700-
assert.ErrorContains(t, err, "services.dict-env.environment must be a mapping")
700+
assert.ErrorContains(t, err, "services.dict-env.environment must be a list")
701+
}
702+
703+
func TestCommentedEnvironmentObject(t *testing.T) {
704+
config, err := loadYAML(`
705+
name: commented-environment-object
706+
services:
707+
commented-env:
708+
image: busybox
709+
environment:
710+
#- FOO=1
711+
`)
712+
assert.NilError(t, err)
713+
714+
expected := types.MappingWithEquals{}
715+
716+
assert.Check(t, is.Equal(1, len(config.Services)))
717+
718+
for _, service := range config.Services {
719+
assert.Check(t, is.DeepEqual(expected, service.Environment))
720+
}
701721
}
702722

703723
func TestLoadWithEnvironmentInterpolation(t *testing.T) {
@@ -2261,7 +2281,7 @@ services:
22612281
context: .
22622282
ssh:
22632283
`)
2264-
assert.ErrorContains(t, err, "services.test.build.ssh must be a mapping")
2284+
assert.ErrorContains(t, err, "services.test.build.ssh: invalid type <nil> for ssh")
22652285
}
22662286

22672287
func TestLoadLegacyBoolean(t *testing.T) {

schema/compose-spec.json

+98-65
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@
1717
},
1818

1919
"include": {
20-
"type": "array",
21-
"items": {
22-
"type": "object",
23-
"$ref": "#/definitions/include"
24-
},
25-
"description": "compose sub-projects to be included."
20+
"oneOf": [
21+
{
22+
"type": "array",
23+
"items": {
24+
"type": "object",
25+
"$ref": "#/definitions/include"
26+
},
27+
"description": "compose sub-projects to be included."
28+
},
29+
{"type": "null"}
30+
]
2631
},
2732

2833
"services": {
@@ -103,12 +108,12 @@
103108
"context": {"type": "string"},
104109
"dockerfile": {"type": "string"},
105110
"dockerfile_inline": {"type": "string"},
106-
"entitlements": {"type": "array", "items": {"type": "string"}},
111+
"entitlements": {"$ref": "#/definitions/list_of_strings"},
107112
"args": {"$ref": "#/definitions/list_or_dict"},
108113
"ssh": {"$ref": "#/definitions/list_or_dict"},
109114
"labels": {"$ref": "#/definitions/list_or_dict"},
110-
"cache_from": {"type": "array", "items": {"type": "string"}},
111-
"cache_to": {"type": "array", "items": {"type": "string"}},
115+
"cache_from": {"$ref": "#/definitions/list_of_strings"},
116+
"cache_to": {"$ref": "#/definitions/list_of_strings"},
112117
"no_cache": {"type": ["boolean", "string"]},
113118
"additional_contexts": {"$ref": "#/definitions/list_or_dict"},
114119
"network": {"type": "string"},
@@ -119,9 +124,9 @@
119124
"isolation": {"type": "string"},
120125
"privileged": {"type": ["boolean", "string"]},
121126
"secrets": {"$ref": "#/definitions/service_config_or_secret"},
122-
"tags": {"type": "array", "items": {"type": "string"}},
127+
"tags": {"$ref": "#/definitions/list_of_strings"},
123128
"ulimits": {"$ref": "#/definitions/ulimits"},
124-
"platforms": {"type": "array", "items": {"type": "string"}}
129+
"platforms": {"$ref": "#/definitions/list_of_strings"}
125130
},
126131
"additionalProperties": false,
127132
"patternProperties": {"^x-": {}}
@@ -132,31 +137,26 @@
132137
"type": "object",
133138
"properties": {
134139
"device_read_bps": {
135-
"type": "array",
136-
"items": {"$ref": "#/definitions/blkio_limit"}
140+
"$ref": "#/definitions/blkio_limit_list"
137141
},
138142
"device_read_iops": {
139-
"type": "array",
140-
"items": {"$ref": "#/definitions/blkio_limit"}
143+
"$ref": "#/definitions/blkio_limit_list"
141144
},
142145
"device_write_bps": {
143-
"type": "array",
144-
"items": {"$ref": "#/definitions/blkio_limit"}
146+
"$ref": "#/definitions/blkio_limit_list"
145147
},
146148
"device_write_iops": {
147-
"type": "array",
148-
"items": {"$ref": "#/definitions/blkio_limit"}
149+
"$ref": "#/definitions/blkio_limit_list"
149150
},
150151
"weight": {"type": ["integer", "string"]},
151152
"weight_device": {
152-
"type": "array",
153-
"items": {"$ref": "#/definitions/blkio_weight"}
153+
"$ref": "#/definitions/blkio_weight_list"
154154
}
155155
},
156156
"additionalProperties": false
157157
},
158-
"cap_add": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
159-
"cap_drop": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
158+
"cap_add": {"$ref": "#/definitions/list_of_unique_strings"},
159+
"cap_drop": {"$ref": "#/definitions/list_of_unique_strings"},
160160
"cgroup": {"type": "string", "enum": ["host", "private"]},
161161
"cgroup_parent": {"type": "string"},
162162
"command": {"$ref": "#/definitions/command"},
@@ -189,7 +189,7 @@
189189
},
190190
"depends_on": {
191191
"oneOf": [
192-
{"$ref": "#/definitions/list_of_strings"},
192+
{"$ref": "#/definitions/list_of_unique_strings"},
193193
{
194194
"type": "object",
195195
"additionalProperties": false,
@@ -215,10 +215,10 @@
215215
}
216216
]
217217
},
218-
"device_cgroup_rules": {"$ref": "#/definitions/list_of_strings"},
219-
"devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
218+
"device_cgroup_rules": {"$ref": "#/definitions/list_of_unique_strings"},
219+
"devices": {"$ref": "#/definitions/list_of_unique_strings"},
220220
"dns": {"$ref": "#/definitions/string_or_list"},
221-
"dns_opt": {"type": "array","items": {"type": "string"}, "uniqueItems": true},
221+
"dns_opt": {"$ref": "#/definitions/list_of_unique_strings"},
222222
"dns_search": {"$ref": "#/definitions/string_or_list"},
223223
"domainname": {"type": "string"},
224224
"entrypoint": {"$ref": "#/definitions/command"},
@@ -248,7 +248,7 @@
248248
}
249249
]
250250
},
251-
"external_links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
251+
"external_links": {"$ref": "#/definitions/list_of_unique_strings"},
252252
"extra_hosts": {"$ref": "#/definitions/list_or_dict"},
253253
"group_add": {
254254
"type": "array",
@@ -264,7 +264,7 @@
264264
"ipc": {"type": "string"},
265265
"isolation": {"type": "string"},
266266
"labels": {"$ref": "#/definitions/list_or_dict"},
267-
"links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
267+
"links": {"$ref": "#/definitions/list_of_unique_strings"},
268268
"logging": {
269269
"type": "object",
270270

@@ -288,7 +288,7 @@
288288
"network_mode": {"type": "string"},
289289
"networks": {
290290
"oneOf": [
291-
{"$ref": "#/definitions/list_of_strings"},
291+
{"$ref": "#/definitions/list_of_unique_strings"},
292292
{
293293
"type": "object",
294294
"patternProperties": {
@@ -297,10 +297,10 @@
297297
{
298298
"type": "object",
299299
"properties": {
300-
"aliases": {"$ref": "#/definitions/list_of_strings"},
300+
"aliases": {"$ref": "#/definitions/list_of_unique_strings"},
301301
"ipv4_address": {"type": "string"},
302302
"ipv6_address": {"type": "string"},
303-
"link_local_ips": {"$ref": "#/definitions/list_of_strings"},
303+
"link_local_ips": {"$ref": "#/definitions/list_of_unique_strings"},
304304
"mac_address": {"type": "string"},
305305
"driver_opts": {
306306
"type": "object",
@@ -354,7 +354,7 @@
354354
"uniqueItems": true
355355
},
356356
"privileged": {"type": ["boolean", "string"]},
357-
"profiles": {"$ref": "#/definitions/list_of_strings"},
357+
"profiles": {"$ref": "#/definitions/list_of_unique_strings"},
358358
"pull_policy": {"type": "string", "enum": [
359359
"always", "never", "if_not_present", "build", "missing"
360360
]},
@@ -366,7 +366,7 @@
366366
"scale": {
367367
"type": ["integer", "string"]
368368
},
369-
"security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
369+
"security_opt": {"$ref": "#/definitions/list_of_unique_strings"},
370370
"shm_size": {"type": ["number", "string"]},
371371
"secrets": {"$ref": "#/definitions/service_config_or_secret"},
372372
"sysctls": {"$ref": "#/definitions/list_or_dict"},
@@ -436,9 +436,7 @@
436436
"uniqueItems": true
437437
},
438438
"volumes_from": {
439-
"type": "array",
440-
"items": {"type": "string"},
441-
"uniqueItems": true
439+
"$ref": "#/definitions/list_of_unique_strings"
442440
},
443441
"working_dir": {"type": "string"}
444442
},
@@ -456,7 +454,7 @@
456454
"test": {
457455
"oneOf": [
458456
{"type": "string"},
459-
{"type": "array", "items": {"type": "string"}}
457+
{"$ref": "#/definitions/list_of_strings"}
460458
]
461459
},
462460
"timeout": {"type": "string"},
@@ -476,7 +474,7 @@
476474
"type": "object",
477475
"required": ["path", "action"],
478476
"properties": {
479-
"ignore": {"type": "array", "items": {"type": "string"}},
477+
"ignore": {"$ref": "#/definitions/list_of_strings"},
480478
"path": {"type": "string"},
481479
"action": {"type": "string", "enum": ["rebuild", "sync", "sync+restart"]},
482480
"target": {"type": "string"}
@@ -567,7 +565,7 @@
567565
"placement": {
568566
"type": "object",
569567
"properties": {
570-
"constraints": {"type": "array", "items": {"type": "string"}},
568+
"constraints": {"$ref": "#/definitions/list_of_strings"},
571569
"preferences": {
572570
"type": "array",
573571
"items": {
@@ -616,9 +614,9 @@
616614
"items": {
617615
"type": "object",
618616
"properties": {
619-
"capabilities": {"$ref": "#/definitions/list_of_strings"},
617+
"capabilities": {"$ref": "#/definitions/list_of_unique_strings"},
620618
"count": {"type": ["string", "integer"]},
621-
"device_ids": {"$ref": "#/definitions/list_of_strings"},
619+
"device_ids": {"$ref": "#/definitions/list_of_unique_strings"},
622620
"driver":{"type": "string"},
623621
"options":{"$ref": "#/definitions/list_or_dict"}
624622
},
@@ -790,12 +788,13 @@
790788
"oneOf": [
791789
{"type": "null"},
792790
{"type": "string"},
793-
{"type": "array","items": {"type": "string"}}
791+
{"type": "array", "items": {"type": "string"}}
794792
]
795793
},
796794

797795
"env_file": {
798796
"oneOf": [
797+
{"type": "null"},
799798
{"type": "string"},
800799
{
801800
"type": "array",
@@ -827,14 +826,29 @@
827826
"string_or_list": {
828827
"oneOf": [
829828
{"type": "string"},
830-
{"$ref": "#/definitions/list_of_strings"}
829+
{"$ref": "#/definitions/list_of_unique_strings"}
830+
]
831+
},
832+
833+
"list_of_unique_strings": {
834+
"oneOf": [
835+
{
836+
"type": "array",
837+
"items": {"type": "string"},
838+
"uniqueItems": true
839+
},
840+
{"type": "null"}
831841
]
832842
},
833843

834844
"list_of_strings": {
835-
"type": "array",
836-
"items": {"type": "string"},
837-
"uniqueItems": true
845+
"oneOf": [
846+
{
847+
"type": "array",
848+
"items": {"type": "string"}
849+
},
850+
{"type": "null"}
851+
]
838852
},
839853

840854
"list_or_dict": {
@@ -848,7 +862,7 @@
848862
},
849863
"additionalProperties": false
850864
},
851-
{"type": "array", "items": {"type": "string"}, "uniqueItems": true}
865+
{"$ref": "#/definitions/list_of_unique_strings"}
852866
]
853867
},
854868

@@ -860,6 +874,13 @@
860874
},
861875
"additionalProperties": false
862876
},
877+
"blkio_limit_list": {
878+
"oneOf": [
879+
{"type": "array", "items": {"$ref": "#/definitions/blkio_limit"}},
880+
{"type": "null"}
881+
]
882+
},
883+
863884
"blkio_weight": {
864885
"type": "object",
865886
"properties": {
@@ -868,25 +889,37 @@
868889
},
869890
"additionalProperties": false
870891
},
892+
"blkio_weight_list": {
893+
"oneOf": [
894+
{"type": "array", "items": {"$ref": "#/definitions/blkio_weight"}},
895+
{"type": "null"}
896+
]
897+
},
898+
871899
"service_config_or_secret": {
872-
"type": "array",
873-
"items": {
874-
"oneOf": [
875-
{"type": "string"},
876-
{
877-
"type": "object",
878-
"properties": {
879-
"source": {"type": "string"},
880-
"target": {"type": "string"},
881-
"uid": {"type": "string"},
882-
"gid": {"type": "string"},
883-
"mode": {"type": ["number", "string"]}
884-
},
885-
"additionalProperties": false,
886-
"patternProperties": {"^x-": {}}
900+
"oneOf": [
901+
{"type": "null"},
902+
{
903+
"type": "array",
904+
"items": {
905+
"oneOf": [
906+
{"type": "string"},
907+
{
908+
"type": "object",
909+
"properties": {
910+
"source": {"type": "string"},
911+
"target": {"type": "string"},
912+
"uid": {"type": "string"},
913+
"gid": {"type": "string"},
914+
"mode": {"type": ["number", "string"]}
915+
},
916+
"additionalProperties": false,
917+
"patternProperties": {"^x-": {}}
918+
}
919+
]
887920
}
888-
]
889-
}
921+
}
922+
]
890923
},
891924
"ulimits": {
892925
"type": "object",

0 commit comments

Comments
 (0)