Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 66c9dcf

Browse files
committed
handler: swagger the whole API
1 parent b3d0b32 commit 66c9dcf

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

infra/firebase-login/package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies:
1818
- servant
1919
- servant-client-core
2020
- servant-server
21+
- servant-swagger
2122
- text
2223
- unordered-containers
2324
- wai

infra/firebase-login/src/Servant/Auth/Firebase.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Control.Monad.Except
1717
import Data.Proxy
1818
import Data.Word8 (isSpace, toLower)
1919
import Servant.API
20+
import qualified Servant.Swagger as Servant
2021
import qualified Crypto.JOSE.JWK as JWK
2122
import qualified Network.URI as URI
2223
import qualified Crypto.JWT as JWT
@@ -154,3 +155,6 @@ instance
154155

155156
hoistServerWithContext Proxy p hoist s = \uid ->
156157
Servant.hoistServerWithContext (Proxy :: Proxy sub) p hoist (s uid)
158+
159+
instance Servant.HasSwagger sub => Servant.HasSwagger (Protected :> sub) where
160+
toSwagger Proxy = Servant.toSwagger (Proxy :: Proxy sub)

infra/handler/app/Swagger.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ swagger :: Swagger.Swagger
2626
swagger = Servant.toSwagger (Proxy :: Proxy DeckGo.Handler.SlidesAPI)
2727

2828
dumpSwagger :: FilePath -> IO ()
29-
dumpSwagger out = Servant.swaggerSchemaUiDump out swaggerApi (Proxy :: Proxy DeckGo.Handler.SlidesAPI)
29+
dumpSwagger out = Servant.swaggerSchemaUiDump out swaggerApi DeckGo.Handler.api
3030

3131
serveSwagger :: IO ()
3232
serveSwagger =

infra/handler/src/DeckGo/Handler.hs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
module DeckGo.Handler where
1818

1919
-- TODO: double check what is returned on 200 from DynamoDB
20+
-- TODO: check user is in DB
21+
-- TODO: check permissions
22+
-- TODO: created_at, updated_at
23+
-- TODO: TTL on anonymous users
2024

2125
import Control.Lens hiding ((.=))
2226
import Control.Monad
@@ -119,7 +123,7 @@ instance FromJSONObject User where
119123
User
120124
-- potentially return "error exists" + user object
121125
<$> obj .: "firebase_uid"
122-
<*> obj .: "anonymous" -- TODO: TTL
126+
<*> obj .: "anonymous"
123127

124128
instance ToJSONObject User where
125129
toJSONObject user = HMS.fromList
@@ -131,9 +135,19 @@ instance Aeson.FromJSON User where
131135
parseJSON = Aeson.withObject "User" parseJSONObject
132136
instance Aeson.ToJSON User where
133137
toJSON = Aeson.Object . toJSONObject
134-
-- TODO: check user is in DB
135-
-- TODO: check permissions
136-
-- TODO: created_at, updated_at
138+
139+
140+
instance ToSchema (Item UserId User) where
141+
declareNamedSchema _ = pure $ NamedSchema (Just "UserWithId") mempty
142+
143+
instance ToSchema User where
144+
declareNamedSchema _ = pure $ NamedSchema (Just "User") mempty
145+
146+
instance ToParamSchema (Item UserId User) where
147+
toParamSchema _ = mempty
148+
149+
instance ToParamSchema UserId where
150+
toParamSchema _ = mempty
137151

138152
-- DECKS
139153

@@ -180,6 +194,18 @@ instance Aeson.FromJSON Deck where
180194
instance Aeson.ToJSON Deck where
181195
toJSON = Aeson.Object . toJSONObject
182196

197+
instance ToSchema (Item DeckId Deck) where
198+
declareNamedSchema _ = pure $ NamedSchema (Just "DeckWithId") mempty
199+
200+
instance ToSchema Deck where
201+
declareNamedSchema _ = pure $ NamedSchema (Just "Deck") mempty
202+
203+
instance ToParamSchema (Item DeckId Deck) where
204+
toParamSchema _ = mempty
205+
206+
instance ToParamSchema DeckId where
207+
toParamSchema _ = mempty
208+
183209
-- SLIDES
184210

185211
type SlidesAPI =

0 commit comments

Comments
 (0)