compose-spec / compose-go

Reference library for parsing and loading Compose YAML files
https://compose-spec.io
Apache License 2.0
350 stars 109 forks source link

Allow empty (null) lists #670

Open lionello opened 1 month ago

lionello commented 1 month ago

This happens when some users are not very familiar with the Compose file syntax: during testing they'd comment out the environment variables, but not the actual environment: key, and the Compose file would fail to load:

services:
  service1:
    build: .
    environment:
      #NODE_ENV: production

This change adds "null" as a valid type for many of the lists in the JSON schema:

lionello commented 1 month ago

If this is the right approach I can add "oneOf": [{"type": "null"}, {"type": "array": …}] to the remaining ones.

jhrotko commented 1 month ago

they should get a warning from the IDE (if an extension is installed) or they get an error when running up for instance. The current behaviour is expected if environment or any other compose key is empty.

lionello commented 1 month ago

they should get a warning from the IDE (if an extension is installed) or they get an error when running up for instance. The current behaviour is expected if environment or any other compose key is empty.

That's right, you do get an error when you do up, but IMHO handling null is a better dev experience. Because arrays can be nil (and a nil array has length 0), the code already handles this.

ndeloof commented 1 month ago

I agree there's no reason we consider an null list as invalid while an empty one if fine