Skip to content

Commit

Permalink
fix: OpenAPI now tags a FK correctly on O2O relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenceisla authored and steve-chavez committed Apr 18, 2024
1 parent 1bf0c54 commit 0d13b84
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/PostgREST/Response/OpenAPI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions test/spec/Feature/OpenApi/OpenApiSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.<fk table='second' column='id'/>"
}
|]

describe "Foreign table" $

it "includes foreign table properties" $ do
Expand Down

0 comments on commit 0d13b84

Please sign in to comment.