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

encoding/openapi: struct.MinFields not satisfied when generating from CUE #3605

Open
thorehusfeldt opened this issue Dec 2, 2024 · 1 comment

Comments

@thorehusfeldt
Copy link

thorehusfeldt commented Dec 2, 2024

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

$ cue version

cue version v0.11.0

go version go1.23.3
      -buildmode exe
       -compiler gc
       -trimpath true
  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?

It does.

What did you do?

I create

import "struct"

#foo: {
	[string]: string
} & struct.MinFields(1)

and run

> cue export *.cue --out openapi -d "#foo"

What did you expect to see?

{
    "openapi": "3.0.0",
    "info": {
        "title": "Generated by cue.",
        "version": "no version"
    },
    "paths": {},
    "components": {
        "schemas": {
            "foo": {
                "type": "object",
                "minProperties": 1,
                "additionalProperties": {
                    "type": "string"
                }
            }
        }
    }
}

In particular, the above does indeed happen for the more-or-less-symmetrical case with s/MinFields/MaxFields/ in the CUE schema and s/minProperties/maxProperties/ in the OpenAPI output.

What did you see instead?

#foo: openapi: #foo: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
    ./test.cue:5:5
@thorehusfeldt thorehusfeldt added NeedsInvestigation Triage Requires triage/attention labels Dec 2, 2024
@thorehusfeldt thorehusfeldt changed the title struct.MinFields and OpenApi schema export struct.MinFields and OpenAPI schema export Dec 2, 2024
@myitcv myitcv changed the title struct.MinFields and OpenAPI schema export encoding/openapi: struct.MinFields not satisfied when generating from CUE Dec 6, 2024
@myitcv
Copy link
Member

myitcv commented Dec 8, 2024

Confirmed as of f99441a

exec cue export --out openapi -o - -d '#foo' x.cue

-- x.cue --
import "struct"

#foo: {
	[string]: string
} & struct.MinFields(1)
-- stdout.golden --
{
    "openapi": "3.0.0",
    "info": {
        "title": "Generated by cue.",
        "version": "no version"
    },
    "paths": {},
    "components": {
        "schemas": {
            "foo": {
                "type": "object",
                "minProperties": 1,
                "additionalProperties": {
                    "type": "string"
                }
            }
        }
    }
}

For some variation of stdout.golden, because CUE's interpretation of additionalProperties is not correct in all situations.

@myitcv myitcv added jsonschema / openapi encoding and removed Triage Requires triage/attention labels Dec 8, 2024
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

2 participants