MCPcopy Create free account
hub / github.com/middleapi/orpc / applyCustomOpenAPIOperation

Function applyCustomOpenAPIOperation

packages/openapi/src/openapi-custom.ts:31–67  ·  view source on GitHub ↗
(operation: OpenAPI.OperationObject, contract: AnyContractProcedure)

Source from the content-addressed store, hash-verified

29}
30
31export 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}

Callers 2

generateMethod · 0.90

Calls 4

isProcedureFunction · 0.90
valuesMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected