compose-go icon indicating copy to clipboard operation
compose-go copied to clipboard

Allow empty (null) lists

Open lionello opened this issue 1 year ago • 4 comments

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:

  • [x] include
  • [x] service.blkio_config.device_read_bps
  • [x] service.blkio_config.device_read_iops
  • [x] service.blkio_config.device_write_bps
  • [x] service.blkio_config.device_write_iops
  • [x] service.blkio_config.weight_device
  • [ ] service.expose
  • [ ] service.group_add
  • [ ] service.ports
  • [ ] service.volumes
  • [ ] development.watch
  • [ ] deployment.placement.preferences
  • [ ] generic_resources
  • [ ] devices
  • [ ] network.ipam.config
  • [x] command
  • [x] env_file
  • [x] list_of_unique_strings (was: list_of_strings)
  • [x] list_of_strings
  • [x] list_or_dict
  • [x] service_config_or_secret

lionello avatar Jul 31 '24 01:07 lionello

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

lionello avatar Jul 31 '24 16:07 lionello

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.

jhrotko avatar Aug 01 '24 10:08 jhrotko

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.

lionello avatar Aug 02 '24 17:08 lionello

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

ndeloof avatar Aug 02 '24 20:08 ndeloof