tapir icon indicating copy to clipboard operation
tapir copied to clipboard

[Feature request] cleanup fileBody after successful response

Open sebarys opened this issue 3 years ago • 3 comments

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

sebarys avatar Jun 08 '22 08:06 sebarys

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]

sebarys avatar Jun 08 '22 10:06 sebarys

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?

adamw avatar Jun 15 '22 14:06 adamw

sure @adamw : https://github.com/softwaremill/tapir/issues/2256

sebarys avatar Jun 21 '22 07:06 sebarys