diff --git a/CHANGELOG.md b/CHANGELOG.md index 21cf719eb..10d0c7caa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - #3345, Fix in-database configuration values not loading for `pgrst.server_trace_header` and `pgrst.server_cors_allowed_origins` - @laurenceisla - #3361, Clarify PGRST204(column not found) error message - @steve-chavez - #3373, Remove rejected mediatype `application/vnd.pgrst.object+json` from response - @taimoorzaeem + - #3418, Fix OpenAPI not tagging a FK column correctly on O2O relationships - @laurenceisla ### Deprecated diff --git a/src/PostgREST/Response/OpenAPI.hs b/src/PostgREST/Response/OpenAPI.hs index 0a8933454..8d939cd14 100644 --- a/src/PostgREST/Response/OpenAPI.hs +++ b/src/PostgREST/Response/OpenAPI.hs @@ -115,6 +115,7 @@ makeProperty tbl rels col = (colName col, Inline s) -- Finds the relationship that has a single column foreign key rel = find (\case Relationship{relCardinality=(M2O _ relColumns)} -> [colName col] == (fst <$> relColumns) + Relationship{relCardinality=(O2O _ relColumns)} -> [colName col] == (fst <$> relColumns) _ -> False ) relsSortedByIsView fCol = (headMay . (\r -> snd <$> relColumns (relCardinality r)) =<< rel) diff --git a/test/spec/Feature/OpenApi/OpenApiSpec.hs b/test/spec/Feature/OpenApi/OpenApiSpec.hs index eae5fef3e..0fc29508b 100644 --- a/test/spec/Feature/OpenApi/OpenApiSpec.hs +++ b/test/spec/Feature/OpenApi/OpenApiSpec.hs @@ -222,6 +222,21 @@ spec actualPgVersion = describe "OpenAPI" $ do . nth 0 liftIO $ tableTag `shouldBe` Just [aesonQQ|"authors_only"|] + it "includes a fk description for a O2O relationship" $ do + r <- simpleBody <$> get "/" + + let referralLink = r ^? key "definitions" . key "first" . key "properties" . key "second_id_1" + + liftIO $ + referralLink `shouldBe` Just + [aesonQQ| + { + "format": "integer", + "type": "integer", + "description": "Note:\nThis is a Foreign Key to `second.id`." + } + |] + describe "Foreign table" $ it "includes foreign table properties" $ do