apple / swift-openapi-generator

Generate Swift client and server code from an OpenAPI document.
https://swiftpackageindex.com/apple/swift-openapi-generator/documentation
Apache License 2.0
1.21k stars 87 forks source link

Logging and HTTPBody #566

Closed IanKeen closed 3 weeks ago

IanKeen commented 4 weeks ago

Question

Has anyone successfully found a way to log the request/response from the generated client code? It appears as though ClientMiddleware only allows a hook into requests not responses. I also attempted to create a custom ClientTransport but logging the HTTPBody causes everything to fail as you can only iterate the bytes once (a second pass throws an error)

czechboy0 commented 4 weeks ago

Hi @IanKeen, have you seen the two logging-middleware-* examples here? https://github.com/apple/swift-openapi-generator/tree/main/Examples

simonjbeaumont commented 4 weeks ago

@IanKeen The examples @czechboy0 links so show how you can log the body, which is an AsyncSequence, so requires you to map over it and produce a new sequence.

Please let us know if that works for you.

IanKeen commented 3 weeks ago

@czechboy0 / @simonjbeaumont thank ya'll!

I hadn't see those examples, I got it up and running. I appreciate the help 🙌