Skip to content

Commit cf3229a

Browse files
author
Alexander Zielenski
committed
add vendor extensions to marshal openapi v2 header
Discovered while fuzzing a type converter to gnostic. Seems like it was forgotten to include this when originally implemented.
1 parent 4241196 commit cf3229a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pkg/validation/spec/header.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ func (h Header) MarshalJSON() ([]byte, error) {
5353
if err != nil {
5454
return nil, err
5555
}
56-
return swag.ConcatJSON(b1, b2, b3), nil
56+
b4, err := json.Marshal(h.VendorExtensible)
57+
if err != nil {
58+
return nil, err
59+
}
60+
return swag.ConcatJSON(b1, b2, b3, b4), nil
5761
}
5862

5963
// UnmarshalJSON unmarshals this header from JSON

pkg/validation/spec/header_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"testing"
2020

2121
"github.com/stretchr/testify/assert"
22+
"github.com/stretchr/testify/require"
2223
)
2324

2425
func float64Ptr(f float64) *float64 {
@@ -88,3 +89,19 @@ func TestIntegrationHeader(t *testing.T) {
8889

8990
assertParsesJSON(t, headerJSON, header)
9091
}
92+
93+
// Makes sure that a Header unmarshaled from known good JSON, and one unmarshaled
94+
// from generated JSON are equivalent.
95+
func TestHeaderSerialization(t *testing.T) {
96+
generatedJSON, err := json.Marshal(header)
97+
require.NoError(t, err)
98+
99+
100+
generatedJSONActual := Header{}
101+
require.NoError(t, json.Unmarshal(generatedJSON, &generatedJSONActual))
102+
require.EqualValues(t, header, generatedJSONActual)
103+
104+
goodJSONActual := Header{}
105+
require.NoError(t, json.Unmarshal([]byte(headerJSON), &goodJSONActual))
106+
require.EqualValues(t, header, goodJSONActual)
107+
}

0 commit comments

Comments
 (0)