this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/encoding/gotypes: generate valid json tags for quoted fields

This change updates the behavior of the generator to unquote field names
when they are strings, as they may be quoted, resulting in the json tag
being double quoted:

type Example struct {
FooBar string `json:""foo-bar""`
}

Fixes #3882.

Closes #3883 as merged as of commit ad5e0b0d.

Signed-off-by: Travis Truman <trumant@gmail.com>
Change-Id: I74f3cc0a2d70944b6d50e5ad60cfa4cf67f4cf54
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1213127
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>

authored by

Travis Truman and committed by
Daniel Martí
93c1421c e0580148

+8 -2
+5 -2
cmd/cue/cmd/testdata/script/exp_gengotypes.txtar
··· 186 186 ./root/types.cue:43:14 187 187 fail.both.notList: conflicting values [1,2,3] and {embedded2?:int} (mismatched types list and struct): 188 188 ./cuetest/all.cue:5:24 189 - ./root/root.cue:95:2 189 + ./root/root.cue:96:2 190 190 fail.both.notString: conflicting values "not_a_struct" and {embedded2?:int} (mismatched types string and struct): 191 191 ./cuetest/all.cue:4:24 192 - ./root/root.cue:95:2 192 + ./root/root.cue:96:2 193 193 fail.cue."11_Int8".types.Int8: invalid value 99999 (out of bound <=127): 194 194 ./cuetest/all.cue:61:30 195 195 fail.cue."12_Int8".types.Int8: invalid value -99999 (out of bound >=-128): ··· 435 435 436 436 mustEqual1?: int 437 437 mustEqual2?: mustEqual1 438 + "quoted-field"?: string @go(QuotedField) 438 439 } 439 440 440 441 // Actually, this field needed even more documentation. ··· 646 647 Regular int64 `json:"regular"` 647 648 648 649 Required int64 `json:"required,omitempty"` 650 + 651 + QuotedField string `json:"quoted-field"` 649 652 650 653 // Optional types are represented as *T in Go if they are structs. 651 654 Optional int64 `json:"optional,omitempty"`
+3
internal/encoding/gotypes/generate.go
··· 265 265 continue 266 266 } 267 267 cueName := sel.String() 268 + if sel.IsString() { 269 + cueName = sel.Unquoted() 270 + } 268 271 cueName = strings.TrimRight(cueName, "?!") 269 272 g.emitDocs(cueName, val.Doc()) 270 273 // TODO: should we ensure that optional fields are always nilable in Go?