cue icon indicating copy to clipboard operation
cue copied to clipboard

encoding/openapi: additionalProperties is not specified where it should be

Open myitcv opened this issue 10 months ago • 1 comments

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

$ cue version
cue version v0.0.0-20250131154328-0a43336cccf3

go version go1.23.5
      -buildmode exe
       -compiler gc
  DefaultGODEBUG asynctimerchan=1,gotypesalias=0,httpservecontentkeepheaders=1,tls3des=1,tlskyber=0,x509keypairleaf=0,x509negativeserial=1
     CGO_ENABLED 1
          GOARCH arm64
            GOOS linux
         GOARM64 v8.0
             vcs git
    vcs.revision 0a43336cccf3b6fc632e976912d74fb2c9670557
        vcs.time 2025-01-31T15:43:28Z
    vcs.modified false
cue.lang.version v0.13.0

Does this issue reproduce with the latest release?

Yes

What did you do?

# -- evalv3 --
env CUE_EXPERIMENT=evalv3=1

# cmd/cue
exec cue export --out=openapi
cmp stdout stdout.golden

-- types.cue --
package openapi

#Tags: {
    owner: string | *"sre"
    role: string | *"control-plane"
    ...
}

#Spec: {
    name: string
    tags?: #Tags | *#Tags
}

-- stdout.golden --
{
    "openapi": "3.0.0",
    "info": {
        "title": "Generated by cue.",
        "version": "no version"
    },
    "paths": {},
    "components": {
        "schemas": {
            "Spec": {
                "type": "object",
                "required": [
                    "name"
                ],
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "tags": {
                        "$ref": "#/components/schemas/Tags"
                    }
                },
		"additionalProperties": false
            },
            "Tags": {
                "type": "object",
                "required": [
                    "owner",
                    "role"
                ],
                "properties": {
                    "owner": {
                        "type": "string",
                        "default": "sre"
                    },
                    "role": {
                        "type": "string",
                        "default": "control-plane"
                    }
                },
		"additionalProperties": {}
            }
        }
    }
}

What did you expect to see?

Passing test.

What did you see instead?

# -- evalv3 -- (0.000s)
# cmd/cue (0.044s)
> exec cue export --out=openapi
[stdout]
{
    "openapi": "3.0.0",
    "info": {
        "title": "Generated by cue.",
        "version": "no version"
    },
    "paths": {},
    "components": {
        "schemas": {
            "Spec": {
                "type": "object",
                "required": [
                    "name"
                ],
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "tags": {
                        "$ref": "#/components/schemas/Tags"
                    }
                }
            },
            "Tags": {
                "type": "object",
                "required": [
                    "owner",
                    "role"
                ],
                "properties": {
                    "owner": {
                        "type": "string",
                        "default": "sre"
                    },
                    "role": {
                        "type": "string",
                        "default": "control-plane"
                    }
                }
            }
        }
    }
}
> cmp stdout stdout.golden
diff stdout stdout.golden
--- stdout
+++ stdout.golden
@@ -19,7 +19,8 @@
                     "tags": {
                         "$ref": "#/components/schemas/Tags"
                     }
-                }
+                },
+               "additionalProperties": false
             },
             "Tags": {
                 "type": "object",
@@ -36,7 +37,8 @@
                         "type": "string",
                         "default": "control-plane"
                     }
-                }
+                },
+               "additionalProperties": {}
             }
         }
     }

FAIL: /tmp/testscript3456258337/repro.txtar/script.txtar:6: stdout and stdout.golden differ

Noting that using evalv2 with this example we run into an instance of https://github.com/cue-lang/cue/issues/2723:

# -- evalv3 -- (0.000s)
# cmd/cue (0.014s)
> exec cue export --out=openapi
[stderr]
#Spec.tags?: unsupported op . for object type ({
        owner: *"sre" | string
        role:  *"control-plane" | string
}):
    ./types.cue:11:12
[exit status 1]
FAIL: /tmp/testscript1173077964/repro.txtar/script.txtar:5: unexpected command failure

But to flag that https://github.com/cue-lang/cue/issues/2723 highlights that the problem in that issue does actually apply to both evalv2 and evalv3.

myitcv avatar Feb 03 '25 07:02 myitcv

I assume this is a duplicate of https://github.com/cue-lang/cue/issues/267, so I've closed that one as such. Please flag if I got that wrong.

mvdan avatar May 30 '25 17:05 mvdan