Description
Summary
When a generated Swift OpenAPI client sends an empty string as a text/plain request body, the request crashes at runtime with:
Precondition failed: writePendingBytes(_:) must be called with non-empty bytes
This appears to come from the OpenAPI runtime/URLSession transport path (HTTPBodyOutputStreamBridge).
Actual behavior
App crashes with precondition failure:
writePendingBytes(_:) must be called with non-empty bytes.
Reproduction
OpenAPI snippet
paths:
/items/{itemname}:
post:
operationId: sendItemCommand
parameters:
- name: itemname
in: path
required: true
schema:
type: string
requestBody:
required: true
content:
text/plain:
schema:
type: string
responses:
"200":
description: OK
let path = Operations.sendItemCommand.Input.Path(itemname: "MyItem")
let body = Operations.sendItemCommand.Input.Body.plainText(.init(""))
let query = Operations.sendItemCommand.Input.Query()
_ = try await client.sendItemCommand(path: path, query: query, body: body)
Package version(s)
swift-openapi-runtime: 1.8.0
swift-openapi-urlsession: 1.0.2
Expected behavior
No crash.
Either:
- send a valid request with Content-Length: 0, or
- return a normal thrown error if empty body is unsupported.
Environment
Xcode: 26.3 (17C529)
swift-openapi-runtime: 1.8.0
swift-openapi-urlsession: 1.0.2
Generated by swift-openapi-generator
Additional information
No response
Description
Summary
When a generated Swift OpenAPI client sends an empty string as a
text/plainrequest body, the request crashes at runtime with:Precondition failed: writePendingBytes(_:) must be called with non-empty bytesThis appears to come from the OpenAPI runtime/URLSession transport path (
HTTPBodyOutputStreamBridge).Actual behavior
App crashes with precondition failure:
writePendingBytes(_:) must be called with non-empty bytes.
Reproduction
OpenAPI snippet
Package version(s)
swift-openapi-runtime: 1.8.0
swift-openapi-urlsession: 1.0.2
Expected behavior
No crash.
Either:
Environment
Xcode: 26.3 (17C529)
swift-openapi-runtime: 1.8.0
swift-openapi-urlsession: 1.0.2
Generated by swift-openapi-generator
Additional information
No response