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

Function multiPartFormFileSchema

formdata.go:200–239  ·  view source on GitHub ↗
(r Registry, t reflect.Type)

Source from the content-addressed store, hash-verified

198}
199
200func multiPartFormFileSchema(r Registry, t reflect.Type) *Schema {
201 nFields := t.NumField()
202 schema := &Schema{
203 Type: "object",
204 Properties: make(map[string]*Schema, nFields),
205 requiredMap: make(map[string]bool, nFields),
206 }
207 requiredFields := make([]string, 0, nFields)
208 for i := range nFields {
209 f := t.Field(i)
210 name := formDataFieldName(f)
211
212 switch {
213 case f.Type == reflect.TypeFor[FormFile]():
214 schema.Properties[name] = multiPartFileSchema(f)
215 case f.Type == reflect.TypeFor[[]FormFile]():
216 schema.Properties[name] = &Schema{
217 Type: "array",
218 Items: multiPartFileSchema(f),
219 }
220 default:
221 schema.Properties[name] = SchemaFromField(r, f, name)
222
223 // Should we panic if [T] struct defines fields with unsupported types?
224 }
225
226 fieldRequired := !getConfig[registryConfig](r).FieldsOptionalByDefault
227
228 if _, ok := f.Tag.Lookup("required"); ok {
229 fieldRequired = boolTag(f, "required", false)
230 }
231
232 if fieldRequired {
233 requiredFields = append(requiredFields, name)
234 schema.requiredMap[name] = true
235 }
236 }
237 schema.Required = requiredFields
238 return schema
239}
240
241func multiPartFileSchema(f reflect.StructField) *Schema {
242 return &Schema{

Callers 1

Calls 4

formDataFieldNameFunction · 0.85
multiPartFileSchemaFunction · 0.85
SchemaFromFieldFunction · 0.85
boolTagFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…