softwaremill / tapir

Rapid development of self-documenting APIs
https://tapir.softwaremill.com
Apache License 2.0
1.36k stars 411 forks source link

[Feature request] cleanup fileBody after successful response #2182

Open sebarys opened 2 years ago

sebarys commented 2 years ago

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:

More context in this gitter thread: https://gitter.im/softwaremill/tapir?at=629dc6c4c61b987d33e59c2e

sebarys commented 2 years ago

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]
adamw commented 2 years ago

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?

sebarys commented 2 years ago

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