From d02453543010a10d89388feff178a23f896a41bf Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Mon, 24 Jun 2024 18:09:31 +0200 Subject: [PATCH] Update test --- reflect_test.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/reflect_test.go b/reflect_test.go index 3e3a641..17d9016 100644 --- a/reflect_test.go +++ b/reflect_test.go @@ -2516,22 +2516,37 @@ func TestReflector_Reflect_byteSlice(t *testing.T) { r := jsonschema.Reflector{} type S struct { - A []byte `json:"a" description:"Hello world!"` + A []byte `json:"a" description:"Hello world!"` + B json.RawMessage `json:"b" description:"I am a RawMessage."` + C *json.RawMessage `json:"c" description:"I am a RawMessage pointer."` } - v, err := json.Marshal(S{A: []byte("hello world!")}) + s1 := S{ + A: []byte("hello world!"), + B: []byte(`{"foo":"bar"}`), + } + s1.C = &s1.B + + v, err := json.Marshal(s1) require.NoError(t, err) - assert.Equal(t, `{"a":"aGVsbG8gd29ybGQh"}`, string(v)) // []byte is marshaled to base64. + // []byte is marshaled to base64, RawMessage value and pointer are passed as is. + assert.Equal(t, `{"a":"aGVsbG8gd29ybGQh","b":{"foo":"bar"},"c":{"foo":"bar"}}`, string(v)) var s2 S require.NoError(t, json.Unmarshal(v, &s2)) assert.Equal(t, "hello world!", string(s2.A)) // []byte is unmarshaled from base64. + assert.Equal(t, `{"foo":"bar"}`, string(s2.B)) + assert.Equal(t, `{"foo":"bar"}`, string(*s2.C)) s, err := r.Reflect(S{}) require.NoError(t, err) assertjson.EqMarshal(t, `{ - "properties":{"a":{"description":"Hello world!","type":"string","format":"base64"}}, + "properties":{ + "a":{"description":"Hello world!","type":"string","format":"base64"}, + "b":{"description":"I am a RawMessage."}, + "c":{"description":"I am a RawMessage pointer."} + }, "type":"object" }`, s) }