Skip to content

JsonSchema export doesn't evaluate hex.Encode or uuid.Parse #4450

Description

@ymelois

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

$ cue version
cue version (devel)

CUE language version v0.17.1

Go version go1.26.4
      -buildmode exe
       -compiler gc
       -trimpath true
  DefaultGODEBUG cryptocustomrand=1,tlssecpmlkem=0,urlstrictcolons=0
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v1

Does this issue reproduce with the latest stable release?

As of date filing this issue, yes.

What did you do?

While trying to write a UUID definition and making CUE export explicit constraints over jsonschema I found the following case which I did not expect, using testscript:

exec cue export in.cue --out json
exec cue export in.cue --out jsonschema

-- in.cue --
import (
	"uuid"
	"encoding/hex"
)

a: '\x18\xb3\x1b\x66\x0a\x87\x44\x3d\x8d\xa2\xeb\x89\x3e\x04\xdc\x4b'
b: hex.Encode(a)
c: uuid.Parse(b)
> exec cue export in.cue --out json
[stdout]
{
    "a": "GLMbZgqHRD2NouuJPgTcSw==",
    "b": "18b31b660a87443d8da2eb893e04dc4b",
    "c": "18b31b66-0a87-443d-8da2-eb893e04dc4b"
}
> exec cue export in.cue --out jsonschema
[stdout]
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
        "a": {
            "const": "GLMbZgqHRD2NouuJPgTcSw=="
        },
        "b": true,
        "c": true
    }
}

While simpler evaluations work like additions.

What did you expect to see?

jsonschema export output should have evaluated b and c like json export's output.

I expected to see the following output or similar:

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
        "a": {
            "const": "GLMbZgqHRD2NouuJPgTcSw=="
        },
        "b": {
            "const": "18b31b660a87443d8da2eb893e04dc4b"
        },
        "c": {
            "const": "18b31b66-0a87-443d-8da2-eb893e04dc4b"
        },
    }
}

What did you see instead?

jsonschema export output b and c fields don't get evaluated and instead show true as value like the following:

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
        "a": {
            "const": "GLMbZgqHRD2NouuJPgTcSw=="
        },
        "b": true,
        "c": true
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions