diff --git a/reflect.go b/reflect.go index 73ce7e4..4d2cc2e 100644 --- a/reflect.go +++ b/reflect.go @@ -622,6 +622,8 @@ func (t *Schema) structKeywordsFromTags(f reflect.StructField, parent *Schema, p t.arrayKeywords(tags) case "boolean": t.booleanKeywords(tags) + default: + t.nonDefaultTypeKeywords(tags) } extras := strings.Split(f.Tag.Get("jsonschema_extras"), ",") t.extraKeywords(extras) @@ -883,6 +885,21 @@ func (t *Schema) arrayKeywords(tags []string) { } } +func (t *Schema) nonDefaultTypeKeywords(tags []string) { + for _, tag := range tags { + nameValue := strings.SplitN(tag, "=", 2) + if len(nameValue) == 2 { + name, val := nameValue[0], nameValue[1] + switch name { + case "default": + t.Default = val + case "example": + t.Examples = append(t.Examples, val) + } + } + } +} + func (t *Schema) extraKeywords(tags []string) { for _, tag := range tags { nameValue := strings.SplitN(tag, "=", 2)