fix: FK pointing to VIEW instead of TABLE in OpenAPI output
This commit is contained in:
committed by
Steve Chavez
parent
12c1d4a8e4
commit
81501aefa0
@@ -103,11 +103,14 @@ makeProperty tbl rels col = (colName col, Inline s)
|
|||||||
fk :: Maybe Text
|
fk :: Maybe Text
|
||||||
fk =
|
fk =
|
||||||
let
|
let
|
||||||
|
searchedRels = fromMaybe mempty $ HM.lookup (QualifiedIdentifier (tableSchema tbl) (tableName tbl), tableSchema tbl) rels
|
||||||
|
-- Sorts the relationship list to get tables first
|
||||||
|
relsSortedByIsView = sortOn relFTableIsView [ r | r@Relationship{} <- searchedRels]
|
||||||
-- Finds the relationship that has a single column foreign key
|
-- Finds the relationship that has a single column foreign key
|
||||||
rel = find (\case
|
rel = find (\case
|
||||||
Relationship{relCardinality=(M2O _ relColumns)} -> [colName col] == (fst <$> relColumns)
|
Relationship{relCardinality=(M2O _ relColumns)} -> [colName col] == (fst <$> relColumns)
|
||||||
_ -> False
|
_ -> False
|
||||||
) $ fromMaybe mempty $ HM.lookup (QualifiedIdentifier (tableSchema tbl) (tableName tbl), tableSchema tbl) rels
|
) relsSortedByIsView
|
||||||
fCol = (headMay . (\r -> snd <$> relColumns (relCardinality r)) =<< rel)
|
fCol = (headMay . (\r -> snd <$> relColumns (relCardinality r)) =<< rel)
|
||||||
fTbl = qiName . relForeignTable <$> rel
|
fTbl = qiName . relForeignTable <$> rel
|
||||||
fTblCol = (,) <$> fTbl <*> fCol
|
fTblCol = (,) <$> fTbl <*> fCol
|
||||||
|
|||||||
@@ -310,6 +310,23 @@ spec actualPgVersion = describe "OpenAPI" $ do
|
|||||||
}
|
}
|
||||||
|]
|
|]
|
||||||
|
|
||||||
|
describe "VIEW created for a TABLE with a O2M relationship" $ do
|
||||||
|
|
||||||
|
it "fk points to destination TABLE instead of the VIEW" $ do
|
||||||
|
r <- simpleBody <$> get "/"
|
||||||
|
|
||||||
|
let referralLink = r ^? key "definitions" . key "projects" . key "properties" . key "client_id"
|
||||||
|
|
||||||
|
liftIO $
|
||||||
|
referralLink `shouldBe` Just
|
||||||
|
[aesonQQ|
|
||||||
|
{
|
||||||
|
"format": "integer",
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Note:\nThis is a Foreign Key to `clients.id`.<fk table='clients' column='id'/>"
|
||||||
|
}
|
||||||
|
|]
|
||||||
|
|
||||||
describe "PostgreSQL to Swagger Type Mapping" $ do
|
describe "PostgreSQL to Swagger Type Mapping" $ do
|
||||||
|
|
||||||
it "character varying to string" $ do
|
it "character varying to string" $ do
|
||||||
|
|||||||
Vendored
+10
@@ -3076,3 +3076,13 @@ LANGUAGE sql
|
|||||||
AS $$
|
AS $$
|
||||||
select * from test.yards;
|
select * from test.yards;
|
||||||
$$;
|
$$;
|
||||||
|
|
||||||
|
-- view's name is alphabetically before projects
|
||||||
|
create view test.alpha_projects as
|
||||||
|
select c.id, p.name as pro_name, c.name as cli_name
|
||||||
|
from projects p join clients c on p.client_id = c.id;
|
||||||
|
|
||||||
|
-- view's name is alphabetically after projects
|
||||||
|
create view test.zeta_projects as
|
||||||
|
select c.id, p.name as pro_name, c.name as cli_name
|
||||||
|
from projects p join clients c on p.client_id = c.id;
|
||||||
Reference in New Issue
Block a user