@@ -161,7 +161,7 @@ func RegisterOpenAPIOperation[T, B any](s *Server, method, path string) (*openap
161
161
}
162
162
163
163
// Request body
164
- bodyTag := schemaTagFromType [ B ] (s , * new (B ))
164
+ bodyTag := schemaTagFromType (s , * new (B ))
165
165
if (method == http .MethodPost || method == http .MethodPut || method == http .MethodPatch ) && bodyTag .name != "unknown-interface" && bodyTag .name != "string" {
166
166
content := openapi3 .NewContentWithSchemaRef (& bodyTag .SchemaRef , []string {"application/json" })
167
167
requestBody := openapi3 .NewRequestBody ().
@@ -180,7 +180,7 @@ func RegisterOpenAPIOperation[T, B any](s *Server, method, path string) (*openap
180
180
}
181
181
}
182
182
183
- responseSchema := schemaTagFromType [ T ] (s , * new (T ))
183
+ responseSchema := schemaTagFromType (s , * new (T ))
184
184
content := openapi3 .NewContentWithSchemaRef (& responseSchema .SchemaRef , []string {"application/json" })
185
185
response := openapi3 .NewResponse ().
186
186
WithDescription ("OK" ).
@@ -205,7 +205,7 @@ type schemaTag struct {
205
205
name string
206
206
}
207
207
208
- func schemaTagFromType [ V any ] (s * Server , v any ) schemaTag {
208
+ func schemaTagFromType (s * Server , v any ) schemaTag {
209
209
if v == nil {
210
210
// ensure we add unknown-interface to our schemas
211
211
s .getOrCreateSchema ("unknown-interface" , struct {}{})
@@ -217,7 +217,7 @@ func schemaTagFromType[V any](s *Server, v any) schemaTag {
217
217
}
218
218
}
219
219
220
- return dive [ V ] (s , reflect .TypeOf (v ), schemaTag {}, 5 )
220
+ return dive (s , reflect .TypeOf (v ), schemaTag {}, 5 )
221
221
}
222
222
223
223
// dive returns a schemaTag which includes the generated openapi3.SchemaRef and
@@ -227,7 +227,7 @@ func schemaTagFromType[V any](s *Server, v any) schemaTag {
227
227
// If the type is a slice or array type it will dive into the type as well as
228
228
// build and openapi3.Schema where Type is array and Ref is set to the proper
229
229
// components Schema
230
- func dive [ V any ] (s * Server , t reflect.Type , tag schemaTag , maxDepth int ) schemaTag {
230
+ func dive (s * Server , t reflect.Type , tag schemaTag , maxDepth int ) schemaTag {
231
231
if maxDepth == 0 {
232
232
return schemaTag {
233
233
name : "default" ,
@@ -239,10 +239,10 @@ func dive[V any](s *Server, t reflect.Type, tag schemaTag, maxDepth int) schemaT
239
239
240
240
switch t .Kind () {
241
241
case reflect .Ptr , reflect .Map , reflect .Chan , reflect .Func , reflect .UnsafePointer :
242
- return dive [ V ] (s , t .Elem (), tag , maxDepth - 1 )
242
+ return dive (s , t .Elem (), tag , maxDepth - 1 )
243
243
244
244
case reflect .Slice , reflect .Array :
245
- item := dive [ V ] (s , t .Elem (), tag , maxDepth - 1 )
245
+ item := dive (s , t .Elem (), tag , maxDepth - 1 )
246
246
tag .name = item .name
247
247
tag .Value = & openapi3.Schema {
248
248
Type : "array" ,
@@ -253,7 +253,7 @@ func dive[V any](s *Server, t reflect.Type, tag schemaTag, maxDepth int) schemaT
253
253
default :
254
254
tag .name = t .Name ()
255
255
tag .Ref = "#/components/schemas/" + tag .name
256
- tag .Value = s .getOrCreateSchema (tag .name , new ( V ))
256
+ tag .Value = s .getOrCreateSchema (tag .name , reflect . New ( t ). Interface ( ))
257
257
return tag
258
258
}
259
259
}
0 commit comments