feat(openapi): export configured transport paths
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
9b24a46fd5
commit
fe256147e6
2 changed files with 50 additions and 2 deletions
|
|
@ -41,10 +41,10 @@ func (e *Engine) OpenAPISpecBuilder() *SpecBuilder {
|
|||
builder.GraphQLPath = e.graphql.path
|
||||
builder.GraphQLPlayground = e.graphql.playground
|
||||
}
|
||||
if e.wsHandler != nil {
|
||||
if e.wsHandler != nil || strings.TrimSpace(e.wsPath) != "" {
|
||||
builder.WSPath = resolveWSPath(e.wsPath)
|
||||
}
|
||||
if e.sseBroker != nil {
|
||||
if e.sseBroker != nil || strings.TrimSpace(e.ssePath) != "" {
|
||||
builder.SSEPath = resolveSSEPath(e.ssePath)
|
||||
}
|
||||
builder.PprofEnabled = e.pprofEnabled
|
||||
|
|
|
|||
|
|
@ -196,3 +196,51 @@ func TestEngine_Good_OpenAPISpecBuilderCarriesExplicitSwaggerPathWithoutUI(t *te
|
|||
t.Fatalf("expected explicit x-swagger-ui-path=/docs, got %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEngine_Good_OpenAPISpecBuilderCarriesConfiguredWSPathWithoutHandler(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
|
||||
e, err := api.New(api.WithWSPath("/socket"))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
builder := e.OpenAPISpecBuilder()
|
||||
data, err := builder.Build(nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
var spec map[string]any
|
||||
if err := json.Unmarshal(data, &spec); err != nil {
|
||||
t.Fatalf("invalid JSON: %v", err)
|
||||
}
|
||||
|
||||
if got := spec["x-ws-path"]; got != "/socket" {
|
||||
t.Fatalf("expected x-ws-path=/socket, got %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEngine_Good_OpenAPISpecBuilderCarriesConfiguredSSEPathWithoutBroker(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
|
||||
e, err := api.New(api.WithSSE(nil), api.WithSSEPath("/events"))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
builder := e.OpenAPISpecBuilder()
|
||||
data, err := builder.Build(nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
var spec map[string]any
|
||||
if err := json.Unmarshal(data, &spec); err != nil {
|
||||
t.Fatalf("invalid JSON: %v", err)
|
||||
}
|
||||
|
||||
if got := spec["x-sse-path"]; got != "/events" {
|
||||
t.Fatalf("expected x-sse-path=/events, got %v", got)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue