Closed myitcv closed 3 years ago
Some thoughts
inline
tag is an interesting grey area case...cue.mod/usr
dirT1
and T2
share a field name and have the inline
tag? This would seem problematic... but what is the user intention here? Could it be to merge some schemas which have some overlap, or unmarshal the same field into multiple structs? I'll have to think on this more in the import vs marshal comparison...--out go
for structs (and/or) import/export for other languages?inline
, are there cases where a breakage occurs? Do we already have a test that might show this?This issue has been migrated to https://github.com/cue-lang/cue/issues/1026.
For more details about CUE's migration to a new home, please see https://github.com/cue-lang/cue/issues/1078.
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
https://github.com/cuelang/cue/issues/848 raises a question about whether the CUE generated by
cue get go
(which will becomecue import go
under #646) is in fact valid. #848 has been closed as "working as intended" but per https://github.com/cuelang/cue/issues/848#issuecomment-805006596 it does appear to raise a couple of issues/questions.The
cue help get go
text talks about the JSONinline
tag:However, this tag does not exist as part of
encoding/json
, it only exists as a proposal: https://github.com/golang/go/issues/6213. This tag does however exist as part ofgopkg.in/yaml.v1
and later major versions.My suggestion would therefore be that we drop this rule for the
inline
tag and instead, by default, adopt the semantics implied by JSON marshalling. Consider this example:https://gist.github.com/myitcv/fbf930c45892bbbc22cced812bfbe346
This demonstrates how:
encoding/json
marshals values of typesS1
andS2
identically, regardless of the presence of theinline
tagencoding/json
respects the embedding ofT1
andT2
in bothS1
andS2
, hence valuess1
ands2
marshal to the same value (seestdout.golden
)cue get go
does behave differently depending on theinline
tag: see how#S1
and#S2
differ inmain_go_gen.cue.golden
But this raises one further question. The
sigs.k8s.io
types referenced in #848 have lots of Yaml tags, which implies these values of these types are fairly regularly marshalled to/from Yaml. Given the proposed change in struct rules above, this might well imply a number of users would be discontent with the default:This seems to point to another requirement: that the caller of
cue get go
should be able to specify the "rules" applied during the conversion. By default,encoding/json
semantics would be applied, with further options available (perhaps in future we could define what it would mean for a Go package to implement and "interface"/API for such conversions?) behind a flag.cc @nyarly and @verdverm from #848