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