refactor(api): normalise config snapshots

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 12:38:54 +00:00
parent f919e8a3be
commit 5c067b3dae
3 changed files with 38 additions and 3 deletions

View file

@ -5,6 +5,7 @@ package api
import (
"reflect"
"slices"
"strings"
)
// SwaggerConfig captures the configured Swagger/OpenAPI metadata for an Engine.
@ -104,9 +105,8 @@ func (e *Engine) SwaggerConfig() SwaggerConfig {
return SwaggerConfig{}
}
return SwaggerConfig{
cfg := SwaggerConfig{
Enabled: e.swaggerEnabled,
Path: e.swaggerPath,
Title: e.swaggerTitle,
Summary: e.swaggerSummary,
Description: e.swaggerDesc,
@ -122,6 +122,12 @@ func (e *Engine) SwaggerConfig() SwaggerConfig {
ExternalDocsDescription: e.swaggerExternalDocsDescription,
ExternalDocsURL: e.swaggerExternalDocsURL,
}
if strings.TrimSpace(e.swaggerPath) != "" {
cfg.Path = normaliseSwaggerPath(e.swaggerPath)
}
return cfg
}
func cloneSecuritySchemes(schemes map[string]any) map[string]any {

View file

@ -0,0 +1,29 @@
// SPDX-License-Identifier: EUPL-1.2
package api
import "testing"
func TestEngine_SwaggerConfig_Good_NormalisesPathAtSnapshot(t *testing.T) {
e := &Engine{
swaggerPath: " /docs/ ",
}
cfg := e.SwaggerConfig()
if cfg.Path != "/docs" {
t.Fatalf("expected normalised Swagger path /docs, got %q", cfg.Path)
}
}
func TestEngine_TransportConfig_Good_NormalisesGraphQLPathAtSnapshot(t *testing.T) {
e := &Engine{
graphql: &graphqlConfig{
path: " /gql/ ",
},
}
cfg := e.TransportConfig()
if cfg.GraphQLPath != "/gql" {
t.Fatalf("expected normalised GraphQL path /gql, got %q", cfg.GraphQLPath)
}
}

View file

@ -53,7 +53,7 @@ func (e *Engine) TransportConfig() TransportConfig {
cfg.SwaggerPath = resolveSwaggerPath(e.swaggerPath)
}
if e.graphql != nil {
cfg.GraphQLPath = e.graphql.path
cfg.GraphQLPath = normaliseGraphQLPath(e.graphql.path)
}
if e.wsHandler != nil || strings.TrimSpace(e.wsPath) != "" {
cfg.WSPath = resolveWSPath(e.wsPath)