From 043b1f97eef01f026f7842919f5aa85e8a58a11c Mon Sep 17 00:00:00 2001 From: Laurence Isla Date: Fri, 29 Aug 2025 16:21:32 -0500 Subject: [PATCH] fix: empty enum in 'preferParams' openAPI parameter --- CHANGELOG.md | 1 + src/PostgREST/Response/OpenAPI.hs | 3 ++- test/spec/Feature/OpenApi/OpenApiSpec.hs | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59102f8c2..a83bf4473 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Fix logging the Haskell type instead of the listener error message directly by @laurenceisla in #3588 - Fix format of `IPv6` address logged at PostgREST startup by @taimoorzaeem in #4291 +- Fix empty enum in `preferParams` OpenAPI parameter by @laurenceisla in #4292 ### Changed diff --git a/src/PostgREST/Response/OpenAPI.hs b/src/PostgREST/Response/OpenAPI.hs index 9ca526932..880106a8c 100644 --- a/src/PostgREST/Response/OpenAPI.hs +++ b/src/PostgREST/Response/OpenAPI.hs @@ -171,8 +171,9 @@ makePreferParam ts = & schema .~ ParamOther ((mempty :: ParamOtherSchema) & in_ .~ ParamHeader & type_ ?~ SwaggerString - & enum_ .~ JSON.decode (JSON.encode $ foldl (<>) [] (val <$> ts))) + & enum_ .~ if null enu then Nothing else JSON.decode (JSON.encode enu)) where + enu = foldl (<>) [] (val <$> ts) val :: Text -> [Text] val = \case "count" -> ["count=none"] diff --git a/test/spec/Feature/OpenApi/OpenApiSpec.hs b/test/spec/Feature/OpenApi/OpenApiSpec.hs index c035bbe7b..f9d26fafe 100644 --- a/test/spec/Feature/OpenApi/OpenApiSpec.hs +++ b/test/spec/Feature/OpenApi/OpenApiSpec.hs @@ -1085,6 +1085,13 @@ spec = describe "OpenAPI" $ do immutableGet `shouldNotBe` Nothing immutablePost `shouldNotBe` Nothing + it "does not include empty enum in the preferParams parameter" $ do + r <- simpleBody <$> get "/" + let preferParams = r ^? key "parameters" . key "preferParams" . key "enum" + + liftIO $ do + preferParams `shouldBe` Nothing + describe "Security" $ it "does not include security or security definitions by default" $ do r <- simpleBody <$> get "/"