From 84ee2ff566fa8faa148e8ff10196956c0afc109b Mon Sep 17 00:00:00 2001 From: dylanhitt Date: Wed, 25 Dec 2024 18:58:48 -0500 Subject: [PATCH] chore: do not embed OpenAPIServerConfig --- openapi.go | 12 ++++++------ openapi_handler_test.go | 4 ++-- server.go | 2 +- server_test.go | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/openapi.go b/openapi.go index fc42071c..3d3b9f1c 100644 --- a/openapi.go +++ b/openapi.go @@ -116,13 +116,13 @@ func (s *Server) OutputOpenAPISpec() openapi3.T { // Registers the routes to serve the OpenAPI spec and Swagger UI. func (s *Server) registerOpenAPIRoutes(jsonSpec []byte) { - GetStd(s, s.SpecURL, func(w http.ResponseWriter, r *http.Request) { + GetStd(s, s.OpenAPIServerConfig.SpecURL, func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") _, _ = w.Write(jsonSpec) }) - s.printOpenAPIMessage(fmt.Sprintf("JSON spec: %s%s", s.url(), s.SpecURL)) + s.printOpenAPIMessage(fmt.Sprintf("JSON spec: %s%s", s.url(), s.OpenAPIServerConfig.SpecURL)) - if s.DisableSwaggerUI { + if s.OpenAPIServerConfig.DisableSwaggerUI { return } Registers(s.Engine, netHttpRouteRegisterer[any, any]{ @@ -130,12 +130,12 @@ func (s *Server) registerOpenAPIRoutes(jsonSpec []byte) { route: Route[any, any]{ BaseRoute: BaseRoute{ Method: http.MethodGet, - Path: s.SwaggerURL + "/", + Path: s.OpenAPIServerConfig.SwaggerURL + "/", }, }, - controller: s.UIHandler(s.SpecURL), + controller: s.OpenAPIServerConfig.UIHandler(s.OpenAPIServerConfig.SpecURL), }) - s.printOpenAPIMessage(fmt.Sprintf("OpenAPI UI: %s%s/index.html", s.url(), s.SwaggerURL)) + s.printOpenAPIMessage(fmt.Sprintf("OpenAPI UI: %s%s/index.html", s.url(), s.OpenAPIServerConfig.SwaggerURL)) } func validateSpecURL(specURL string) bool { diff --git a/openapi_handler_test.go b/openapi_handler_test.go index 3764d6e7..2e3e6323 100644 --- a/openapi_handler_test.go +++ b/openapi_handler_test.go @@ -23,7 +23,7 @@ func TestUIHandler(t *testing.T) { s.OutputOpenAPISpec() - require.NotNil(t, s.UIHandler) + require.NotNil(t, s.OpenAPIServerConfig.UIHandler) w := httptest.NewRecorder() r := httptest.NewRequest("GET", "/swagger/index.html", nil) @@ -45,7 +45,7 @@ func TestUIHandler(t *testing.T) { ) s.OutputOpenAPISpec() - require.NotNil(t, s.UIHandler) + require.NotNil(t, s.OpenAPIServerConfig.UIHandler) w := httptest.NewRecorder() r := httptest.NewRequest("GET", "/swagger/index.html", nil) diff --git a/server.go b/server.go index fc46dfef..9479b957 100644 --- a/server.go +++ b/server.go @@ -74,7 +74,7 @@ type Server struct { startTime time.Time - OpenAPIServerConfig + OpenAPIServerConfig OpenAPIServerConfig isTLS bool } diff --git a/server_test.go b/server_test.go index ff27215b..91141ea8 100644 --- a/server_test.go +++ b/server_test.go @@ -74,8 +74,8 @@ func TestWithOpenAPIConfig(t *testing.T) { WithOpenAPIServerConfig(OpenAPIServerConfig{}), ) - require.Equal(t, "/swagger", s.SwaggerURL) - require.Equal(t, "/swagger/openapi.json", s.SpecURL) + require.Equal(t, "/swagger", s.OpenAPIServerConfig.SwaggerURL) + require.Equal(t, "/swagger/openapi.json", s.OpenAPIServerConfig.SpecURL) require.Equal(t, "doc/openapi.json", s.OpenAPIConfig.JSONFilePath) require.False(t, s.OpenAPIConfig.PrettyFormatJSON) }) @@ -96,8 +96,8 @@ func TestWithOpenAPIConfig(t *testing.T) { ), ) - require.Equal(t, "/api", s.SwaggerURL) - require.Equal(t, "/api/openapi.json", s.SpecURL) + require.Equal(t, "/api", s.OpenAPIServerConfig.SwaggerURL) + require.Equal(t, "/api/openapi.json", s.OpenAPIServerConfig.SpecURL) require.Equal(t, "openapi.json", s.OpenAPIConfig.JSONFilePath) require.True(t, s.Engine.OpenAPIConfig.Disabled) require.True(t, s.OpenAPIConfig.DisableLocalSave)