Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty (null) lists #670

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,27 @@ services:
image: busybox
environment: "FOO=1"
`)
assert.ErrorContains(t, err, "services.dict-env.environment must be a mapping")
assert.ErrorContains(t, err, "services.dict-env.environment must be a list")
}

func TestCommentedEnvironmentObject(t *testing.T) {
config, err := loadYAML(`
name: commented-environment-object
services:
commented-env:
image: busybox
environment:
#- FOO=1
`)
assert.NilError(t, err)

expected := types.MappingWithEquals{}

assert.Check(t, is.Equal(1, len(config.Services)))

for _, service := range config.Services {
assert.Check(t, is.DeepEqual(expected, service.Environment))
}
}

func TestLoadWithEnvironmentInterpolation(t *testing.T) {
Expand Down Expand Up @@ -2261,7 +2281,7 @@ services:
context: .
ssh:
`)
assert.ErrorContains(t, err, "services.test.build.ssh must be a mapping")
assert.ErrorContains(t, err, "services.test.build.ssh: invalid type <nil> for ssh")
}

func TestLoadLegacyBoolean(t *testing.T) {
Expand Down
163 changes: 98 additions & 65 deletions schema/compose-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@
},

"include": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/include"
},
"description": "compose sub-projects to be included."
"oneOf": [
{
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/include"
},
"description": "compose sub-projects to be included."
},
{"type": "null"}
]
},

