Skip to content

Commit

Permalink
Specify content type
Browse files Browse the repository at this point in the history
  • Loading branch information
tdeebswihart committed Mar 6, 2024
1 parent f4d6d26 commit ace6a6a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions service/frontend/openapi_http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (h *OpenAPIHTTPHandler) RegisterRoutes(r *mux.Router) {
return
}

serve := func(version int, apiName string, spec []byte) func(http.ResponseWriter, *http.Request) {
serve := func(version int, apiName string, contentType string, spec []byte) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if err := h.rateLimitInterceptor.Allow(apiName, r.Header); err != nil {
w.WriteHeader(http.StatusTooManyRequests)
Expand All @@ -82,6 +82,16 @@ func (h *OpenAPIHTTPHandler) RegisterRoutes(r *mux.Router) {
}
}

r.PathPrefix("/api/v1/swagger.json").Methods("GET").HandlerFunc(serve(2, configs.OpenAPIV2APIName, openapi.OpenAPIV2JSONSpec))
r.PathPrefix("/api/v1/openapi.yaml").Methods("GET").HandlerFunc(serve(3, configs.OpenAPIV3APIName, openapi.OpenAPIV3YAMLSpec))
r.PathPrefix("/api/v1/swagger.json").Methods("GET").HandlerFunc(serve(
2,
configs.OpenAPIV2APIName,
"application/vnd.oai.openapi+json;version=2.0",
openapi.OpenAPIV2JSONSpec,
))
r.PathPrefix("/api/v1/openapi.yaml").Methods("GET").HandlerFunc(serve(
3,
configs.OpenAPIV3APIName,
"application/vnd.oai.openapi;version=3.0",
openapi.OpenAPIV3YAMLSpec,
))
}

0 comments on commit ace6a6a

Please sign in to comment.