( operation: OperationObject, r: DocResolver, )
| 125 | }; |
| 126 | |
| 127 | const extractRequestBody = ( |
| 128 | operation: OperationObject, |
| 129 | r: DocResolver, |
| 130 | ): OperationRequestBody | undefined => { |
| 131 | if (!operation.requestBody) return undefined; |
| 132 | |
| 133 | const body = r.resolve<RequestBodyObject>(operation.requestBody); |
| 134 | if (!body) return undefined; |
| 135 | |
| 136 | const contents = declaredContents(body.content).map(({ mediaType, media }) => |
| 137 | MediaBinding.make({ |
| 138 | contentType: mediaType, |
| 139 | schema: Option.fromNullishOr(multipartFileInputSchema(media.schema, mediaType)), |
| 140 | encoding: Option.fromNullishOr( |
| 141 | buildEncodingRecord((media as { encoding?: Record<string, unknown> }).encoding), |
| 142 | ), |
| 143 | }), |
| 144 | ); |
| 145 | if (contents.length === 0) return undefined; |
| 146 | |
| 147 | // Default = first declared (spec author's preferred order). Callers can |
| 148 | // override at invoke time with a `contentType` arg. |
| 149 | const defaultContent = contents[0]!; |
| 150 | |
| 151 | return OperationRequestBody.make({ |
| 152 | required: body.required === true, |
| 153 | contentType: defaultContent.contentType, |
| 154 | schema: defaultContent.schema, |
| 155 | contents: Option.some(contents), |
| 156 | }); |
| 157 | }; |
| 158 | |
| 159 | // --------------------------------------------------------------------------- |
| 160 | // Response schema extraction |
no test coverage detected