refactor(api): normalise config snapshots
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
f919e8a3be
commit
5c067b3dae
3 changed files with 38 additions and 3 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
29
spec_builder_helper_internal_test.go
Normal file
29
spec_builder_helper_internal_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue