Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option to disable default open api server #405

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ type OpenAPIConfig struct {
DisableMessages bool
// If true, the engine will not save the OpenAPI JSON spec locally
DisableLocalSave bool
// If true, no default server will be added.
// Note: this option only applies to the fuego [Server]. Adaptors are not affected by this option.
DisableDefaultServer bool
// Pretty prints the OpenAPI spec with proper JSON indentation
PrettyFormatJSON bool
// URL to serve the OpenAPI JSON spec
Expand Down Expand Up @@ -117,6 +120,7 @@ func WithOpenAPIConfig(config OpenAPIConfig) func(*Engine) {

e.OpenAPI.Config.Disabled = config.Disabled
e.OpenAPI.Config.DisableLocalSave = config.DisableLocalSave
e.OpenAPI.Config.DisableDefaultServer = config.DisableDefaultServer
e.OpenAPI.Config.PrettyFormatJSON = config.PrettyFormatJSON
e.OpenAPI.Config.DisableSwaggerUI = config.DisableSwaggerUI

Expand Down
10 changes: 6 additions & 4 deletions serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ func (s *Server) setup() error {
if err := s.setupDefaultListener(); err != nil {
return err
}
s.OpenAPI.Description().Servers = append(s.OpenAPI.Description().Servers, &openapi3.Server{
URL: s.url(),
Description: "local server",
})
if !s.OpenAPI.Config.DisableDefaultServer {
s.OpenAPI.Description().Servers = append(s.OpenAPI.Description().Servers, &openapi3.Server{
URL: s.url(),
Description: "local server",
})
}
go s.OutputOpenAPISpec()
s.Engine.RegisterOpenAPIRoutes(s)
s.printStartupMessage()
Expand Down
14 changes: 8 additions & 6 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ func TestWithOpenAPIConfig(t *testing.T) {
WithEngineOptions(
WithOpenAPIConfig(
OpenAPIConfig{
JSONFilePath: "openapi.json",
DisableLocalSave: true,
PrettyFormatJSON: true,
Disabled: true,
SwaggerURL: "/api",
SpecURL: "/api/openapi.json",
JSONFilePath: "openapi.json",
DisableLocalSave: true,
DisableDefaultServer: true,
PrettyFormatJSON: true,
Disabled: true,
SwaggerURL: "/api",
SpecURL: "/api/openapi.json",
}),
),
)
Expand All @@ -105,6 +106,7 @@ func TestWithOpenAPIConfig(t *testing.T) {
require.Equal(t, "openapi.json", s.OpenAPI.Config.JSONFilePath)
require.True(t, s.Engine.OpenAPI.Config.Disabled)
require.True(t, s.OpenAPI.Config.DisableLocalSave)
require.True(t, s.OpenAPI.Config.DisableDefaultServer)
require.True(t, s.OpenAPI.Config.PrettyFormatJSON)
})

Expand Down