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

cmd/cue: import on a valid JSONSchema file fails #2654

Closed
jpluscplusm opened this issue Oct 23, 2023 · 3 comments
Closed

cmd/cue: import on a valid JSONSchema file fails #2654

jpluscplusm opened this issue Oct 23, 2023 · 3 comments

Comments

@jpluscplusm
Copy link
Collaborator

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

$ cue version
cue version v0.6.0

go version go1.20.6
      -buildmode exe
       -compiler gc
       -trimpath true
     CGO_ENABLED 0
          GOARCH amd64
            GOOS linux
         GOAMD64 v1

Does this issue reproduce with the latest stable release?

Yes, 0.6.0.

What did you do?

I attempted to import the (current) tip-of-main (JSON)schema for GitLab CI/CD pipelines:

exec wget -q https://gitlab.com/gitlab-org/gitlab/-/raw/2e31bcdbead44ef80052f6c3db5dd98f465ba241/app/assets/javascripts/editor/schema/ci.json
exec cue import jsonschema: ci.json

What did you expect to see?

I expected cue to succeed, emitting a CUE version of the schema.

What did you see instead?

> exec wget -q https://gitlab.com/gitlab-org/gitlab/-/raw/2e31bcdbead44ef80052f6c3db5dd98f465ba241/app/assets/javascripts/editor/schema/ci.json
> exec cue import jsonschema: ci.json
[stderr]
constraint not allowed because type string is excluded:
    ./ci.json:126:17
constraint not allowed because type string is excluded:
    ./ci.json:546:11
constraint not allowed because type string is excluded:
    ./ci.json:852:13
constraint not allowed because type string is excluded:
    ./ci.json:904:13
schema expects mapping node, found bool:
    ./ci.json:959:9
schema expects mapping node, found bool:
    ./ci.json:989:9
schema expects mapping node, found bool:
    ./ci.json:1002:9
constraint not allowed because type string is excluded:
    ./ci.json:1550:15
constraint not allowed because type string is excluded:
    ./ci.json:2130:7
constraint not allowed because type string is excluded:
    ./ci.json:2140:13
[exit status 1]
FAIL: /tmp/testscript2818960354/gitlab-schema.txtar/script.txtar:2: unexpected command failure
error running gitlab-schema.txtar in /tmp/testscript2818960354/gitlab-schema.txtar

Using https://www.jsonschemavalidator.net/, I was able to successfully validate the GitLab file against the appropriate JSONSchema meta-schema, suggesting that cue's objections aren't fundamental to the file's contents.

An earlier version of the same GitLab schema was flagged in an seemingly unrelated issue, here: #1487

@jpluscplusm jpluscplusm added NeedsInvestigation Triage Requires triage/attention labels Oct 23, 2023
@myitcv myitcv changed the title cmd/cue: cue importing a valid JSONSchema file fails cmd/cue: import on a valid JSONSchema file fails Oct 23, 2023
jpluscplusm added a commit to jpluscplusm-forks/cue-lang.cue-by-example that referenced this issue Oct 24, 2023
This change adds a new piece of content which shows how to manage a
GitLab repo's CI/CD pipeline file in CUE, instead of YAML.

Because GitLab still needs to see a YAML file serialised in the repo,
the guide includes a CUE _tool that turns the CUE back into YAML on
demand.

It also includes a schema for the pipeline's representation, but this
schema is pretty lightweight and could do with improving. Part of the
problem is that I had to manually write the schema, as GitLab's
JSONSchema schema currently confuses `cue import`. I opened
cue-lang/cue#2654 to track this.

Closes cue-labs#19
jpluscplusm added a commit to jpluscplusm-forks/cue-lang.cue-by-example that referenced this issue Oct 24, 2023
This change adds a new piece of content which shows how to manage a
GitLab repo's CI/CD pipeline file in CUE, instead of YAML.

Because GitLab still needs to see a YAML file serialised in the repo,
the guide includes a CUE _tool that turns the CUE back into YAML on
demand.

It also includes a schema for the pipeline's representation, but this
schema is pretty lightweight and could do with improving. Part of the
problem is that I had to manually write the schema, as GitLab's
JSONSchema schema currently confuses `cue import`. I opened
cue-lang/cue#2654 to track this.

