[Feature request] cleanup fileBody after successful response
Hi :)
Like we discussed on Tapir gitter it would be desirable for some use cases to have a way to cleanup/remove file provided as response body to an endpoint that declare out as fileBody, e.g. export endpoint that create temporary file that is no longer needed after an endpoint returned response.
Currently the only way that I managed to implement e2e is either:
- returning stream that will cleanup file on finish https://github.com/softwaremill/adopt-tapir/blob/main/backend/src/main/scala/com/softwaremill/adopttapir/starter/api/StarterApi.scala#L46
- convert file to byteStream and remove it in an endpoint logic explicitly
.out(byteBufferBody and header("Content-Type", "text/csv"))
More context in this gitter thread: https://gitter.im/softwaremill/tapir?at=629dc6c4c61b987d33e59c2e
Other finding:
for byteBufferBody when I provided example value
.out(
byteBufferBody.example(Example.of(ByteBuffer.wrap(SampleExportContent.getBytes)))
and header("Content-Type", "text/csv")
)
generated openapi example is java.nio.HeapByteBuffer[pos=0 lim=2018 cap=2018], not provided, stringified value
responses:
'200':
description: ''
headers:
Content-Type:
required: true
schema:
type: string
content:
text/csv:
schema:
type: string
format: binary
example: java.nio.HeapByteBuffer[pos=0 lim=2018 cap=2018]
for byteBufferBody when I provided example value
This should be a separate issue - can you open one? Also, what would you expect to be visible in the example section?
sure @adamw : https://github.com/softwaremill/tapir/issues/2256