Skip to content
Open
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
3 changes: 3 additions & 0 deletions pkg/ffapi/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions pkg/ffapi/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down