Closes cue-labs#19
jpluscplusm added a commit to jpluscplusm-forks/cue-lang.cue-by-example that referenced this issue Oct 24, 2023
This change adds a new piece of content which shows how to manage a
GitLab repo's CI/CD pipeline file in CUE, instead of YAML.

Because GitLab still needs to see a YAML file serialised in the repo,
the guide includes a CUE _tool that turns the CUE back into YAML on
demand.

It also includes a schema for the pipeline's representation, but this
schema is pretty lightweight and could do with improving. Part of the
problem is that I had to manually write the schema, as GitLab's
JSONSchema schema currently confuses `cue import`. I opened
cue-lang/cue#2654 to track this.

Closes cue-labs#19
jpluscplusm added a commit to jpluscplusm-forks/cue-lang.cue-by-example that referenced this issue Oct 24, 2023
This change adds a new piece of content which shows how to manage a
GitLab repo's CI/CD pipeline file in CUE, instead of YAML.

Because GitLab still needs to see a YAML file serialised in the repo,
the guide includes a CUE _tool that turns the CUE back into YAML on
demand.

It also includes a schema for the pipeline's representation, but this
schema is pretty lightweight and could do with improving. Part of the
problem is that I had to manually write the schema, as GitLab's
JSONSchema schema currently confuses `cue import`. I opened
cue-lang/cue#2654 to track this.

Closes cue-labs#19
myitcv pushed a commit to cue-labs/cue-by-example that referenced this issue Oct 24, 2023
This change adds a new piece of content which shows how to manage a
GitLab repo's CI/CD pipeline file in CUE, instead of YAML.

Because GitLab still needs to see a YAML file serialised in the repo,
the guide includes a CUE _tool that turns the CUE back into YAML on
demand.

It also includes a schema for the pipeline's representation, but this
schema is pretty lightweight and could do with improving. Part of the
problem is that I had to manually write the schema, as GitLab's
JSONSchema schema currently confuses `cue import`. I opened
cue-lang/cue#2654 to track this.

Closes #19
@justenstall
Copy link

justenstall commented Jan 19, 2024

Ran into the same blocker trying to import the JSON Schema for Renovate configuration.

$ curl https://docs.renovatebot.com/renovate-schema.json > renovate-schema.json
$ cue import jsonschema renovate-schema.json --verbose --trace -E
constraint not allowed because type array is excluded:
    ./renovate-schema.json:648:7
constraint not allowed because type array is excluded:
    ./renovate-schema.json:2497:7
$ cue version
cue version v0.7.0

go version go1.21.5
      -buildmode exe
       -compiler gc
       -trimpath true
  DefaultGODEBUG panicnil=1
     CGO_ENABLED 1
          GOARCH arm64
            GOOS darwin

For some context, here are the items at lines 648 and 2497:

Line 648 is properties.customDatasources.items:

{
  "properties": {
    "customDatasources": {
      "items": {
        "allOf": [
          {
            "type": "object",
            "properties": {
              "description": {
                "type": "string",
                "description": "A custom description for this configuration object"
              },
              "defaultRegistryUrlTemplate": {
                "description": "Template for generating a `defaultRegistryUrl` for custom datasource.",
                "type": "string",
                "default": ""
              },
              "format": {
                "description": "Format of the custom datasource.",
                "type": "string",
                "enum": [
                  "json",
                  "plain"
                ],
                "default": "json"
              },
              "transformTemplates": {
                "description": "List of jsonata transformation rules.",
                "type": "array",
                "items": {
                  "type": "string"
                },
                "default": []
              }
            }
          }
        ]
      }
    }
  }
}   

Line 2497 is properties.postUpgradeTasks.items:

