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

Unable to define recursive definitions #3524

Open
roman-mazur opened this issue Oct 18, 2024 · 0 comments
Open

Unable to define recursive definitions #3524

roman-mazur opened this issue Oct 18, 2024 · 0 comments
Labels
NeedsInvestigation Triage Requires triage/attention

Comments

@roman-mazur
Copy link

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

$ cue version
cue version v0.11.0-alpha.3

go version go1.23.1
      -buildmode exe
       -compiler gc
  DefaultGODEBUG asynctimerchan=1,gotypesalias=0,httpservecontentkeepheaders=1,tls3des=1,tlskyber=0,x509keypairleaf=0,x509negativeserial=1
     CGO_ENABLED 1
          GOARCH amd64
            GOOS darwin
         GOAMD64 v1
cue.lang.version v0.11.0

Does this issue reproduce with the latest stable release?

yes

What did you do?

I'm trying to write a convertor from Terraform schema document to a JSON schema. Bellow is an extract from this convertor that does not seem to behave as it should when I have a mix of nested list and object definitions. If you try to remove the top-level list, it works.

testscript << EOF
exec cue def

-- x.cue --
package x

#jsonSchema & {
  #type: ["list",
    ["object", {foo: ["list", ["list", "string"]]}]
  ]
}

#jsonSchema: {
    #type: #primitive
    type: #type
} | {
    #type: ["list", _]

    _child: #type[1]
    type: "array"
    items: #jsonSchema & {#type: _child}
} | {
        #type: ["object", _]
        type: "object"
        additionalProperties: false
        _child: #type[1]
        properties: {
                for fName, fType in _child {
                        (fName): #jsonSchema & {#type: fType}
                }
        }
}

#primitive: "string" | "bool" | "number"
EOF

What did you expect to see?

{
	type: "array"
	items: {
		type:                 "object"
		additionalProperties: false
		properties: {
			foo: {
				type: "array"
				items: {
					type: "array"
					items: {
						type: "string"
					}
				}
			}
		}
	}
}

What did you see instead?

5 errors in empty disjunction:
#type: 3 errors in empty disjunction:
#type: conflicting values "bool" and ["list",["object",{foo:["list",["list","string"]]}]] (mismatched types string and list):
    -:1:1
    -:2:10
    -:28:24
#type: conflicting values "number" and ["list",["object",{foo:["list",["list","string"]]}]] (mismatched types string and list):
    -:1:1
    -:2:10
    -:28:33
#type: conflicting values "string" and ["list",["object",{foo:["list",["list","string"]]}]] (mismatched types string and list):
    -:1:1
    -:2:10
    -:28:13
#type.0: conflicting values "object" and "list":
    -:1:1
    -:2:11
    -:17:10
@roman-mazur roman-mazur added NeedsInvestigation Triage Requires triage/attention labels Oct 18, 2024
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

1 participant