Skip to content

Commit

Permalink
Explicitly convert inMediaType json to outMediaType yaml
Browse files Browse the repository at this point in the history
Signed-off-by: Deathstroke <[email protected]>
  • Loading branch information
Deathstr0ke1 committed May 11, 2024
1 parent e0dda1c commit 0a0e7cf
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ func Convert(codecs serializer.CodecFactory, inMediaType, outMediaType string, i
if outMediaType == JsonMediaType {
encoded = append(encoded, '\n')
}
} else if inMediaType == JsonMediaType && outMediaType == YamlMediaType {
val := map[string]interface{}{}
if err := json.Unmarshal(in, &val); err != nil {
return nil, fmt.Errorf("error decoding from %s: %s", inMediaType, err)

Check failure on line 101 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / test

not enough return values

Check failure on line 101 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / run

not enough return values

Check failure on line 101 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / run

not enough return values

Check failure on line 101 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / run

not enough return values
}
encoded, err = yaml.Marshal(val)
if err != nil {
return nil, fmt.Errorf("error encoding from %s: %s", outMediaType, err)

Check failure on line 105 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / test

not enough return values

Check failure on line 105 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / run

not enough return values

Check failure on line 105 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / run

not enough return values

Check failure on line 105 in pkg/encoding/encoding.go

View workflow job for this annotation

GitHub Actions / run

not enough return values
}
} else {
inCodec, err := newCodec(codecs, typeMeta, inMediaType)
if err != nil {
Expand Down

0 comments on commit 0a0e7cf

Please sign in to comment.