( parameters: readonly OperationParameter[], requestBody: OperationRequestBody | undefined, servers: readonly ServerInfo[], )
| 332 | }; |
| 333 | |
| 334 | export const buildInputSchema = ( |
| 335 | parameters: readonly OperationParameter[], |
| 336 | requestBody: OperationRequestBody | undefined, |
| 337 | servers: readonly ServerInfo[], |
| 338 | ): Record<string, unknown> | undefined => { |
| 339 | const properties: Record<string, unknown> = {}; |
| 340 | const required: string[] = []; |
| 341 | let requiredBodyAlternatives: readonly { readonly required: readonly string[] }[] | undefined; |
| 342 | |
| 343 | for (const param of parameters) { |
| 344 | properties[param.name] = Option.getOrElse(param.schema, () => ({ type: "string" })); |
| 345 | if (param.required) required.push(param.name); |
| 346 | } |
| 347 | |
| 348 | // A path/query parameter named `server` takes precedence over the host input. |
| 349 | const serverProperty = buildServerInputProperty(servers); |
| 350 | if (serverProperty && !("server" in properties)) properties.server = serverProperty; |
| 351 | |
| 352 | if (requestBody) { |
| 353 | // When the spec declares multiple media types for this requestBody, |
| 354 | // expose `contentType` so the model can pick. Default = first declared. |
| 355 | // For mixed bodies, `body` schema tracks the default; the model is |
| 356 | // responsible for supplying a body shape that matches whichever |
| 357 | // contentType it picks. Octet-only operations use `bodyBase64` instead. |
| 358 | const contents = Option.getOrUndefined(requestBody.contents); |
| 359 | const defaultIsOctetStream = |
| 360 | requestBody.contentType.split(";")[0]?.trim().toLowerCase() === "application/octet-stream"; |
| 361 | const acceptsOctetStream = |
| 362 | defaultIsOctetStream || |
| 363 | contents?.some( |
| 364 | (content) => |
| 365 | content.contentType.split(";")[0]?.trim().toLowerCase() === "application/octet-stream", |
| 366 | ) === true; |
| 367 | const acceptsBody = |
| 368 | !defaultIsOctetStream || |
| 369 | contents?.some( |
| 370 | (content) => |
| 371 | content.contentType.split(";")[0]?.trim().toLowerCase() !== "application/octet-stream", |
| 372 | ) === true; |
| 373 | if (acceptsBody) { |
| 374 | properties.body = Option.getOrElse(requestBody.schema, () => ({ type: "object" })); |
| 375 | } |
| 376 | if (acceptsOctetStream) { |
| 377 | properties.bodyBase64 = { |
| 378 | type: "string", |
| 379 | contentEncoding: "base64", |
| 380 | contentMediaType: "application/octet-stream", |
| 381 | description: |
| 382 | "Base64-encoded bytes for application/octet-stream request bodies. When contentType is omitted, this selects application/octet-stream.", |
| 383 | }; |
| 384 | } |
| 385 | if (requestBody.required) { |
| 386 | if (acceptsOctetStream && acceptsBody) { |
| 387 | requiredBodyAlternatives = [{ required: ["body"] }, { required: ["bodyBase64"] }]; |
| 388 | } else { |
| 389 | required.push(acceptsOctetStream ? "bodyBase64" : "body"); |
| 390 | } |
| 391 | } |
no test coverage detected