"services": {
Expand Down Expand Up @@ -103,12 +108,12 @@
"context": {"type": "string"},
"dockerfile": {"type": "string"},
"dockerfile_inline": {"type": "string"},
"entitlements": {"type": "array", "items": {"type": "string"}},
"entitlements": {"$ref": "#/definitions/list_of_strings"},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these could possibly be list_of_unique_strings but that would technically be a breaking change.

"args": {"$ref": "#/definitions/list_or_dict"},
"ssh": {"$ref": "#/definitions/list_or_dict"},
"labels": {"$ref": "#/definitions/list_or_dict"},
"cache_from": {"type": "array", "items": {"type": "string"}},
"cache_to": {"type": "array", "items": {"type": "string"}},
"cache_from": {"$ref": "#/definitions/list_of_strings"},
"cache_to": {"$ref": "#/definitions/list_of_strings"},
"no_cache": {"type": ["boolean", "string"]},
"additional_contexts": {"$ref": "#/definitions/list_or_dict"},
"network": {"type": "string"},
Expand All @@ -119,9 +124,9 @@
"isolation": {"type": "string"},
"privileged": {"type": ["boolean", "string"]},
"secrets": {"$ref": "#/definitions/service_config_or_secret"},
"tags": {"type": "array", "items": {"type": "string"}},
"tags": {"$ref": "#/definitions/list_of_strings"},
"ulimits": {"$ref": "#/definitions/ulimits"},
"platforms": {"type": "array", "items": {"type": "string"}}
"platforms": {"$ref": "#/definitions/list_of_strings"}
},
"additionalProperties": false,
"patternProperties": {"^x-": {}}
Expand All @@ -132,31 +137,26 @@
"type": "object",
"properties": {
"device_read_bps": {
"type": "array",
"items": {"$ref": "#/definitions/blkio_limit"}
"$ref": "#/definitions/blkio_limit_list"
},
"device_read_iops": {
"type": "array",
"items": {"$ref": "#/definitions/blkio_limit"}
"$ref": "#/definitions/blkio_limit_list"
},
"device_write_bps": {
"type": "array",
"items": {"$ref": "#/definitions/blkio_limit"}
"$ref": "#/definitions/blkio_limit_list"
},
"device_write_iops": {
"type": "array",
"items": {"$ref": "#/definitions/blkio_limit"}
"$ref": "#/definitions/blkio_limit_list"
},
"weight": {"type": ["integer", "string"]},
"weight_device": {
"type": "array",
"items": {"$ref": "#/definitions/blkio_weight"}
"$ref": "#/definitions/blkio_weight_list"
}
},
"additionalProperties": false
},
"cap_add": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"cap_drop": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"cap_add": {"$ref": "#/definitions/list_of_unique_strings"},
"cap_drop": {"$ref": "#/definitions/list_of_unique_strings"},
"cgroup": {"type": "string", "enum": ["host", "private"]},
"cgroup_parent": {"type": "string"},
"command": {"$ref": "#/definitions/command"},
Expand Down Expand Up @@ -189,7 +189,7 @@
},
"depends_on": {
"oneOf": [
{"$ref": "#/definitions/list_of_strings"},
{"$ref": "#/definitions/list_of_unique_strings"},
{
"type": "object",
"additionalProperties": false,
Expand All @@ -215,10 +215,10 @@
}
]
},
"device_cgroup_rules": {"$ref": "#/definitions/list_of_strings"},
"devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"device_cgroup_rules": {"$ref": "#/definitions/list_of_unique_strings"},
"devices": {"$ref": "#/definitions/list_of_unique_strings"},
"dns": {"$ref": "#/definitions/string_or_list"},
"dns_opt": {"type": "array","items": {"type": "string"}, "uniqueItems": true},
"dns_opt": {"$ref": "#/definitions/list_of_unique_strings"},
"dns_search": {"$ref": "#/definitions/string_or_list"},
"domainname": {"type": "string"},
"entrypoint": {"$ref": "#/definitions/command"},
Expand Down Expand Up @@ -248,7 +248,7 @@
}
]
},
"external_links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"external_links": {"$ref": "#/definitions/list_of_unique_strings"},
"extra_hosts": {"$ref": "#/definitions/list_or_dict"},
"group_add": {
"type": "array",
Expand All @@ -264,7 +264,7 @@
"ipc": {"type": "string"},
"isolation": {"type": "string"},
"labels": {"$ref": "#/definitions/list_or_dict"},
"links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"links": {"$ref": "#/definitions/list_of_unique_strings"},
"logging": {
"type": "object",

Expand All @@ -288,7 +288,7 @@
"network_mode": {"type": "string"},
"networks": {
"oneOf": [
{"$ref": "#/definitions/list_of_strings"},
{"$ref": "#/definitions/list_of_unique_strings"},
{
"type": "object",
"patternProperties": {
Expand All @@ -297,10 +297,10 @@
{
"type": "object",
"properties": {
"aliases": {"$ref": "#/definitions/list_of_strings"},
"aliases": {"$ref": "#/definitions/list_of_unique_strings"},
"ipv4_address": {"type": "string"},
"ipv6_address": {"type": "string"},
"link_local_ips": {"$ref": "#/definitions/list_of_strings"},
"link_local_ips": {"$ref": "#/definitions/list_of_unique_strings"},
"mac_address": {"type": "string"},
"driver_opts": {
"type": "object",
Expand Down Expand Up @@ -354,7 +354,7 @@
"uniqueItems": true
},
"privileged": {"type": ["boolean", "string"]},
"profiles": {"$ref": "#/definitions/list_of_strings"},
"profiles": {"$ref": "#/definitions/list_of_unique_strings"},
"pull_policy": {"type": "string", "enum": [
"always", "never", "if_not_present", "build", "missing"
]},
Expand All @@ -366,7 +366,7 @@
"scale": {
"type": ["integer", "string"]
},
"security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"security_opt": {"$ref": "#/definitions/list_of_unique_strings"},
"shm_size": {"type": ["number", "string"]},
"secrets": {"$ref": "#/definitions/service_config_or_secret"},
"sysctls": {"$ref": "#/definitions/list_or_dict"},
Expand Down Expand Up @@ -436,9 +436,7 @@
"uniqueItems": true
},
"volumes_from": {
"type": "array",
"items": {"type": "string"},
"uniqueItems": true
"$ref": "#/definitions/list_of_unique_strings"
},
"working_dir": {"type": "string"}
},
Expand All @@ -456,7 +454,7 @@
"test": {
"oneOf": [
{"type": "string"},
{"type": "array", "items": {"type": "string"}}
{"$ref": "#/definitions/list_of_strings"}
]
},
"timeout": {"type": "string"},
Expand All @@ -476,7 +474,7 @@
"type": "object",
"required": ["path", "action"],
"properties": {
"ignore": {"type": "array", "items": {"type": "string"}},
"ignore": {"$ref": "#/definitions/list_of_strings"},
"path": {"type": "string"},
"action": {"type": "string", "enum": ["rebuild", "sync", "sync+restart"]},
"target": {"type": "string"}
Expand Down Expand Up @@ -569,7 +567,7 @@
"placement": {
"type": "object",
"properties": {
"constraints": {"type": "array", "items": {"type": "string"}},
"constraints": {"$ref": "#/definitions/list_of_strings"},
"preferences": {
"type": "array",
"items": {
Expand Down Expand Up @@ -618,9 +616,9 @@
"items": {
"type": "object",
"properties": {
"capabilities": {"$ref": "#/definitions/list_of_strings"},
"capabilities": {"$ref": "#/definitions/list_of_unique_strings"},
"count": {"type": ["string", "integer"]},
"device_ids": {"$ref": "#/definitions/list_of_strings"},
"device_ids": {"$ref": "#/definitions/list_of_unique_strings"},
"driver":{"type": "string"},
"options":{"$ref": "#/definitions/list_or_dict"}
},
Expand Down Expand Up @@ -792,12 +790,13 @@
"oneOf": [
{"type": "null"},
{"type": "string"},
{"type": "array","items": {"type": "string"}}
{"type": "array", "items": {"type": "string"}}
]
},

"env_file": {
"oneOf": [
{"type": "null"},
{"type": "string"},
{
"type": "array",
Expand Down Expand Up @@ -829,14 +828,29 @@
"string_or_list": {
"oneOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"}
{"$ref": "#/definitions/list_of_unique_strings"}
]
},

"list_of_unique_strings": {
"oneOf": [
{
"type": "array",
"items": {"type": "string"},
"uniqueItems": true
},
{"type": "null"}
]
},

"list_of_strings": {
"type": "array",
"items": {"type": "string"},
"uniqueItems": true
"oneOf": [
{
"type": "array",
"items": {"type": "string"}
},
{"type": "null"}
]
},

"list_or_dict": {
Expand All @@ -850,7 +864,7 @@
},
"additionalProperties": false
},
{"type": "array", "items": {"type": "string"}, "uniqueItems": true}
{"$ref": "#/definitions/list_of_unique_strings"}
]
},

Expand All @@ -862,6 +876,13 @@
},
"additionalProperties": false
},
"blkio_limit_list": {
"oneOf": [
{"type": "array", "items": {"$ref": "#/definitions/blkio_limit"}},
{"type": "null"}
]
},

"blkio_weight": {
"type": "object",
"properties": {
Expand All @@ -870,25 +891,37 @@
},
"additionalProperties": false
},
"blkio_weight_list": {
"oneOf": [
{"type": "array", "items": {"$ref": "#/definitions/blkio_weight"}},
{"type": "null"}
]
},

"service_config_or_secret": {
"type": "array",
"items": {
"oneOf": [
{"type": "string"},
{
"type": "object",
"properties": {
"source": {"type": "string"},
"target": {"type": "string"},
"uid": {"type": "string"},
"gid": {"type": "string"},
"mode": {"type": ["number", "string"]}
},
"additionalProperties": false,
"patternProperties": {"^x-": {}}
"oneOf": [
{"type": "null"},
{
"type": "array",
"items": {
"oneOf": [
{"type": "string"},
{
"type": "object",
"properties": {
"source": {"type": "string"},
"target": {"type": "string"},
"uid": {"type": "string"},
"gid": {"type": "string"},
"mode": {"type": ["number", "string"]}
},
"additionalProperties": false,
"patternProperties": {"^x-": {}}
}
]
}
]
}
}
]
},
"ulimits": {
"type": "object",
Expand Down