(operation: OpenAPI.OperationObject, contract: AnyContractProcedure)
| 29 | } |
| 30 | |
| 31 | export function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject { |
| 32 | const operationCustoms: OverrideOperationValue[] = [] |
| 33 | |
| 34 | for (const errorItem of Object.values(contract['~orpc'].errorMap) as ErrorMap[keyof ErrorMap][]) { |
| 35 | const maybeExtender = errorItem ? getCustomOpenAPIOperation(errorItem) : undefined |
| 36 | |
| 37 | if (maybeExtender) { |
| 38 | operationCustoms.push(maybeExtender) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | if (isProcedure(contract)) { |
| 43 | for (const middleware of contract['~orpc'].middlewares) { |
| 44 | const maybeExtender = getCustomOpenAPIOperation(middleware) |
| 45 | |
| 46 | if (maybeExtender) { |
| 47 | operationCustoms.push(maybeExtender) |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | let currentOperation = operation |
| 53 | |
| 54 | for (const custom of operationCustoms) { |
| 55 | if (typeof custom === 'function') { |
| 56 | currentOperation = custom(currentOperation, contract) |
| 57 | } |
| 58 | else { |
| 59 | currentOperation = { |
| 60 | ...currentOperation, |
| 61 | ...custom, |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return currentOperation |
| 67 | } |
no test coverage detected