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

Error importing gitlab json schema #1939

Closed
benmoss opened this issue Sep 16, 2022 · 3 comments
Closed

Error importing gitlab json schema #1939

benmoss opened this issue Sep 16, 2022 · 3 comments
Labels
NeedsInvestigation Triage Requires triage/attention

Comments

@benmoss
Copy link
Contributor

benmoss commented Sep 16, 2022

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

$ cue version
cue version v0.4.3 darwin/arm64

Does this issue reproduce with the latest release?

Yep

What did you do?

curl -JLO https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json
cue import -f -l "#CISpec:" -p gitlab ci.json

Permalink to latest commit: https://gitlab.com/gitlab-org/gitlab/-/blob/7cac80c74d52cce38faa8a0068305a370a417ebd/app/assets/javascripts/editor/schema/ci.json

What did you expect to see?

The schema converted to CUE

What did you see instead?

constraint not allowed because type string is excluded:
    ./ci.json:116:33
constraint not allowed because type string is excluded:
    ./ci.json:703:25

Lines 116 and 703 for reference

@benmoss benmoss added NeedsInvestigation Triage Requires triage/attention labels Sep 16, 2022
@myitcv
Copy link
Member

myitcv commented Oct 1, 2022

@benmoss thanks for your patience here.

Following these steps to commit 7cac80c74d52cce38faa8a0068305a370a417ebd you reference above, using cad3f23 (current tip):

exec curl -sJLO https://gitlab.com/gitlab-org/gitlab/-/raw/7cac80c74d52cce38faa8a0068305a370a417ebd/app/assets/javascripts/editor/schema/ci.json
exec cue import jsonschema: ci.json

I see:

> exec cue import jsonschema: ci.json
[stderr]
constraint not allowed because type string is excluded:
    ./ci.json:68:33
constraint not allowed because type string is excluded:
    ./ci.json:577:29
[exit status 1]
FAIL: /tmp/testscript1311223080/repro.txtar/script.txtar:2: unexpected command failure

Looking at the relevant bits from the schema:

        "rules": {
          "type": "array",
          "items": {
            "anyOf": [
              {"type": "object"},
              {"type": "array", "minLength": 1, "items": { "type": "string" }}
            ],
            "properties": {
              "if": { "$ref": "#/definitions/if" },
              "changes": { "$ref": "#/definitions/changes" },
              "exists": { "$ref": "#/definitions/exists" },
              "variables": { "$ref": "#/definitions/variables" },
              "when": {
                "type": "string",
                "enum": ["always", "never"]
              }
            },
            "additionalProperties": false
          }
        }

The slightly cryptic error message refers to this line:

{"type": "array", "minLength": 1, "items": { "type": "string" }}

minLength is only something that applies to strings, not arrays. minItems is what is needed here, unless minLength was a constraint intended for the items in the array in which case:

{"type": "array", "items": { "type": "string",  "minLength": 1 }}

might have been what was intended.

If we fix the schema in these two places to use minItems it imports as expected.

So I believe this is a bug in the source JSONSchema. But please let me know if this analysis doesn't correspond with your understanding.

@myitcv myitcv closed this as completed Oct 1, 2022
@myitcv
Copy link
Member

myitcv commented Apr 3, 2024

For anyone following along here, I just raised https://gitlab.com/gitlab-org/gitlab/-/merge_requests/148555 to fix the schema upstream.

@myitcv
Copy link
Member

myitcv commented Apr 15, 2024

And delighted to say that https://gitlab.com/gitlab-org/gitlab/-/merge_requests/148555 is now merged! cue import on the current tip of that schema now works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Triage Requires triage/attention
Projects
None yet
Development

No branches or pull requests

2 participants