File: marsh.go

package info (click to toggle)
golang-github-getkin-kin-openapi 0.124.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,288 kB
  • sloc: sh: 344; makefile: 4
file content (26 lines) | stat: -rw-r--r-- 713 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package openapi3

import (
	"encoding/json"
	"fmt"
	"strings"

	"github.com/invopop/yaml"
)

func unmarshalError(jsonUnmarshalErr error) error {
	if before, after, found := strings.Cut(jsonUnmarshalErr.Error(), "Bis"); found && before != "" && after != "" {
		before = strings.ReplaceAll(before, " Go struct ", " ")
		return fmt.Errorf("%s%s", before, strings.ReplaceAll(after, "Bis", ""))
	}
	return jsonUnmarshalErr
}

func unmarshal(data []byte, v interface{}) error {
	// See https://github.com/getkin/kin-openapi/issues/680
	if err := json.Unmarshal(data, v); err != nil {
		// UnmarshalStrict(data, v) TODO: investigate how ymlv3 handles duplicate map keys
		return yaml.Unmarshal(data, v)
	}
	return nil
}