( schema: unknown, mediaType: string, r: DocResolver, )
| 267 | : "base64"; |
| 268 | |
| 269 | const detectFileHint = ( |
| 270 | schema: unknown, |
| 271 | mediaType: string, |
| 272 | r: DocResolver, |
| 273 | ): OperationFileHint | undefined => { |
| 274 | const resolved = isRecord(schema) ? r.resolve<Record<string, unknown>>(schema) : null; |
| 275 | if (!resolved) return undefined; |
| 276 | |
| 277 | if (!isJsonMediaType(mediaType) && binaryStringSchema(resolved)) { |
| 278 | return OperationFileHint.make({ |
| 279 | kind: "binaryResponse", |
| 280 | mimeType: Option.some(mediaType), |
| 281 | dataField: Option.none(), |
| 282 | sizeField: Option.none(), |
| 283 | encoding: Option.none(), |
| 284 | }); |
| 285 | } |
| 286 | |
| 287 | if (!isJsonMediaType(mediaType)) return undefined; |
| 288 | |
| 289 | const properties = resolved.properties; |
| 290 | if (!isRecord(properties)) return undefined; |
| 291 | const data = properties.data; |
| 292 | const dataSchema = isRecord(data) ? r.resolve<Record<string, unknown>>(data) : null; |
| 293 | if (!dataSchema || !binaryStringSchema(dataSchema)) return undefined; |
| 294 | |
| 295 | const size = properties.size; |
| 296 | const sizeSchema = isRecord(size) ? r.resolve<Record<string, unknown>>(size) : null; |
| 297 | const sizeField = sizeSchema && numericType(sizeSchema) ? "size" : undefined; |
| 298 | |
| 299 | return OperationFileHint.make({ |
| 300 | kind: "byteField", |
| 301 | mimeType: Option.some("application/octet-stream"), |
| 302 | dataField: Option.some("data"), |
| 303 | sizeField: sizeField ? Option.some(sizeField) : Option.none(), |
| 304 | encoding: Option.some(base64EncodingFromDescription(dataSchema)), |
| 305 | }); |
| 306 | }; |
| 307 | |
| 308 | const extractResponseBody = ( |
| 309 | operation: OperationObject, |
no test coverage detected