Skip to content

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

@berimbolo13

Description

@berimbolo13

Summary

openapi.Gen with ExpandReferences: true fails with unsupported op for number & when a definition contains a default value combined with a bounded integer conjunction.

Minimal reproduction

ctx := cuecontext.New()
v := ctx.CompileString(`#X: *20 | int & >=1 & <=100`)
_, err := openapi.Gen(v, &openapi.Generator{ExpandReferences: true})
// err: unsupported op for number &

What works vs what doesn't

Expression ExpandReferences Result
#X: *20 | int & >=1 & <=100 false OK
#X: *20 | int & >=1 & <=100 true FAILS
#X: *20 | int true OK
#X: int & >=1 & <=100 true OK
#X: *20 | >=1 true OK
#X: null | *20 | >=1 & <=100 true OK

The combination of a default value (*20), a disjunction (|), and a conjunction of type+bounds (int & >=1 & <=100) is required to trigger the bug.

Where it fails

The error is produced at the default branch of the number() function:

case cue.NoOp:
// TODO: extract format from specific type.
default:
b.failf(v, "unsupported op for number %v", op)
}
}

number() handles individual constraint ops (>=, <=, <, >, !=, CallOp, NoOp) but has no case for AndOp. Normally conjunctions are decomposed before reaching number(), but with ExpandReferences: true the value arrives unsplit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions