compose-spec / compose-spec

The Compose specification

Home Page:https://compose-spec.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spec does not allow an array of anchors (but should)

bmerigan opened this issue · comments

commented

What is the problem you're trying to solve
Reusable sections of code fragments and extensions are defined in the spec, but the spec does not actually allow the use of 2 or more fragments in the same service definition.
This closed Docker issue, confirms it should be of the form <<: [*first, *second] as already shown in the extensions doco examples.
compose-spec.json does not list array as an allowed child of the environment object (line 828)

    "list_or_dict": {
      "oneOf": [
        {
          "type": "object",
          "patternProperties": {
            ".+": {
              "type": ["string", "number", "boolean", "null"]
            }
          },
          "additionalProperties": false
        },
        {"type": "array", "items": {"type": "string"}, "uniqueItems": true}
      ]
    },

Describe the solution you'd like
The spec needs to accept the syntax: <<: [*first, *second, *third, ...] as shown in extensions doco
Edit compose-spec.json line 828 to: "type": ["array", "string", "number", "boolean", "null"]

Additional context
My IDE currently highlights these lines as invalid even though they are, and my investigation has led me to this repo being the source of truth.
image

yaml anchors is a pure yaml syntax feature, this is not modeled by compose-spec.json
This sounds like a bug/limitation in your IDE with yaml edition

commented

I need you to explain that further if you could. Are you saying a docker-compose.yaml file should NOT reference compose-spec.json?

docker-compose.yaml SHOULD refer to compose-spec.json, but this json schema defines the data tree t validate, while yaml syntax allows more, including use of anchors. It seems your IDE does not manage yaml anchors, while this is well defined by the yaml language spec (https://ktomk.github.io/writing/yaml-anchor-alias-and-merge-key.html)

Which IDE is this ?

yaml with anchors -> yaml parsing -> yaml node tree -> json schema validation

commented

This is in Jetbrains PHPStorm.
Thanks for the explanation

Weird... I'm using Golang which has very good support for compose file edition, and I don't have such an issue

I guess the error is that you use anchors to a declaration that is set later in your compose.yaml file, should be declared before any reference . The json validation pop-up is confusing here but unrelated to the actual error reported on merge keys

commented

I have them declared at the start of the file, then used in multiple places throughout the file. Won't be related to that.

example:

version: '3.7'

x-composer: &composer
  COMPOSER_FOO: fff
  COMPOSER_BAR: ggg

x-feature-flag: &feature-flag
  FF_QUX: hhh

x-apm: &apm
  APM_BAZ: ppp

services:
  my-service-name:
  ...
    environment:
      FOO: xxx
      <<: [*composer, *feature-flag, *apm]
      BAR: yyy

remove version: '3.7' from your compose file. This is obsolete, and (while there's no reason for this) this seems to change the way Jetbrains IDE parse and validate the compose file