fix: skip fields named "-" when generating schemas

This commit is contained in:
Daniel G. Taylor 2020-04-20 21:55:44 -07:00
parent 8004efb597
commit 3a6046412a
No known key found for this signature in database
GPG key ID: 7BD6DC99C9A87E22
2 changed files with 15 additions and 0 deletions

View file

@ -169,6 +169,11 @@ func GenerateWithMode(t reflect.Type, mode Mode, schema *Schema) (*Schema, error
name = jsonTags[0]
}
if name == "-" {
// Skip deliberately filtered out items
continue
}
s, err := GenerateWithMode(f.Type, mode, nil)
if err != nil {
return nil, err

View file

@ -515,6 +515,16 @@ func TestSchemaNonStringExampleErrorCast(t *testing.T) {
assert.Error(t, err)
}
func TestSchemaFieldFilteredOut(t *testing.T) {
type Example struct {
Foo bool `json:"-"`
}
s, err := Generate(reflect.ValueOf(Example{}).Type())
assert.NoError(t, err)
assert.Equal(t, 0, len(s.Properties))
}
func TestPointerHelpers(t *testing.T) {
// Just confirm this compiles.
_ = Schema{