hofstadter-io / cuetorials.com

Learn you some CUE for a great good!
https://cuetorials.com
BSD 3-Clause "New" or "Revised" License
116 stars 34 forks source link

Compose spec import error #82

Open AndrewO opened 6 months ago

AndrewO commented 6 months ago

Following the Convert JSON Schema with the current compose schema (as of this commit), cue import raises the following error:

% cue import -f -p compose -l '#ComposeSpec:' compose-spec.json

constraint not allowed because type object is excluded:
    ./compose-spec.json:471:11

The offending JSON Schema section is below, specifically the "patternProperties": {"^x-": {}}.

    "development": {
      "id": "#/definitions/development",
      "type": ["object", "null"],
      "properties": {
        "watch": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["path", "action"],
            "properties": {
              "ignore": {"type": "array", "items": {"type": "string"}},
              "path": {"type": "string"},
              "action": {"type": "string", "enum": ["rebuild", "sync", "sync+restart"]},
              "target": {"type": "string"}
            }
          },
          "additionalProperties": false,
          "patternProperties": {"^x-": {}}
        }
      }

Removing that line (and the comma on the line above) worked around the issue. I'm not sure what a more correct fix would be.

verdverm commented 6 months ago

Hmm, this seems like an error in the schema.json file

  1. There are many similar fields that import fine
  2. If you move the tow fields up, to be inside the items object, it also works
    "development": {
      "id": "#/definitions/development",
      "type": ["object", "null"],
      "properties": {
        "watch": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["path", "action"],
            "properties": {
              "ignore": {"type": "array", "items": {"type": "string"}},
              "path": {"type": "string"},
              "action": {"type": "string", "enum": ["rebuild", "sync", "sync+restart"]},
              "target": {"type": "string"}
            },
            "additionalProperties": false,
            "patternProperties": {"^x-": {}}
          }
        }
      }
    },

Doing so matches another type on line 577

    "generic_resources": {
      "id": "#/definitions/generic_resources",
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "discrete_resource_spec": {
            "type": "object",
            "properties": {
              "kind": {"type": "string"},
              "value": {"type": "number"}
            },
            "additionalProperties": false,
            "patternProperties": {"^x-": {}}
          }
        },
        "additionalProperties": false,
        "patternProperties": {"^x-": {}}
      }
    },

So maybe this is a win for CUE?

I'd ask on the source repository, show them this issue, and see what they say.