diff options
author | Bjørn Erik Pedersen <[email protected]> | 2020-06-30 16:11:05 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2020-07-06 20:03:36 +0200 |
commit | 12a65e76df9470d9563b91a22969ddb41b7c19aa (patch) | |
tree | ab7b7b3cc67fbb9b4a86c1c347081e4e959ed8e8 /parser | |
parent | 58c0f5e6171cbf8e3ed8d73ac95a7b85168c5b2f (diff) | |
download | hugo-12a65e76df9470d9563b91a22969ddb41b7c19aa.tar.gz hugo-12a65e76df9470d9563b91a22969ddb41b7c19aa.zip |
Add openapi3.Unmarshal
Fixes #7442
Fixes #7443
Diffstat (limited to 'parser')
-rw-r--r-- | parser/metadecoders/decoder.go | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/parser/metadecoders/decoder.go b/parser/metadecoders/decoder.go index 1a4a57076..2624ad16f 100644 --- a/parser/metadecoders/decoder.go +++ b/parser/metadecoders/decoder.go @@ -63,7 +63,7 @@ func (d Decoder) UnmarshalToMap(data []byte, f Format) (map[string]interface{}, return m, nil } - err := d.unmarshal(data, f, &m) + err := d.UnmarshalTo(data, f, &m) return m, err } @@ -122,13 +122,13 @@ func (d Decoder) Unmarshal(data []byte, f Format) (interface{}, error) { } var v interface{} - err := d.unmarshal(data, f, &v) + err := d.UnmarshalTo(data, f, &v) return v, err } -// unmarshal unmarshals data in format f into v. -func (d Decoder) unmarshal(data []byte, f Format, v interface{}) error { +// UnmarshalTo unmarshals data in format f into v. +func (d Decoder) UnmarshalTo(data []byte, f Format, v interface{}) error { var err error @@ -156,15 +156,17 @@ func (d Decoder) unmarshal(data []byte, f Format, v interface{}) error { case *interface{}: ptr = *v.(*interface{}) default: - return errors.Errorf("unknown type %T in YAML unmarshal", v) + // Not a map. } - if mm, changed := stringifyMapKeys(ptr); changed { - switch v.(type) { - case *map[string]interface{}: - *v.(*map[string]interface{}) = mm.(map[string]interface{}) - case *interface{}: - *v.(*interface{}) = mm + if ptr != nil { + if mm, changed := stringifyMapKeys(ptr); changed { + switch v.(type) { + case *map[string]interface{}: + *v.(*map[string]interface{}) = mm.(map[string]interface{}) + case *interface{}: + *v.(*interface{}) = mm + } } } case CSV: |