wI2L / fizz

:lemon: Gin wrapper with OpenAPI 3 spec generation
https://pkg.go.dev/github.com/wI2L/fizz
MIT License
214 stars 52 forks source link

How to specify the return type for an API that writes to the output directly via stream #81

Open dtyree-spyderbat opened 2 years ago

dtyree-spyderbat commented 2 years ago

Hi,

We're returning a large ndjson stream on some calls, and the problem we have is that we can't figure out how to get fizz go generate an openapi spec that indicates that ndjson is returned as the output, so instead the spec indicates nothing is returned.

We're essentially writing x-ndjson directly to the Writer on the context.

We tried using a fizz.Response(200...) but we can't override that.

sberryman commented 2 years ago

I ran into this problem today and it doesn't look possible with tonic.

https://github.com/loopfz/gadgeto/blob/ecd126f80b95fae7372be52e0e0f119d4e46f5d2/tonic/handler.go#L37-L65 The options function appears useless because the tonic.Route struct is mostly private.

wI2L commented 2 years ago

The media type of the operations' response is defined by the media type that Tonic uses to encode responses, and it is limited to json and xml.

It think we should allow to override the media type per operation for the response using a fizz.Option, when the route is declared.

Does any one of you wish to send a PR ? Otherwise I'll look into it when I have the time.

mcorbin commented 2 years ago

Does any one of you wish to send a PR ? Otherwise I'll look into it when I have the time.

I did it in https://github.com/loopfz/gadgeto/pull/87 a while ago on Tonic, and https://github.com/mcorbin/fizz/commit/1b8b7d7d09bce0d18be37fe4156e888ae8c612aa on Fizz to generate the proper OpenAPI doc based on routes media types.

wI2L commented 2 years ago

@mcorbin Reviewed the PR on tonic, waiting for another approval/check. Once its ok, send the PR on fizz to close this issue, and I'll review it.

mcorbin commented 2 years ago

Thank you @wI2L . There is a lot of interesting MR on Tonic which should be interesting to merge (for now I forked both repositories and merged everything on my side). Do you know what is Tonic status regarding maintenance ?