Skip to content

Commit

Permalink
Added support for enum tag in schema generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieg0Code committed Dec 6, 2024
1 parent c203ca0 commit 7b426eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions jsonschema/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 != "" {
Expand Down
1 change: 1 addition & 0 deletions test.mp3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello

0 comments on commit 7b426eb

Please sign in to comment.