Skip to content

Commit

Permalink
chore: do not embed OpenAPIServerConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanhitt committed Dec 25, 2024
1 parent bd92d9b commit 84ee2ff
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,26 @@ 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]{
s: s,
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 {
Expand Down
4 changes: 2 additions & 2 deletions openapi_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type Server struct {

startTime time.Time

OpenAPIServerConfig
OpenAPIServerConfig OpenAPIServerConfig

isTLS bool
}
Expand Down
8 changes: 4 additions & 4 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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)
Expand Down

0 comments on commit 84ee2ff

Please sign in to comment.