timoni icon indicating copy to clipboard operation
timoni copied to clipboard

[bug] The import function vendor crd not correctly converting fields that have constraints 'oneOf', 'not', and 'anyOf'

Open yyvess opened this issue 1 year ago • 2 comments

The import function vendor crd not correctly converting fields that have constraints 'oneOf', 'not', and 'anyOf'

Not sure if the bug is on Timoni or in Cue, perhaps around it https://github.com/cue-lang/cue/blob/64a117c07a084f82970596f3ac67023087952f4f/encoding/jsonschema/constraints.go#L288 ?

Command used timoni mod vendor crd -f https://raw.githubusercontent.com/istio/istio/1.20.2/manifests/charts/base/crds/crd-all.gen.yaml

As exemple the field method declared on the Istio crd to enforce that one and only one property exact, prefix or regex is defined as is

method: {
  oneOf: [{
    not: anyOf: [ { required: ["exact"]} , { required: ["prefix"]} , { required: ["regex"]}] },
    ,{required: ["exact"]}
    ,{required: ["prefix"]}
    ,{required: ["regex"]
  }]
  properties: {
	  exact: type: "string"
	  prefix: type: "string"
	  regex: { type: "string" }
  }
  type: "object"
}

The CUE output not corresponding and don't allow to set any property on method

method?: ({} | {
	exact: _
} | {
	prefix: _
} | {
	regex: _
}) & {
	exact?:  string
	prefix?: string
	regex?: string
}

yyvess avatar Feb 04 '24 22:02 yyvess

This is tracked upstream here https://github.com/cue-lang/cue/issues/2686 and https://github.com/cue-lang/cue/issues/3165

stefanprodan avatar Feb 05 '24 06:02 stefanprodan

@yyvess there was a fix in CUE that is meant to resolve this issue (https://github.com/cue-lang/cue/commit/bfce1505abf03b2800e5a7b48b592d4ef9a4075c), I opened https://github.com/stefanprodan/timoni/pull/424, it'd be great if you could test it with your use-case.

errordeveloper avatar Sep 10 '24 11:09 errordeveloper