diff --git a/jsonschema/json.go b/jsonschema/json.go index bcb253fa..3036b99a 100644 --- a/jsonschema/json.go +++ b/jsonschema/json.go @@ -131,6 +131,12 @@ func reflectSchemaObject(t reflect.Type) (*Definition, error) { required = false } + enumTag := field.Tag.Get("enum") + var enumValues []string + if enumTag != "" { + enumValues = strings.Split(enumTag, ",") + } + item, err := reflectSchema(field.Type) if err != nil { return nil, err @@ -139,6 +145,11 @@ func reflectSchemaObject(t reflect.Type) (*Definition, error) { if description != "" { item.Description = description } + + if len(enumValues) > 0 { + item.Enum = enumValues + } + properties[jsonTag] = *item if s := field.Tag.Get("required"); s != "" { diff --git a/test.mp3 b/test.mp3 new file mode 100644 index 00000000..b6fc4c62 --- /dev/null +++ b/test.mp3 @@ -0,0 +1 @@ +hello \ No newline at end of file