MCPcopy
hub / github.com/danielgtaylor/huma / TestSchema

Function TestSchema

schema_test.go:106–1289  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

104}
105
106func TestSchema(t *testing.T) {
107 bitSize := strconv.Itoa(bits.UintSize)
108
109 cases := []struct {
110 name string
111 input any
112 expected string
113 panics string
114 }{
115 {
116 name: "bool",
117 input: true,
118 expected: `{"type": "boolean"}`,
119 },
120 {
121 name: "bool-pointer",
122 input: Ptr(true),
123 expected: `{"type": ["boolean", "null"]}`,
124 },
125 {
126 name: "int",
127 input: 1,
128 expected: `{"type": "integer", "format": "int` + bitSize + `"}`,
129 },
130 {
131 name: "int32",
132 input: int32(1),
133 expected: `{"type": "integer", "format": "int32"}`,
134 },
135 {
136 name: "int64",
137 input: int64(1),
138 expected: `{"type": "integer", "format": "int64"}`,
139 },
140 {
141 name: "uint",
142 input: uint(1),
143 expected: `{"type": "integer", "format": "int` + bitSize + `", "minimum": 0}`,
144 },
145 {
146 name: "uint32",
147 input: uint32(1),
148 expected: `{"type": "integer", "format": "int32", "minimum": 0}`,
149 },
150 {
151 name: "uint64",
152 input: uint64(1),
153 expected: `{"type": "integer", "format": "int64", "minimum": 0}`,
154 },
155 {
156 name: "float64",
157 input: 1.0,
158 expected: `{"type": "number", "format": "double"}`,
159 },
160 {
161 name: "float32",
162 input: float32(1.0),
163 expected: `{"type": "number", "format": "float"}`,

Callers

nothing calls this directly

Calls 4

PtrFunction · 0.85
RunMethod · 0.65
SchemaMethod · 0.65
MarshalMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…