Skip to content

Commit d23ed1e

Browse files
committed
update the logic to only try to unmarshal json when it's json
1 parent 7671aca commit d23ed1e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

datamodel/spec_info.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,13 @@ func ExtractSpecInfoWithDocumentCheck(spec []byte, bypass bool) (*SpecInfo, erro
106106

107107
parseJSON := func(bytes []byte, spec *SpecInfo, parsedNode *yaml.Node) error {
108108
var jsonSpec map[string]interface{}
109-
if utils.IsYAML(string(bytes)) {
109+
switch {
110+
case utils.IsYAML(string(bytes)):
110111
_ = parsedNode.Decode(&jsonSpec)
111112
b, _ := json.Marshal(&jsonSpec)
112113
spec.SpecJSONBytes = &b
113114
spec.SpecJSON = &jsonSpec
114-
} else {
115+
case utils.IsJSON(string(bytes)):
115116
if err := json.Unmarshal(bytes, &jsonSpec); err != nil {
116117
return err
117118
}

0 commit comments

Comments
 (0)