generated from coulomb/repo-seed
Make hub discovery public
All checks were successful
Build and Deploy / build-push-deploy (push) Successful in 3m6s
All checks were successful
Build and Deploy / build-push-deploy (push) Successful in 3m6s
This commit is contained in:
@@ -27,7 +27,6 @@ instance Controller ApiV2HubsController where
|
||||
|
||||
listHubs :: (?context :: ControllerContext, ?modelContext :: ModelContext, ?respond :: Respond, ?request :: Request) => IO ()
|
||||
listHubs = do
|
||||
_consumer <- requireApiConsumer
|
||||
(page, perPage) <- getPageParams
|
||||
let pageOffset = (page - 1) * perPage
|
||||
total <- query @Hub |> fetchCount
|
||||
|
||||
@@ -136,7 +136,7 @@ buildOpenApiSpec = do
|
||||
buildPaths :: Value
|
||||
buildPaths = object
|
||||
[ "/hubs" .= object
|
||||
[ "get" .= listOp "Hub" []
|
||||
[ "get" .= publicPaginatedListOp "Hub" []
|
||||
, "post" .= writeOp "Hub" "CreateHubRequest"
|
||||
]
|
||||
, "/hubs/{id}" .= getShowPath "Hub"
|
||||
@@ -268,6 +268,37 @@ listOp schemaName extraParams = object
|
||||
, "schema" .= object (["type" .= typ] ++ if fmt /= "" then [("format", A.String fmt)] else [])
|
||||
]
|
||||
|
||||
publicPaginatedListOp :: Text -> [(Text, Text, Text)] -> Value
|
||||
publicPaginatedListOp schemaName extraParams = object
|
||||
[ "summary" .= ("List " <> schemaName)
|
||||
, "security" .= ([] :: [Value])
|
||||
, "parameters" .= (pageParams ++ map toParam extraParams)
|
||||
, "responses" .= object
|
||||
[ "200" .= object
|
||||
[ "description" .= ("OK" :: Text)
|
||||
, "content" .= object
|
||||
[ "application/json" .= object
|
||||
[ "schema" .= object
|
||||
[ "type" .= ("object" :: Text)
|
||||
, "properties" .= object
|
||||
[ "data" .= object
|
||||
[ "type" .= ("array" :: Text)
|
||||
, "items" .= object ["$ref" .= ("#/components/schemas/" <> schemaName)]
|
||||
]
|
||||
, "meta" .= object ["$ref" .= ("#/components/schemas/PaginationMeta" :: Text)]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
where
|
||||
toParam (name, typ, fmt) = object $
|
||||
[ "name" .= name, "in" .= ("query" :: Text)
|
||||
, "schema" .= object (["type" .= typ] ++ if fmt /= "" then [("format", A.String fmt)] else [])
|
||||
]
|
||||
|
||||
showOp :: Text -> Value
|
||||
showOp schemaName = showOpWithParam schemaName "id"
|
||||
|
||||
@@ -356,6 +387,7 @@ publicListPath :: Text -> Value
|
||||
publicListPath schemaName = object
|
||||
[ "get" .= object
|
||||
[ "summary" .= ("List registered " <> schemaName <> " values" :: Text)
|
||||
, "security" .= ([] :: [Value])
|
||||
, "responses" .= object
|
||||
[ "200" .= object ["description" .= ("OK" :: Text)] ]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user