fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix bodySerializer for binary format request bodies

- Modified SDK operation.ts to check for binary format in request body schema
- Set bodySerializer to null for any request body with format: 'binary'
- Added test spec body-binary-format.yaml with examples
- Verified fix works correctly for application/zip, application/pdf, and application/octet-stream

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>

+60
+13
packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts
··· 252 252 const reqOptions = $.object(); 253 253 254 254 if (operation.body) { 255 + // Check if body has binary format - if so, don't use JSON serializer 256 + const isBinaryFormat = operation.body.schema.format === 'binary'; 257 + 255 258 switch (operation.body.type) { 256 259 case 'form-data': { 257 260 const symbol = plugin.external('client.formDataBodySerializer'); ··· 260 263 } 261 264 case 'json': 262 265 // jsonBodySerializer is the default, no need to specify 266 + // unless the schema has binary format 267 + if (isBinaryFormat) { 268 + reqOptions.prop('bodySerializer', $.literal(null)); 269 + } 263 270 break; 264 271 case 'text': 265 272 case 'octet-stream': ··· 271 278 reqOptions.spread(symbol); 272 279 break; 273 280 } 281 + default: 282 + // For unrecognized media types with binary format, don't use JSON serializer 283 + if (isBinaryFormat) { 284 + reqOptions.prop('bodySerializer', $.literal(null)); 285 + } 286 + break; 274 287 } 275 288 } 276 289
+47
specs/3.0.x/body-binary-format.yaml
··· 1 + openapi: 3.0.0 2 + info: 3 + title: OpenAPI 3.0.0 binary format body example 4 + version: 1 5 + paths: 6 + /upload-zip: 7 + post: 8 + summary: Upload a zip file 9 + operationId: uploadZip 10 + requestBody: 11 + required: true 12 + content: 13 + application/zip: 14 + schema: 15 + type: string 16 + format: binary 17 + responses: 18 + '204': 19 + description: Successfully uploaded 20 + /upload-pdf: 21 + post: 22 + summary: Upload a PDF file 23 + operationId: uploadPdf 24 + requestBody: 25 + required: true 26 + content: 27 + application/pdf: 28 + schema: 29 + type: string 30 + format: binary 31 + responses: 32 + '204': 33 + description: Successfully uploaded 34 + /upload-binary: 35 + post: 36 + summary: Upload binary data 37 + operationId: uploadBinary 38 + requestBody: 39 + required: true 40 + content: 41 + application/octet-stream: 42 + schema: 43 + type: string 44 + format: binary 45 + responses: 46 + '204': 47 + description: Successfully uploaded