{
  "properties": {
    "postUpgradeTasks": {
      "items": {
        "allOf": [
          {
            "type": "object",
            "properties": {
              "description": {
                "type": "string",
                "description": "A custom description for this configuration object"
              },
              "commands": {
                "description": "A list of post-upgrade commands that are executed before a commit is made by Renovate.",
                "type": "array",
                "items": {
                  "type": "string"
                },
                "default": []
              },
              "executionMode": {
                "description": "Controls when the post upgrade tasks run: on every update, or once per upgrade branch.",
                "type": "string",
                "enum": [
                  "update",
                  "branch"
                ],
                "default": "update"
              },
              "fileFilters": {
                "description": "Files that match the glob pattern will be committed after running a post-upgrade task.",
                "type": "array",
                "items": {
                  "type": "string"
                },
                "default": [
                  "**/*"
                ]
              }
            }
          }
        ]
     }
  }
}

vpayno added a commit to vpayno/github-gitlab-with-cuelang that referenced this issue Mar 8, 2024
GitLab's CI Schema can't be used: cue-lang/cue#2654

```text
$ cue import --verbose --force --path '#GitLabCi:' --package gitlab jsonschema: ./gitlab-ci.json
constraint not allowed because type string is excluded:
    ./gitlab-ci.json:145:17
constraint not allowed because type string is excluded:
    ./gitlab-ci.json:951:13
constraint not allowed because type string is excluded:
    ./gitlab-ci.json:1003:13
schema expects mapping node, found bool:
    ./gitlab-ci.json:1084:9
schema expects mapping node, found bool:
    ./gitlab-ci.json:1115:9
schema expects mapping node, found bool:
    ./gitlab-ci.json:1129:9
constraint not allowed because type string is excluded:
    ./gitlab-ci.json:1698:15
constraint not allowed because type string is excluded:
    ./gitlab-ci.json:2287:7
constraint not allowed because type string is excluded:
    ./gitlab-ci.json:2297:13
exit code: 1
```
@kharf
Copy link
Contributor

kharf commented Mar 9, 2024

Ran into the same blocker trying to import the JSON Schema for Renovate configuration.

$ curl https://docs.renovatebot.com/renovate-schema.json > renovate-schema.json
$ cue import jsonschema renovate-schema.json --verbose --trace -E
constraint not allowed because type array is excluded:
    ./renovate-schema.json:648:7
constraint not allowed because type array is excluded:
    ./renovate-schema.json:2497:7
$ cue version
cue version v0.7.0

go version go1.21.5
      -buildmode exe
       -compiler gc
       -trimpath true
  DefaultGODEBUG panicnil=1
     CGO_ENABLED 1
          GOARCH arm64
            GOOS darwin

For some context, here are the items at lines 648 and 2497:

Line 648 is properties.customDatasources.items:

{
  "properties": {
    "customDatasources": {
      "items": {
        "allOf": [
          {
            "type": "object",
            "properties": {
              "description": {
                "type": "string",
                "description": "A custom description for this configuration object"
              },
              "defaultRegistryUrlTemplate": {
                "description": "Template for generating a `defaultRegistryUrl` for custom datasource.",
                "type": "string",
                "default": ""
              },
              "format": {
                "description": "Format of the custom datasource.",
                "type": "string",
                "enum": [
                  "json",
                  "plain"
                ],
                "default": "json"
              },
              "transformTemplates": {
                "description": "List of jsonata transformation rules.",
                "type": "array",
                "items": {
                  "type": "string"
                },
                "default": []
              }
            }
          }
        ]
      }
    }
  }
}   

Line 2497 is properties.postUpgradeTasks.items:

{
  "properties": {
    "postUpgradeTasks": {
      "items": {
        "allOf": [
          {
            "type": "object",
            "properties": {
              "description": {
                "type": "string",
                "description": "A custom description for this configuration object"
              },
              "commands": {
                "description": "A list of post-upgrade commands that are executed before a commit is made by Renovate.",
                "type": "array",
                "items": {
                  "type": "string"
                },
                "default": []
              },
              "executionMode": {
                "description": "Controls when the post upgrade tasks run: on every update, or once per upgrade branch.",
                "type": "string",
                "enum": [
                  "update",
                  "branch"
                ],
                "default": "update"
              },
              "fileFilters": {
                "description": "Files that match the glob pattern will be committed after running a post-upgrade task.",
                "type": "array",
                "items": {
                  "type": "string"
                },
                "default": [
                  "**/*"
                ]
              }
            }
          }
        ]
     }
  }
}

It is due to "customDatasources" and "postUpgradeTasks" being declared as objects, but they are both arrays. In my opinion the errors are correct in this case.

@jpluscplusm
Copy link
Collaborator Author

Closing, as either the fix outlined in #1939 (https://gitlab.com/gitlab-org/gitlab/-/merge_requests/148555), or some preceding change to GitLab's schema, now permits GitLab's tip-of-master JSON Schema (https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json) to be successfully imported by cue v0.8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants