Skip to content

encoding/openapi: handle default-wrapped numeric conjunctions#4331

Open
orvis98 wants to merge 1 commit into
cue-lang:masterfrom
orvis98:master
Open

encoding/openapi: handle default-wrapped numeric conjunctions#4331
orvis98 wants to merge 1 commit into
cue-lang:masterfrom
orvis98:master

Conversation

@orvis98
Copy link
Copy Markdown

@orvis98 orvis98 commented Apr 17, 2026

With ExpandReferences set, a numeric field that combines a bound conjunction with a default via disjunction, such as "int & >=1 | *1", would fail to generate an OpenAPI schema with "unsupported op for number &".

The value() dispatch pipeline relies on appendSplit to flatten a top-level conjunction into individual bound operands before handing each one to number(). When the value carries a default marker, cue.Value.Expr strips it and returns a NoOp wrapping the non-default arm. appendSplit's NoOp branch accepts that arm as a single conjunct without recursing, so a compound like "int & >=1" reaches number() with its AndOp intact and falls into the unsupported-op arm.

Handle AndOp in number() by recursing into each operand. The operands are simpler sub-expressions and hit the existing bound handlers, which merge minimum/maximum into the same schema node.

Fixes #4305.

With ExpandReferences set, a numeric field that combines a bound
conjunction with a default via disjunction, such as
"int & >=1 | *1", would fail to generate an OpenAPI schema with
"unsupported op for number &".

The value() dispatch pipeline relies on appendSplit to flatten a
top-level conjunction into individual bound operands before
handing each one to number(). When the value carries a default
marker, cue.Value.Expr strips it and returns a NoOp wrapping the
non-default arm. appendSplit's NoOp branch accepts that arm as a
single conjunct without recursing, so a compound like
"int & >=1" reaches number() with its AndOp intact and falls into
the unsupported-op arm.

Handle AndOp in number() by recursing into each operand. The
operands are simpler sub-expressions and hit the existing bound
handlers, which merge minimum/maximum into the same schema node.

Fixes cue-lang#4305.

Signed-off-by: John Enarsson <johnenarsson@hotmail.com>
@orvis98 orvis98 requested a review from cueckoo as a code owner April 17, 2026 17:23
orvis98 added a commit to open-platform-model/cli that referenced this pull request Apr 18, 2026
Converts a module's `#config` into a Kubernetes CRD via CUE's openapi
encoder + structural-schema post-processing, enabling native kubectl/GitOps
workflows alongside release files. Controller-side reconciliation is future
work.

- pkg/crd: name/version derivation, schema extraction, CRD assembly with
  provenance labels/annotations (OPM keys win over module keys).
- internal/cmd/module/crd.go: Cobra command with `--group` and `-o yaml|json`.
- tests/integration/module-crd: server-side dry-run apply against kind.

go.mod temporarily `replace`s cuelang.org/go with the `opm-cli` branch of
github.com/orvis98/cue to pick up cue-lang/cue#4331 (numeric bounds +
default); drop once upstream tags a release.

See openspec/changes/module-crd-poc/proposal.md for POC rules and deferred
work.

Signed-off-by: John Enarsson <johnenarsson@hotmail.com>
orvis98 added a commit to open-platform-model/cli that referenced this pull request Apr 18, 2026
Converts a module's `#config` into a Kubernetes CRD via CUE's openapi
encoder + structural-schema post-processing, enabling native kubectl/GitOps
workflows alongside release files. Controller-side reconciliation is future
work.

- pkg/crd: name/version derivation, schema extraction, CRD assembly with
  provenance labels/annotations (OPM keys win over module keys).
- internal/cmd/module/crd.go: Cobra command with `--group` and `-o yaml|json`.
- tests/integration/module-crd: server-side dry-run apply against kind.

go.mod temporarily `replace`s cuelang.org/go with the `opm-cli` branch of
github.com/orvis98/cue to pick up cue-lang/cue#4331 (numeric bounds +
default); drop once upstream tags a release.

See openspec/changes/module-crd-poc/proposal.md for POC rules and deferred
work.

Signed-off-by: John Enarsson <johnenarsson@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

encoding/openapi: "unsupported op for number &" with ExpandReferences and default+bounded int

1 participant