-
Originally opened by @ying-jeanne in cuelang/cue#725 Hi, In the project I am working on, we want to remove the default value from the API response (if the value in the response is the same as the default for the field). Now the API is defined in CUE, is there any way to do it efficiently? Maybe some operation like XOR between the 2 cue files? For example rules.cue {
address: string | *"1.2.3.4"
port: int | *8888
protocol: "udp"|*"tcp"
custom: string
// foo: 2 // uncomment this to get an error
} input.json {
"address": "1.2.3.4",
"port": 8888,
"protocol": "udp",
"custom": "1234"
} output.json {
"protocol": "udp",
"custom": "1234"
} Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Original reply by @mpvl in cuelang/cue#725 (comment) This is something that It always good to do a diff of the result as a sanity check. There is also a semantic diff package, but that is as of yet internal. The plan is to expose that though at some point. |
Beta Was this translation helpful? Give feedback.
Original reply by @mpvl in cuelang/cue#725 (comment)
This is something that
cue trim
does. This is also available as a Go package in the repo undertools/trim
.It always good to do a diff of the result as a sanity check. There is also a semantic diff package, but that is as of yet internal. The plan is to expose that though at some point.