You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a use case that would benefit from this because the raw body can either be encoded as JSON or in binary format.
E.g. something along the lines of:
type Request struct {
RawBody []byte `contentType:"application/octet-stream,application/json`
}
(using a comma-separated list in real life is probably a bad idea, it just used it here for illustrative purposes)
The handler function naturally has to treat the data according to a given request's actual content type. As per usual when using RawBody interpretation of the the data is entirely up the handler.
Is something like this already supported, i.e. am I just too stupid to read the documentation? If not, would it make sense for me to investigate how such a feature could be added - or is that a fool's errand?
PS: I guess you can achieve something similar with multi-part forms where each part is optional, but semantically I find this somewhat janky.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
OpenAPI 3 allows to declare multiple accepted content types for a given endpoint: https://swagger.io/docs/specification/v3_0/describing-request-body/describing-request-body.
I have a use case that would benefit from this because the raw body can either be encoded as JSON or in binary format.
E.g. something along the lines of:
(using a comma-separated list in real life is probably a bad idea, it just used it here for illustrative purposes)
The handler function naturally has to treat the data according to a given request's actual content type. As per usual when using
RawBody
interpretation of the the data is entirely up the handler.Is something like this already supported, i.e. am I just too stupid to read the documentation? If not, would it make sense for me to investigate how such a feature could be added - or is that a fool's errand?
PS: I guess you can achieve something similar with multi-part forms where each part is optional, but semantically I find this somewhat janky.
Beta Was this translation helpful? Give feedback.
All reactions