defineErrors extracts possible error responses and defines them on the operation op.
(op *Operation, registry Registry)
| 1625 | // defineErrors extracts possible error responses and defines them on the |
| 1626 | // operation op. |
| 1627 | func 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 |
no test coverage detected
searching dependent graphs…