Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion jsonschema/infer.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ func forType(t reflect.Type, seen map[reflect.Type]bool, ignore bool, schemas ma
s.Types = []string{"null", s.Type}
s.Type = ""
}
schemas[t] = s
return s, nil
}

Expand Down
19 changes: 19 additions & 0 deletions jsonschema/infer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,22 @@ func TestForWithCycle(t *testing.T) {
func falseSchema() *jsonschema.Schema {
return &jsonschema.Schema{Not: &jsonschema.Schema{}}
}

func TestDupSchema(t *testing.T) {
// Verify that we don't repeat schema contents, even if we clone the actual schemas.
type args struct {
S string `jsonschema:"str"`
A []string `jsonschema:"arr"`
}

s := forType[args](false)
if g, w := s.Properties["S"].Description, "str"; g != w {
t.Errorf("S: got %q, want %q", g, w)
}
if g, w := s.Properties["A"].Description, "arr"; g != w {
t.Errorf("A: got %q, want %q", g, w)
}
if g, w := s.Properties["A"].Items.Description, ""; g != w {
t.Errorf("A.items: got %q, want %q", g, w)
}
}