File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ library
5757 , containers
5858 , http-media
5959 , http-types
60+ , lens
6061 , mtl
6162 , singletons
6263 , swagger2
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE DataKinds #-}
2+ {-# LANGUAGE RankNTypes #-}
3+ {-# LANGUAGE GADTs #-}
4+ {-# LANGUAGE KindSignatures #-}
5+ {-# LANGUAGE ScopedTypeVariables #-}
16
27-- | Convert Serv Apis to Swagger definitions
38module Serv.Swagger where
49
5- import Data.Swagger
10+ import Control.Lens
11+ import Data.Monoid
12+ import Data.Singletons
13+ import Data.Singletons.Prelude.List
14+ import Data.Singletons.TypeLits
15+ import Data.Swagger
16+ import Serv.Internal.Api
17+ import Serv.Internal.StatusCode
18+ import Serv.Internal.Verb
19+
20+ opOfVerb :: forall (v :: Verb ) . Sing v -> Lens' PathItem (Maybe Operation )
21+ opOfVerb v =
22+ case v of
23+ SGET -> pathItemGet
24+ SDELETE -> pathItemDelete
25+ SHEAD -> pathItemHead
26+ SOPTIONS -> pathItemOptions
27+ SPATCH -> pathItemPatch
28+ SPOST -> pathItemPost
29+ SPUT -> pathItemPut
30+
31+ pathItem :: forall (v :: Verb ) . Sing v -> Operation -> PathItem
32+ pathItem v op = mempty & opOfVerb v .~ Just op
33+
34+ -- swResponses :: forall (rs :: [ (StatusCode Nat, Output Symbol *) ]) . Sing rs -> Responses
35+ -- swResponses rs = mempty & responsesResponses .~ makeRs rs where
36+ -- makeRs SNil = mempty
37+ -- makeRs (SCons (STuple2 code out) rest) = rest & ix
38+
39+ swHandler :: forall (h :: Handler Nat Symbol * ) . Sing h -> PathItem
40+ swHandler h =
41+ case h of
42+ SMethod verb responses ->
43+ let resps =
44+ mempty
45+ & ix 200 .~ Inline mempty
46+ op =
47+ mempty
48+ & (operationResponses . responsesResponses) .~ resps
49+ in pathItem verb op
You can’t perform that action at this time.
0 commit comments