Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop committed Mar 6, 2024
1 parent c32d392 commit 52862fb
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1883,3 +1883,38 @@ func TestReflector_Reflect_textMarshaler(t *testing.T) {
"type":"object"
}`, schema)
}

type rawExposer func() ([]byte, error)

func (r rawExposer) JSONSchemaBytes() ([]byte, error) {
return r()
}

func TestReflector_AddOperation_rawSchema(t *testing.T) {
r := jsonschema.Reflector{}

type My struct {
A interface{} `json:"a"`
B interface{} `json:"b"`
}

m := My{
A: rawExposer(func() ([]byte, error) {
return []byte(`{"type":"object","properties":{"foo":{"type":"integer"}}}`), nil
}),
B: rawExposer(func() ([]byte, error) {
return []byte(`{"type":"object","properties":{"bar":{"type":"integer"}}}`), nil
}),
}

s, err := r.Reflect(m)
require.NoError(t, err)

assertjson.EqMarshal(t, `{
"properties":{
"a":{"properties":{"foo":{"type":"integer"}},"type":"object"},
"b":{"properties":{"bar":{"type":"integer"}},"type":"object"}
},
"type":"object"
}`, s)
}

0 comments on commit 52862fb

Please sign in to comment.