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

Conversation

lionello
Copy link
Contributor

@lionello lionello commented Jul 31, 2024

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:

  • include
  • service.blkio_config.device_read_bps
  • service.blkio_config.device_read_iops
  • service.blkio_config.device_write_bps
  • service.blkio_config.device_write_iops
  • 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
  • command
  • env_file
  • list_of_unique_strings (was: list_of_strings)
  • list_of_strings
  • list_or_dict
  • service_config_or_secret

@lionello lionello requested a review from ndeloof as a code owner July 31, 2024 01:25
Signed-off-by: Lionello Lunesu <[email protected]>
@lionello lionello changed the title Allow empty lists Allow empty (null) lists Jul 31, 2024
@lionello
Copy link
Contributor Author

lionello commented Jul 31, 2024

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

@@ -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.

@jhrotko
Copy link
Collaborator

jhrotko commented Aug 1, 2024

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
Copy link
Contributor Author

lionello commented Aug 2, 2024

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
Copy link
Collaborator

ndeloof commented Aug 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants