processInputType processes and extracts input-related metadata from a given inputType for an operation configuration.
(inputType reflect.Type, op *Operation, registry Registry)
| 1313 | // processInputType processes and extracts input-related metadata from a given |
| 1314 | // inputType for an operation configuration. |
| 1315 | func processInputType(inputType reflect.Type, op *Operation, registry Registry) (*findResult[*paramFieldInfo], []int, bool, []int, rawBodyType, reflect.Type, *Schema) { |
| 1316 | var inputBodyIndex []int |
| 1317 | inputParams := findParams(registry, op, inputType) |
| 1318 | hasInputBody := false |
| 1319 | if f, ok := inputType.FieldByName("Body"); ok { |
| 1320 | hasInputBody = true |
| 1321 | inputBodyIndex = f.Index |
| 1322 | initRequestBody(op) |
| 1323 | setRequestBodyFromBody(op, registry, f, inputType) |
| 1324 | ensureBodyReadTimeout(op) |
| 1325 | ensureMaxBodyBytes(op) |
| 1326 | } |
| 1327 | |
| 1328 | var rawBodyDataT reflect.Type |
| 1329 | var rawBodyIndex []int |
| 1330 | var rbt rawBodyType |
| 1331 | |
| 1332 | if f, ok := inputType.FieldByName("RawBody"); ok { |
| 1333 | rawBodyIndex = f.Index |
| 1334 | initRequestBody(op, setRequestBodyRequired) |
| 1335 | rbt = setRequestBodyFromRawBody(op, registry, f) |
| 1336 | |
| 1337 | if rbt == rbtMultipartDecoded { |
| 1338 | dataField, ok := f.Type.FieldByName("data") |
| 1339 | if !ok { |
| 1340 | panic("Expected type MultipartFormFiles[T] to have a 'data *T' generic pointer field") |
| 1341 | } |
| 1342 | rawBodyDataT = dataField.Type.Elem() |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | if op.RequestBody != nil { |
| 1347 | for _, mediaType := range op.RequestBody.Content { |
| 1348 | if mediaType.Schema != nil { |
| 1349 | // Ensure all schema validation errors are set up properly as some |
| 1350 | // parts of the schema may have been user-supplied. |
| 1351 | mediaType.Schema.PrecomputeMessages() |
| 1352 | } |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | var inSchema *Schema |
| 1357 | if op.RequestBody != nil && op.RequestBody.Content != nil { |
| 1358 | // Try to get schema from any available content type. |
| 1359 | // Prefer application/json for backwards compatibility, then try others. |
| 1360 | if op.RequestBody.Content["application/json"] != nil && op.RequestBody.Content["application/json"].Schema != nil { |
| 1361 | hasInputBody = true |
| 1362 | inSchema = op.RequestBody.Content["application/json"].Schema |
| 1363 | } else { |
| 1364 | // Fall back to the first available content type with a schema. |
| 1365 | for _, mediaType := range op.RequestBody.Content { |
| 1366 | if mediaType.Schema != nil && mediaType.Schema.Type != "string" && mediaType.Schema.Format != "binary" { |
| 1367 | hasInputBody = true |
| 1368 | inSchema = mediaType.Schema |
| 1369 | break |
| 1370 | } |
| 1371 | } |
| 1372 | } |
no test coverage detected
searching dependent graphs…