cue icon indicating copy to clipboard operation
cue copied to clipboard

Errors when importing Dependabot and Goreleaser JSON schemas

Open staticaland opened this issue 3 years ago • 1 comments

What version of CUE are you using (cue version)?

$ cue version
0.4.3

Does this issue reproduce with the latest release?

Yes.

What did you do?

Tried importing Dependabot schema from JSON Schema Store and getting this error:

cue import -l '#Dependabot' -p dependabot jsonschema: dependabot-2.0.json

constraint not allowed because type number is excluded:
    ./dependabot-2.0.json:113:11
constraint not allowed because type number is excluded:
    ./dependabot-2.0.json:210:11

I also tried the Goreleaser schema:

cue import goreleaser-schema.json

schema expects mapping node, found bool:
    ./goreleaser-schema.json:2102:6
schema expects mapping node, found bool:
    ./goreleaser-schema.json:2112:6

Sounds like the schema is flawed or more lenient, and CUE doesn’t like that. Is that a common thing with JSON schemas?

staticaland avatar Aug 25 '22 11:08 staticaland

I also tried https://ecs-intellisense.s3-us-west-2.amazonaws.com/task-definition/schema.json for AWS Elastic Container Service task definitions and got a similar error. I tried using it as a schema in VS Code and it works fine. This is my VS Code config, for reference:

{
    "json.schemas": [
        {
            "fileMatch": [
                "*ecs-task-def.json",
                "task-definition.json"
            ],
            "url": "https://ecs-intellisense.s3-us-west-2.amazonaws.com/task-definition/schema.json"
        }
    ]
}

staticaland avatar Sep 07 '22 18:09 staticaland

@staticaland - apologies, this issue slipped through the next. Thank you for your patience!

Looking at https://github.com/SchemaStore/schemastore/tree/597cc2264375dc0b43b546ed3c6e13a5f2ed3ae8.

Using:

$ cue version
cue version v0.0.0-20221001181137-79d80efc2882

       -compiler gc
     CGO_ENABLED 1
          GOARCH arm64
            GOOS linux
             vcs git
    vcs.revision 79d80efc288208410f77d47ae9aedd37e106d84b
        vcs.time 2022-10-01T18:11:37Z
    vcs.modified false

src/schemas/json/dependabot.json

$ cue import src/schemas/json/dependabot.json
constraint not allowed because type array is excluded:
    ./src/schemas/json/dependabot.json:55:13
constraint not allowed because type array is excluded:
    ./src/schemas/json/dependabot.json:96:15
constraint not allowed because type array is excluded:
    ./src/schemas/json/dependabot.json:134:15
constraint not allowed because type array is excluded:
    ./src/schemas/json/dependabot.json:159:15

These all appear to be because of errors in the source JSON Schema. Having looked briefly at each, the errors look valid, i.e. CUE is correct that the source JSON Schema is invalid.

The first error occurs in:

          "target_branch": {
            "type": "string",
            "description": "Branch to create pull requests against. By default your repository's default branch is used.",
            "items": {
              "type": "string",
              "description": "branchname",
              "examples": ["develop"]
            }
          },

The use of items is not valid here, because the type is declared as string. The error message could be better, but it is telling you that items cannot be used because array is not a possible type for this field.

All the other errors relate to the use of minItems for a field of type object. That is also not valid AFAIU.

src/schemas/json/dependabot-2.0.json

$ cue import src/schemas/json/dependabot-2.0.json
constraint not allowed because type number is excluded:
    ./src/schemas/json/dependabot-2.0.json:114:11
constraint not allowed because type number is excluded:
    ./src/schemas/json/dependabot-2.0.json:211:11

Both of these errors relate to the use of minimum on a field of type array, when this constraint can only be applied to number. I suspect this was intended to be minItems?

As such I don't think there are any CUE-related errors here, so I will close this issue. But please reply and we can re-open if that conclusion is invalid!

myitcv avatar Oct 04 '22 11:10 myitcv