[openapi] Allow multiple mime-types on single route

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-10-22 22:27:03 +02:00
parent 96140670a7
commit 411756fa45
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
2 changed files with 8 additions and 0 deletions

View file

@ -11,6 +11,7 @@ type (
}
HTTPRouteRegistrationArgs struct {
Accept []string
Description string
HandlerFunc http.HandlerFunc
IsPrefix bool
@ -34,4 +35,5 @@ const (
HTTPRouteResponseTypeNo200 HTTPRouteResponseType = iota
HTTPRouteResponseTypeTextPlain
HTTPRouteResponseTypeJSON
HTTPRouteResponseTypeMultiple
)

View file

@ -100,6 +100,12 @@ func registerSwaggerRoute(route plugins.HTTPRouteRegistrationArgs) error {
case plugins.HTTPRouteResponseTypeJSON:
op.Responses["200"] = spec.JSONResponse(nil).WithDescription("Successful execution with JSON object response")
case plugins.HTTPRouteResponseTypeMultiple:
op.Responses["200"] = (&spec.Response{}).WithDescription("Successful execution with variable response based on Accept header")
for _, a := range route.Accept {
op.Responses["200"].AddContent(a, &spec.MediaType{Schema: nil})
}
case plugins.HTTPRouteResponseTypeNo200:
// We don't add a 200 then