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

[FEATURE] Change array collections to key-value if order is not important #121

Open
chrishumanitec opened this issue Jan 9, 2025 · 0 comments
Assignees

Comments

@chrishumanitec
Copy link

Detailed description

Some fields fields: files and volumes in containers are arrays. Both of these have a required unique identifier: target which is the path to mount in the container.

Using arrays for this introduces the following complexities:

  • Additional validation is required to verify that no two files and no two volumes use the same path
  • The order is not actually important
  • Arrays are harder to visually parse in yaml compared to objects.

Context

In general, it would make sense for arrays to only be used where order is actually important or there is no unique key.

Possible implementation

The spec can be changed to use oneOf as follows:

{
  "files": {
    "description": "The extra files to mount into the container.",
    "oneOf": [
      {
        "type": "array",
        "items": {
          "type": "object",
          "required": [
            "target"
          ],
          "additionalProperties": false,
          "properties": {
            "target": {
              "description": "The file path to expose in the container.",
              "type": "string",
              "minLength": 1
            },
            "mode": {
              "description": "The optional file access mode in octal encoding. For example 0600.",
              "type": "string",
              "pattern": "^0?[0-7]{3}$"
            },
            "source": {
              "description": "The relative or absolute path to the content file.",
              "type": "string",
              "minLength": 1
            },
            "content": {
              "description": "The inline content for the file.",
              "type": "string"
            },
            "noExpand": {
              "description": "If set to true, the placeholders expansion will not occur in the contents of the file.",
              "type": "boolean"
            }
          },
          "oneOf": [
            {
              "required": [
                "target",
                "content"
              ]
            },
            {
              "required": [
                "target",
                "source"
              ]
            }
          ]
        }
      },
      {
        "type": "object",
        "patternProperties": {
          ".+": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "mode": {
                "description": "The optional file access mode in octal encoding. For example 0600.",
                "type": "string",
                "pattern": "^0?[0-7]{3}$"
              },
              "source": {
                "description": "The relative or absolute path to the content file.",
                "type": "string",
                "minLength": 1
              },
              "content": {
                "description": "The inline content for the file.",
                "type": "string"
              },
              "noExpand": {
                "description": "If set to true, the placeholders expansion will not occur in the contents of the file.",
                "type": "boolean"
              }
            }
          },
          "oneOf": [
            {
              "required": [
                "content"
              ]
            },
            {
              "required": [
                "source"
              ]
            }
          ]
        }
      }
    ]
  }
}

Additional information

score-go would need to support both but surface via the existing API. This would mean that implementations using score-go get this for free.

@chrishumanitec chrishumanitec self-assigned this Jan 9, 2025
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

No branches or pull requests

1 participant