diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-06-30 17:11:05 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-07-06 21:03:36 +0300 |
commit | 12a65e76df9470d9563b91a22969ddb41b7c19aa (patch) | |
tree | ab7b7b3cc67fbb9b4a86c1c347081e4e959ed8e8 /tpl/transform | |
parent | 58c0f5e6171cbf8e3ed8d73ac95a7b85168c5b2f (diff) |
Add openapi3.Unmarshal
Fixes #7442
Fixes #7443
Diffstat (limited to 'tpl/transform')
-rw-r--r-- | tpl/transform/unmarshal.go | 17 | ||||
-rw-r--r-- | tpl/transform/unmarshal_test.go | 2 |
2 files changed, 8 insertions, 11 deletions
diff --git a/tpl/transform/unmarshal.go b/tpl/transform/unmarshal.go index da06b6aa1..b606c870a 100644 --- a/tpl/transform/unmarshal.go +++ b/tpl/transform/unmarshal.go @@ -17,17 +17,20 @@ import ( "io/ioutil" "strings" + "github.com/gohugoio/hugo/resources/resource" + + "github.com/gohugoio/hugo/common/types" + "github.com/mitchellh/mapstructure" "github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/parser/metadecoders" - "github.com/gohugoio/hugo/resources/resource" "github.com/pkg/errors" "github.com/spf13/cast" ) -// Unmarshal unmarshals the data given, which can be either a string +// Unmarshal unmarshals the data given, which can be either a string, json.RawMessage // or a Resource. Supported formats are JSON, TOML, YAML, and CSV. // You can optionally provide an options map as the first argument. func (ns *Namespace) Unmarshal(args ...interface{}) (interface{}, error) { @@ -55,7 +58,7 @@ func (ns *Namespace) Unmarshal(args ...interface{}) (interface{}, error) { } } - if r, ok := data.(unmarshableResource); ok { + if r, ok := data.(resource.UnmarshableResource); ok { key := r.Key() if key == "" { @@ -87,7 +90,7 @@ func (ns *Namespace) Unmarshal(args ...interface{}) (interface{}, error) { }) } - dataStr, err := cast.ToStringE(data) + dataStr, err := types.ToStringE(data) if err != nil { return nil, errors.Errorf("type %T not supported", data) } @@ -104,12 +107,6 @@ func (ns *Namespace) Unmarshal(args ...interface{}) (interface{}, error) { }) } -// All the relevant resources implements this interface. -type unmarshableResource interface { - resource.ReadSeekCloserResource - resource.Identifier -} - func decodeDecoder(m map[string]interface{}) (metadecoders.Decoder, error) { opts := metadecoders.Default diff --git a/tpl/transform/unmarshal_test.go b/tpl/transform/unmarshal_test.go index 7b0caa07f..183bdefd5 100644 --- a/tpl/transform/unmarshal_test.go +++ b/tpl/transform/unmarshal_test.go @@ -20,11 +20,11 @@ import ( "testing" "github.com/gohugoio/hugo/common/hugio" + "github.com/gohugoio/hugo/resources/resource" "github.com/gohugoio/hugo/media" qt "github.com/frankban/quicktest" - "github.com/gohugoio/hugo/resources/resource" "github.com/spf13/viper" ) |