Skip to content

Commit

Permalink
add interface example
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidfm committed Jan 30, 2024
1 parent d7cd2eb commit 1d1197f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
18 changes: 17 additions & 1 deletion fixtures/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@
}
]
]
},
"any_example": {
"default": true,
"examples": [
1234,
"string_example",
{
"test": 42
},
[
1,
"str",
true
]
]
}
},
"additionalProperties": false,
Expand All @@ -92,7 +107,8 @@
"float_example",
"int_array_example",
"map_example",
"map_array_example"
"map_array_example",
"any_example"
]
}
}
Expand Down
11 changes: 9 additions & 2 deletions reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,15 @@ func (t *Schema) parseValue(val string) (parsed interface{}, ok bool) {
}
return parsed, true

case "", "object":
obj := make(map[string]interface{})
case "object":
obj := make(map[string]any)
if err := json.Unmarshal([]byte(val), &obj); err != nil {
return nil, false
}
return obj, true

case "":
var obj any
if err := json.Unmarshal([]byte(val), &obj); err != nil {
return nil, false
}
Expand Down
1 change: 1 addition & 0 deletions reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ type Examples struct {
IntArrayExample []int `json:"int_array_example" jsonschema:"example=1;2,example=3;4,example=5;6"`
MapExample map[string]string `json:"map_example" jsonschema:"example={\"key\": \"value\"}"`
MapArrayExample []map[string]string `json:"map_array_example" jsonschema:"example={\"a\": \"b\"};{\"c\": \"d\"},example={\"hello\": \"test\"}"`
AnyExample any `json:"any_example" jsonschema:"example=1234,example=\"string_example\",example={\"test\": 42},example=[1\\,\"str\"\\,true],default=true"`
}

type SchemaExtendTestBase struct {
Expand Down

0 comments on commit 1d1197f

Please sign in to comment.