-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from danielgtaylor/fullname
fix: enhanced generic schema naming
- Loading branch information
Showing
5 changed files
with
78 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ mem.out | |
docs/site | ||
docs/__pycache__ | ||
docs/.cache | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package huma | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
"time" | ||
|
||
"github.com/danielgtaylor/huma/v2/examples/protodemo/protodemo" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type Output[T any] struct{} | ||
|
||
type Embedded[P any] struct{} | ||
|
||
type EmbeddedTwo[P, V any] struct{} | ||
|
||
type S struct{} | ||
|
||
type ü struct{} | ||
|
||
type MP4 struct{} | ||
|
||
func TestDefaultSchemaNamer(t *testing.T) { | ||
type Renamed Output[*[]Embedded[protodemo.User]] | ||
|
||
for _, example := range []struct { | ||
typ any | ||
name string | ||
}{ | ||
{int(0), "Int"}, | ||
{int64(0), "Int64"}, | ||
{S{}, "S"}, | ||
{time.Time{}, "Time"}, | ||
{Output[int]{}, "OutputInt"}, | ||
{Output[*int]{}, "OutputInt"}, | ||
{Output[[]int]{}, "OutputListInt"}, | ||
{Output[[]*int]{}, "OutputListInt"}, | ||
{Output[[][]int]{}, "OutputListListInt"}, | ||
{Output[map[string]int]{}, "OutputMapStringInt"}, | ||
{Output[map[string][]*int]{}, "OutputMapStringListInt"}, | ||
{Output[S]{}, "OutputS"}, | ||
{Output[ü]{}, "OutputÜ"}, | ||
{Output[MP4]{}, "OutputMP4"}, | ||
{Output[Embedded[*protodemo.User]]{}, "OutputEmbeddedUser"}, | ||
{Output[*[]Embedded[protodemo.User]]{}, "OutputListEmbeddedUser"}, | ||
{Output[EmbeddedTwo[[]protodemo.User, **time.Time]]{}, "OutputEmbeddedTwoListUserTime"}, | ||
{Renamed{}, "Renamed"}, | ||
} { | ||
t.Run(example.name, func(t *testing.T) { | ||
name := DefaultSchemaNamer(reflect.TypeOf(example.typ), "hint") | ||
assert.Equal(t, example.name, name) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters