From 252ecfde9da698f859969099ae30d9e9c59cdbe0 Mon Sep 17 00:00:00 2001 From: Peter Broadhurst Date: Wed, 5 Aug 2026 16:25:40 -0400 Subject: [PATCH] Fix swagger serve to have correct max descriptions Signed-off-by: Peter Broadhurst --- pkg/ffapi/apiserver.go | 3 +++ pkg/ffapi/apiserver_test.go | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/pkg/ffapi/apiserver.go b/pkg/ffapi/apiserver.go index 5574f0c..c349cc7 100644 --- a/pkg/ffapi/apiserver.go +++ b/pkg/ffapi/apiserver.go @@ -145,6 +145,9 @@ func NewAPIServer[T any](ctx context.Context, options APIServerOptions[T]) APISe SupportFieldRedaction: options.SupportFieldRedaction, ExportComponentOpts: options.SwaggerExportComponentOpts, AdditionalSchemaCustomizer: options.SwaggerAdditionalSchemaCustomizer, + APIDefaultFilterLimit: options.APIConfig.GetString(ConfAPIDefaultFilterLimit), + APIMaxFilterLimit: options.APIConfig.GetUint(ConfAPIMaxFilterLimit), + APIMaxFilterSkip: options.APIConfig.GetUint(ConfAPIMaxFilterSkip), }, } if as.FavIcon16 == nil { diff --git a/pkg/ffapi/apiserver_test.go b/pkg/ffapi/apiserver_test.go index 22e5ae4..67cd485 100644 --- a/pkg/ffapi/apiserver_test.go +++ b/pkg/ffapi/apiserver_test.go @@ -352,6 +352,29 @@ func TestAPIServerSwaggerJSON(t *testing.T) { assert.Regexp(t, "application/json", res.Header().Get("content-type")) } +func TestAPIServerSwaggerFilterLimitsFromConfig(t *testing.T) { + _, as, done := newTestAPIServer(t, false) + defer done() + + assert.Equal(t, "25", as.baseSwaggerGenOptions.APIDefaultFilterLimit) + assert.Equal(t, uint(100), as.baseSwaggerGenOptions.APIMaxFilterLimit) + assert.Equal(t, uint(100000), as.baseSwaggerGenOptions.APIMaxFilterSkip) + + doc := NewSwaggerGen(&as.baseSwaggerGenOptions).Generate(context.Background(), []*Route{{ + Name: "getThings", + Path: "things", + Method: http.MethodGet, + Description: "list things", + FilterFactory: TestQueryFactory, + JSONOutputValue: func() interface{} { return &sampleOutput{} }, + JSONOutputCodes: []int{http.StatusOK}, + }}) + b, err := json.Marshal(doc) + assert.NoError(t, err) + assert.Contains(t, string(b), "The maximum number of records to return (max: 100)") + assert.Contains(t, string(b), "The number of records to skip (max: 100,000)") +} + func TestAPIServerSwaggerYAML(t *testing.T) { _, as, done := newTestAPIServer(t, true) defer done()