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

Function defineErrors

huma.go:1627–1656  ·  view source on GitHub ↗

defineErrors extracts possible error responses and defines them on the operation op.

(op *Operation, registry Registry)

Source from the content-addressed store, hash-verified

1625// defineErrors extracts possible error responses and defines them on the
1626// operation op.
1627func defineErrors(op *Operation, registry Registry) {
1628 exampleErr := NewError(0, "")
1629 errContentType := "application/json"
1630 if ctf, ok := exampleErr.(ContentTypeFilter); ok {
1631 errContentType = ctf.ContentType(errContentType)
1632 }
1633 errType := deref(reflect.TypeOf(exampleErr))
1634 errSchema := registry.Schema(errType, true, getHint(errType, "", "Error"))
1635 for _, code := range op.Errors {
1636 op.Responses[strconv.Itoa(code)] = &Response{
1637 Description: http.StatusText(code),
1638 Content: map[string]*MediaType{
1639 errContentType: {
1640 Schema: errSchema,
1641 },
1642 },
1643 }
1644 }
1645 if len(op.Responses) <= 1 && len(op.Errors) == 0 {
1646 // No errors are defined, so set a default response.
1647 op.Responses["default"] = &Response{
1648 Description: "Error",
1649 Content: map[string]*MediaType{
1650 errContentType: {
1651 Schema: errSchema,
1652 },
1653 },
1654 }
1655 }
1656}
1657
1658// getParamValue extracts the requested parameter from the relevant
1659// context or cookie source. If unset, the function returns the default value

Callers 1

RegisterFunction · 0.85

Calls 4

getHintFunction · 0.85
derefFunction · 0.70
ContentTypeMethod · 0.65
SchemaMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…