add quotes around field name in required field error

master
Felix Lange 8 years ago
parent 2bc71e15d7
commit 71af48c00f
  1. 2
      genmethod.go
  2. 8
      internal/tests/mapconv/output.go
  3. 8
      internal/tests/sliceconv/output.go

@ -181,7 +181,7 @@ func (m *marshalMethod) unmarshalConversions(from, to Var, format string) (s []S
Body: m.convert(accessFrom, accessTo, f.typ, f.origTyp), Body: m.convert(accessFrom, accessTo, f.typ, f.origTyp),
}) })
} else { } else {
err := fmt.Sprintf("missing required field %s for %s", f.encodedName(format), m.mtyp.name) err := fmt.Sprintf("missing required field '%s' for %s", f.encodedName(format), m.mtyp.name)
errors := m.scope.parent.packageName("errors") errors := m.scope.parent.packageName("errors")
s = append(s, If{ s = append(s, If{
Condition: Equals{Lhs: accessFrom, Rhs: NIL}, Condition: Equals{Lhs: accessFrom, Rhs: NIL},

@ -35,14 +35,14 @@ func (x *X) UnmarshalJSON(input []byte) error {
} }
var x0 X var x0 X
if dec.Map == nil { if dec.Map == nil {
return errors.New("missing required field map for X") return errors.New("missing required field 'map' for X")
} }
x0.Map = make(map[string]int, len(dec.Map)) x0.Map = make(map[string]int, len(dec.Map))
for k, v := range dec.Map { for k, v := range dec.Map {
x0.Map[string(k)] = int(v) x0.Map[string(k)] = int(v)
} }
if dec.Named == nil { if dec.Named == nil {
return errors.New("missing required field named for X") return errors.New("missing required field 'named' for X")
} }
x0.Named = make(namedMap, len(dec.Named)) x0.Named = make(namedMap, len(dec.Named))
for k, v := range dec.Named { for k, v := range dec.Named {
@ -80,14 +80,14 @@ func (x *X) UnmarshalYAML(unmarshal func(interface{}) error) error {
} }
var x0 X var x0 X
if dec.Map == nil { if dec.Map == nil {
return errors.New("missing required field map for X") return errors.New("missing required field 'map' for X")
} }
x0.Map = make(map[string]int, len(dec.Map)) x0.Map = make(map[string]int, len(dec.Map))
for k, v := range dec.Map { for k, v := range dec.Map {
x0.Map[string(k)] = int(v) x0.Map[string(k)] = int(v)
} }
if dec.Named == nil { if dec.Named == nil {
return errors.New("missing required field named for X") return errors.New("missing required field 'named' for X")
} }
x0.Named = make(namedMap, len(dec.Named)) x0.Named = make(namedMap, len(dec.Named))
for k, v := range dec.Named { for k, v := range dec.Named {

@ -35,14 +35,14 @@ func (x *X) UnmarshalJSON(input []byte) error {
} }
var x0 X var x0 X
if dec.Slice == nil { if dec.Slice == nil {
return errors.New("missing required field slice for X") return errors.New("missing required field 'slice' for X")
} }
x0.Slice = make([]int, len(dec.Slice)) x0.Slice = make([]int, len(dec.Slice))
for k, v := range dec.Slice { for k, v := range dec.Slice {
x0.Slice[k] = int(v) x0.Slice[k] = int(v)
} }
if dec.Named == nil { if dec.Named == nil {
return errors.New("missing required field named for X") return errors.New("missing required field 'named' for X")
} }
x0.Named = make(namedSlice, len(dec.Named)) x0.Named = make(namedSlice, len(dec.Named))
for k, v := range dec.Named { for k, v := range dec.Named {
@ -80,14 +80,14 @@ func (x *X) UnmarshalYAML(unmarshal func(interface{}) error) error {
} }
var x0 X var x0 X
if dec.Slice == nil { if dec.Slice == nil {
return errors.New("missing required field slice for X") return errors.New("missing required field 'slice' for X")
} }
x0.Slice = make([]int, len(dec.Slice)) x0.Slice = make([]int, len(dec.Slice))
for k, v := range dec.Slice { for k, v := range dec.Slice {
x0.Slice[k] = int(v) x0.Slice[k] = int(v)
} }
if dec.Named == nil { if dec.Named == nil {
return errors.New("missing required field named for X") return errors.New("missing required field 'named' for X")
} }
x0.Named = make(namedSlice, len(dec.Named)) x0.Named = make(namedSlice, len(dec.Named))
for k, v := range dec.Named { for k, v := range dec.Named {

Loading…
Cancel
Save