{-# LANGUAGE CPP #-}
module WebGear.OpenApi.Handler (
OpenApiHandler (..),
DocNode (..),
Tree,
singletonNode,
nullNode,
toOpenApi,
) where
import Control.Applicative ((<|>))
import Control.Arrow (Arrow (..), ArrowChoice (..), ArrowPlus (..), ArrowZero (..))
import Control.Arrow.Operations (ArrowError (..))
import qualified Control.Category as Cat
import Control.Lens (at, (%~), (&), (.~), (<>~), (?~))
import qualified Data.HashMap.Strict.InsOrd as Map
import Data.OpenApi
import Data.OpenApi.Internal.Utils (swaggerMappend)
import Data.Text (Text)
import qualified Data.Text as Text
import Network.HTTP.Media.MediaType (MediaType)
import qualified Network.HTTP.Types as HTTP
import WebGear.Core.Handler (Description (..), Handler (..), RouteMismatch, RoutePath (..), Summary (..))
data Tree a
= NullNode
| SingleNode a (Tree a)
| BinaryNode (Tree a) (Tree a)
deriving stock (Int -> Tree a -> ShowS
[Tree a] -> ShowS
Tree a -> String
(Int -> Tree a -> ShowS)
-> (Tree a -> String) -> ([Tree a] -> ShowS) -> Show (Tree a)
forall a. Show a => Int -> Tree a -> ShowS
forall a. Show a => [Tree a] -> ShowS
forall a. Show a => Tree a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Tree a] -> ShowS
$cshowList :: forall a. Show a => [Tree a] -> ShowS
show :: Tree a -> String
$cshow :: forall a. Show a => Tree a -> String
showsPrec :: Int -> Tree a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Tree a -> ShowS
Show)
data DocNode
= DocSecurityScheme Text SecurityScheme
| DocRequestBody (Definitions Schema) RequestBody
| DocResponseBody (Definitions Schema) MediaType MediaTypeObject
| Param
| HeaderName Header
| DocMethod HTTP.StdMethod
| DocPathElem Text
| DocPathVar Param
| DocQueryParam Param
| DocStatus HTTP.Status
| DocSummary Summary
| DocDescription Description
deriving stock (Int -> DocNode -> ShowS
[DocNode] -> ShowS
DocNode -> String
(Int -> DocNode -> ShowS)
-> (DocNode -> String) -> ([DocNode] -> ShowS) -> Show DocNode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DocNode] -> ShowS
$cshowList :: [DocNode] -> ShowS
show :: DocNode -> String
$cshow :: DocNode -> String
showsPrec :: Int -> DocNode -> ShowS
$cshowsPrec :: Int -> DocNode -> ShowS
Show)
data CompactDocNode
= CDocSecurityScheme Text SecurityScheme
| CDocRequestBody (Definitions Schema) RequestBody
| CDocResponseBody (Definitions Schema) MediaType MediaTypeObject
| Param
| HeaderName Header
| CDocMethod HTTP.StdMethod
| CDocPathElem Text
| CDocPathVar Param
| CDocRouteDoc (Maybe Summary) (Maybe Description)
| CDocQueryParam Param
| CDocStatus HTTP.Status (Maybe Description)
deriving stock (Int -> CompactDocNode -> ShowS
[CompactDocNode] -> ShowS
CompactDocNode -> String
(Int -> CompactDocNode -> ShowS)
-> (CompactDocNode -> String)
-> ([CompactDocNode] -> ShowS)
-> Show CompactDocNode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CompactDocNode] -> ShowS
$cshowList :: [CompactDocNode] -> ShowS
show :: CompactDocNode -> String
$cshow :: CompactDocNode -> String
showsPrec :: Int -> CompactDocNode -> ShowS
$cshowsPrec :: Int -> CompactDocNode -> ShowS
Show)
singletonNode :: a -> Tree a
singletonNode :: a -> Tree a
singletonNode a
a = a -> Tree a -> Tree a
forall a. a -> Tree a -> Tree a
SingleNode a
a Tree a
forall a. Tree a
NullNode
nullNode :: Tree a
nullNode :: Tree a
nullNode = Tree a
forall a. Tree a
NullNode
newtype OpenApiHandler m a b = OpenApiHandler
{OpenApiHandler m a b -> Tree DocNode
openApiDoc :: Tree DocNode}
instance Cat.Category (OpenApiHandler m) where
id :: OpenApiHandler m a a
id :: OpenApiHandler m a a
id = OpenApiHandler :: forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler{openApiDoc :: Tree DocNode
openApiDoc = Tree DocNode
forall a. Tree a
NullNode}
(.) :: OpenApiHandler m b c -> OpenApiHandler m a b -> OpenApiHandler m a c
OpenApiHandler Tree DocNode
doc2 . :: OpenApiHandler m b c
-> OpenApiHandler m a b -> OpenApiHandler m a c
. OpenApiHandler Tree DocNode
doc1 = Tree DocNode -> OpenApiHandler m a c
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler (Tree DocNode -> OpenApiHandler m a c)
-> Tree DocNode -> OpenApiHandler m a c
forall a b. (a -> b) -> a -> b
$ Tree DocNode -> Tree DocNode -> Tree DocNode
insertAsLeaf Tree DocNode
doc1 Tree DocNode
doc2
where
insertAsLeaf :: Tree DocNode -> Tree DocNode -> Tree DocNode
insertAsLeaf :: Tree DocNode -> Tree DocNode -> Tree DocNode
insertAsLeaf Tree DocNode
parent Tree DocNode
child = case Tree DocNode
parent of
Tree DocNode
NullNode -> Tree DocNode
child
SingleNode DocNode
doc Tree DocNode
next -> DocNode -> Tree DocNode -> Tree DocNode
forall a. a -> Tree a -> Tree a
SingleNode DocNode
doc (Tree DocNode -> Tree DocNode -> Tree DocNode
insertAsLeaf Tree DocNode
next Tree DocNode
child)
BinaryNode Tree DocNode
b1 Tree DocNode
b2 -> Tree DocNode -> Tree DocNode -> Tree DocNode
forall a. Tree a -> Tree a -> Tree a
BinaryNode (Tree DocNode -> Tree DocNode -> Tree DocNode
insertAsLeaf Tree DocNode
b1 Tree DocNode
child) (Tree DocNode -> Tree DocNode -> Tree DocNode
insertAsLeaf Tree DocNode
b2 Tree DocNode
child)
instance Arrow (OpenApiHandler m) where
arr :: (a -> b) -> OpenApiHandler m a b
arr :: (a -> b) -> OpenApiHandler m a b
arr a -> b
_ = OpenApiHandler :: forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler{openApiDoc :: Tree DocNode
openApiDoc = Tree DocNode
forall a. Tree a
NullNode}
first :: OpenApiHandler m b c -> OpenApiHandler m (b, d) (c, d)
first :: OpenApiHandler m b c -> OpenApiHandler m (b, d) (c, d)
first (OpenApiHandler Tree DocNode
doc) = Tree DocNode -> OpenApiHandler m (b, d) (c, d)
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler Tree DocNode
doc
second :: OpenApiHandler m b c -> OpenApiHandler m (d, b) (d, c)
second :: OpenApiHandler m b c -> OpenApiHandler m (d, b) (d, c)
second (OpenApiHandler Tree DocNode
doc) = Tree DocNode -> OpenApiHandler m (d, b) (d, c)
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler Tree DocNode
doc
instance ArrowZero (OpenApiHandler m) where
zeroArrow :: OpenApiHandler m b c
zeroArrow :: OpenApiHandler m b c
zeroArrow = OpenApiHandler :: forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler{openApiDoc :: Tree DocNode
openApiDoc = Tree DocNode
forall a. Tree a
NullNode}
instance ArrowPlus (OpenApiHandler m) where
(<+>) :: OpenApiHandler m b c -> OpenApiHandler m b c -> OpenApiHandler m b c
OpenApiHandler Tree DocNode
NullNode <+> :: OpenApiHandler m b c
-> OpenApiHandler m b c -> OpenApiHandler m b c
<+> OpenApiHandler Tree DocNode
doc = Tree DocNode -> OpenApiHandler m b c
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler Tree DocNode
doc
OpenApiHandler Tree DocNode
doc <+> OpenApiHandler Tree DocNode
NullNode = Tree DocNode -> OpenApiHandler m b c
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler Tree DocNode
doc
OpenApiHandler Tree DocNode
doc1 <+> OpenApiHandler Tree DocNode
doc2 = Tree DocNode -> OpenApiHandler m b c
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler (Tree DocNode -> OpenApiHandler m b c)
-> Tree DocNode -> OpenApiHandler m b c
forall a b. (a -> b) -> a -> b
$ Tree DocNode -> Tree DocNode -> Tree DocNode
forall a. Tree a -> Tree a -> Tree a
BinaryNode Tree DocNode
doc1 Tree DocNode
doc2
instance ArrowChoice (OpenApiHandler m) where
left :: OpenApiHandler m b c -> OpenApiHandler m (Either b d) (Either c d)
left :: OpenApiHandler m b c -> OpenApiHandler m (Either b d) (Either c d)
left (OpenApiHandler Tree DocNode
doc) = Tree DocNode -> OpenApiHandler m (Either b d) (Either c d)
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler Tree DocNode
doc
right :: OpenApiHandler m b c -> OpenApiHandler m (Either d b) (Either d c)
right :: OpenApiHandler m b c -> OpenApiHandler m (Either d b) (Either d c)
right (OpenApiHandler Tree DocNode
doc) = Tree DocNode -> OpenApiHandler m (Either d b) (Either d c)
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler Tree DocNode
doc
(+++) :: OpenApiHandler m b c -> OpenApiHandler m b' c' -> OpenApiHandler m (Either b b') (Either c c')
OpenApiHandler Tree DocNode
doc +++ :: OpenApiHandler m b c
-> OpenApiHandler m b' c'
-> OpenApiHandler m (Either b b') (Either c c')
+++ OpenApiHandler Tree DocNode
NullNode = Tree DocNode -> OpenApiHandler m (Either b b') (Either c c')
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler Tree DocNode
doc
OpenApiHandler Tree DocNode
NullNode +++ OpenApiHandler Tree DocNode
doc = Tree DocNode -> OpenApiHandler m (Either b b') (Either c c')
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler Tree DocNode
doc
OpenApiHandler Tree DocNode
doc1 +++ OpenApiHandler Tree DocNode
doc2 = Tree DocNode -> OpenApiHandler m (Either b b') (Either c c')
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler (Tree DocNode -> OpenApiHandler m (Either b b') (Either c c'))
-> Tree DocNode -> OpenApiHandler m (Either b b') (Either c c')
forall a b. (a -> b) -> a -> b
$ Tree DocNode -> Tree DocNode -> Tree DocNode
forall a. Tree a -> Tree a -> Tree a
BinaryNode Tree DocNode
doc1 Tree DocNode
doc2
(|||) :: OpenApiHandler m b d -> OpenApiHandler m c d -> OpenApiHandler m (Either b c) d
OpenApiHandler Tree DocNode
doc ||| :: OpenApiHandler m b d
-> OpenApiHandler m c d -> OpenApiHandler m (Either b c) d
||| OpenApiHandler Tree DocNode
NullNode = Tree DocNode -> OpenApiHandler m (Either b c) d
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler Tree DocNode
doc
OpenApiHandler Tree DocNode
NullNode ||| OpenApiHandler Tree DocNode
doc = Tree DocNode -> OpenApiHandler m (Either b c) d
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler Tree DocNode
doc
OpenApiHandler Tree DocNode
doc1 ||| OpenApiHandler Tree DocNode
doc2 = Tree DocNode -> OpenApiHandler m (Either b c) d
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler (Tree DocNode -> OpenApiHandler m (Either b c) d)
-> Tree DocNode -> OpenApiHandler m (Either b c) d
forall a b. (a -> b) -> a -> b
$ Tree DocNode -> Tree DocNode -> Tree DocNode
forall a. Tree a -> Tree a -> Tree a
BinaryNode Tree DocNode
doc1 Tree DocNode
doc2
instance ArrowError RouteMismatch (OpenApiHandler m) where
{-# INLINEABLE raise #-}
raise :: OpenApiHandler m RouteMismatch b
raise = OpenApiHandler :: forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler{openApiDoc :: Tree DocNode
openApiDoc = Tree DocNode
forall a. Tree a
NullNode}
{-# INLINEABLE handle #-}
OpenApiHandler Tree DocNode
doc1 handle :: OpenApiHandler m e b
-> OpenApiHandler m (e, RouteMismatch) b -> OpenApiHandler m e b
`handle` OpenApiHandler Tree DocNode
doc2 = Tree DocNode -> OpenApiHandler m e b
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler (Tree DocNode -> OpenApiHandler m e b)
-> Tree DocNode -> OpenApiHandler m e b
forall a b. (a -> b) -> a -> b
$ Tree DocNode -> Tree DocNode -> Tree DocNode
forall a. Tree a -> Tree a -> Tree a
BinaryNode Tree DocNode
doc1 Tree DocNode
doc2
{-# INLINEABLE tryInUnless #-}
tryInUnless :: OpenApiHandler m e b
-> OpenApiHandler m (e, b) c
-> OpenApiHandler m (e, RouteMismatch) c
-> OpenApiHandler m e c
tryInUnless (OpenApiHandler Tree DocNode
doc1) (OpenApiHandler Tree DocNode
doc2) (OpenApiHandler Tree DocNode
doc3) =
Tree DocNode -> OpenApiHandler m e c
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler (Tree DocNode -> OpenApiHandler m e c)
-> Tree DocNode -> OpenApiHandler m e c
forall a b. (a -> b) -> a -> b
$ Tree DocNode -> Tree DocNode -> Tree DocNode
forall a. Tree a -> Tree a -> Tree a
BinaryNode (Tree DocNode -> Tree DocNode -> Tree DocNode
forall a. Tree a -> Tree a -> Tree a
BinaryNode Tree DocNode
doc1 Tree DocNode
doc2) Tree DocNode
doc3
instance Monad m => Handler (OpenApiHandler m) m where
{-# INLINEABLE arrM #-}
arrM :: (a -> m b) -> OpenApiHandler m a b
arrM :: (a -> m b) -> OpenApiHandler m a b
arrM a -> m b
_ = OpenApiHandler :: forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler{openApiDoc :: Tree DocNode
openApiDoc = Tree DocNode
forall a. Tree a
NullNode}
{-# INLINEABLE consumeRoute #-}
consumeRoute :: OpenApiHandler m RoutePath a -> OpenApiHandler m () a
consumeRoute :: OpenApiHandler m RoutePath a -> OpenApiHandler m () a
consumeRoute (OpenApiHandler Tree DocNode
doc) = Tree DocNode -> OpenApiHandler m () a
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler Tree DocNode
doc
{-# INLINEABLE setDescription #-}
setDescription :: Description -> OpenApiHandler m a a
setDescription :: Description -> OpenApiHandler m a a
setDescription = Tree DocNode -> OpenApiHandler m a a
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler (Tree DocNode -> OpenApiHandler m a a)
-> (Description -> Tree DocNode)
-> Description
-> OpenApiHandler m a a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DocNode -> Tree DocNode
forall a. a -> Tree a
singletonNode (DocNode -> Tree DocNode)
-> (Description -> DocNode) -> Description -> Tree DocNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Description -> DocNode
DocDescription
{-# INLINEABLE setSummary #-}
setSummary :: Summary -> OpenApiHandler m a a
setSummary :: Summary -> OpenApiHandler m a a
setSummary = Tree DocNode -> OpenApiHandler m a a
forall k k k (m :: k) (a :: k) (b :: k).
Tree DocNode -> OpenApiHandler m a b
OpenApiHandler (Tree DocNode -> OpenApiHandler m a a)
-> (Summary -> Tree DocNode) -> Summary -> OpenApiHandler m a a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DocNode -> Tree DocNode
forall a. a -> Tree a
singletonNode (DocNode -> Tree DocNode)
-> (Summary -> DocNode) -> Summary -> Tree DocNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Summary -> DocNode
DocSummary
toOpenApi :: OpenApiHandler m a b -> OpenApi
toOpenApi :: OpenApiHandler m a b -> OpenApi
toOpenApi = Tree CompactDocNode -> OpenApi
go (Tree CompactDocNode -> OpenApi)
-> (OpenApiHandler m a b -> Tree CompactDocNode)
-> OpenApiHandler m a b
-> OpenApi
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tree DocNode -> Tree CompactDocNode
compact (Tree DocNode -> Tree CompactDocNode)
-> (OpenApiHandler m a b -> Tree DocNode)
-> OpenApiHandler m a b
-> Tree CompactDocNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OpenApiHandler m a b -> Tree DocNode
forall k (m :: k) k (a :: k) k (b :: k).
OpenApiHandler m a b -> Tree DocNode
openApiDoc
where
go :: Tree CompactDocNode -> OpenApi
go Tree CompactDocNode
t = case Tree CompactDocNode
t of
Tree CompactDocNode
NullNode -> OpenApi
forall a. Monoid a => a
mempty
SingleNode CompactDocNode
parent Tree CompactDocNode
child -> CompactDocNode -> Tree CompactDocNode -> OpenApi -> OpenApi
mergeDoc CompactDocNode
parent Tree CompactDocNode
child OpenApi
forall a. Monoid a => a
mempty
BinaryNode Tree CompactDocNode
t1 Tree CompactDocNode
t2 -> Tree CompactDocNode -> OpenApi
go Tree CompactDocNode
t1 OpenApi -> OpenApi -> OpenApi
`combineOpenApi` Tree CompactDocNode -> OpenApi
go Tree CompactDocNode
t2
compact :: Tree DocNode -> Tree CompactDocNode
compact :: Tree DocNode -> Tree CompactDocNode
compact Tree DocNode
t = let (Maybe Description
_, Maybe Summary
_, Tree CompactDocNode
t') = Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
go Tree DocNode
t in Tree CompactDocNode
t'
where
go :: Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
go = \case
Tree DocNode
NullNode -> (Maybe Description
forall a. Maybe a
Nothing, Maybe Summary
forall a. Maybe a
Nothing, Tree CompactDocNode
forall a. Tree a
NullNode)
BinaryNode Tree DocNode
t1 Tree DocNode
t2 ->
let (Maybe Description
descr1, Maybe Summary
summ1, Tree CompactDocNode
t1') = Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
go Tree DocNode
t1
(Maybe Description
descr2, Maybe Summary
summ2, Tree CompactDocNode
t2') = Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
go Tree DocNode
t2
in (Maybe Description
descr1 Maybe Description -> Maybe Description -> Maybe Description
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Description
descr2, Maybe Summary
summ1 Maybe Summary -> Maybe Summary -> Maybe Summary
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Summary
summ2, Tree CompactDocNode -> Tree CompactDocNode -> Tree CompactDocNode
forall a. Tree a -> Tree a -> Tree a
BinaryNode Tree CompactDocNode
t1' Tree CompactDocNode
t2')
SingleNode DocNode
node Tree DocNode
child -> DocNode
-> Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
compactDoc DocNode
node Tree DocNode
child
compactDoc :: DocNode -> Tree DocNode -> (Maybe Description, Maybe Summary, Tree CompactDocNode)
compactDoc :: DocNode
-> Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
compactDoc (DocSecurityScheme Text
schemeName SecurityScheme
scheme) Tree DocNode
child =
let (Maybe Description
descr, Maybe Summary
summ, Tree CompactDocNode
child') = Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
go Tree DocNode
child
scheme' :: SecurityScheme
scheme' = SecurityScheme
scheme SecurityScheme
-> (SecurityScheme -> SecurityScheme) -> SecurityScheme
forall a b. a -> (a -> b) -> b
& (Maybe Text -> Identity (Maybe Text))
-> SecurityScheme -> Identity SecurityScheme
forall s a. HasDescription s a => Lens' s a
description ((Maybe Text -> Identity (Maybe Text))
-> SecurityScheme -> Identity SecurityScheme)
-> Maybe Text -> SecurityScheme -> SecurityScheme
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Description -> Text) -> Maybe Description -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Description -> Text
getDescription Maybe Description
descr
in (Maybe Description
forall a. Maybe a
Nothing, Maybe Summary
summ, CompactDocNode -> Tree CompactDocNode -> Tree CompactDocNode
forall a. a -> Tree a -> Tree a
SingleNode (Text -> SecurityScheme -> CompactDocNode
CDocSecurityScheme Text
schemeName SecurityScheme
scheme') Tree CompactDocNode
child')
compactDoc (DocRequestBody Definitions Schema
defs RequestBody
body) Tree DocNode
child =
let (Maybe Description
descr, Maybe Summary
summ, Tree CompactDocNode
child') = Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
go Tree DocNode
child
body' :: RequestBody
body' = RequestBody
body RequestBody -> (RequestBody -> RequestBody) -> RequestBody
forall a b. a -> (a -> b) -> b
& (Maybe Text -> Identity (Maybe Text))
-> RequestBody -> Identity RequestBody
forall s a. HasDescription s a => Lens' s a
description ((Maybe Text -> Identity (Maybe Text))
-> RequestBody -> Identity RequestBody)
-> Maybe Text -> RequestBody -> RequestBody
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Description -> Text) -> Maybe Description -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Description -> Text
getDescription Maybe Description
descr
in (Maybe Description
forall a. Maybe a
Nothing, Maybe Summary
summ, CompactDocNode -> Tree CompactDocNode -> Tree CompactDocNode
forall a. a -> Tree a -> Tree a
SingleNode (Definitions Schema -> RequestBody -> CompactDocNode
CDocRequestBody Definitions Schema
defs RequestBody
body') Tree CompactDocNode
child')
compactDoc (DocResponseBody Definitions Schema
defs MediaType
mediaType MediaTypeObject
mediaTypeObject) Tree DocNode
child =
CompactDocNode -> Tree CompactDocNode -> Tree CompactDocNode
forall a. a -> Tree a -> Tree a
SingleNode (Definitions Schema
-> MediaType -> MediaTypeObject -> CompactDocNode
CDocResponseBody Definitions Schema
defs MediaType
mediaType MediaTypeObject
mediaTypeObject) (Tree CompactDocNode -> Tree CompactDocNode)
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
go Tree DocNode
child
compactDoc (DocRequestHeader Param
param) Tree DocNode
child =
let (Maybe Description
descr, Maybe Summary
summ, Tree CompactDocNode
child') = Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
go Tree DocNode
child
param' :: Param
param' = Param
param Param -> (Param -> Param) -> Param
forall a b. a -> (a -> b) -> b
& (Maybe Text -> Identity (Maybe Text)) -> Param -> Identity Param
forall s a. HasDescription s a => Lens' s a
description ((Maybe Text -> Identity (Maybe Text)) -> Param -> Identity Param)
-> Maybe Text -> Param -> Param
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Description -> Text) -> Maybe Description -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Description -> Text
getDescription Maybe Description
descr
in (Maybe Description
forall a. Maybe a
Nothing, Maybe Summary
summ, CompactDocNode -> Tree CompactDocNode -> Tree CompactDocNode
forall a. a -> Tree a -> Tree a
SingleNode (Param -> CompactDocNode
CDocRequestHeader Param
param') Tree CompactDocNode
child')
compactDoc (DocResponseHeader Text
headerName Header
header) Tree DocNode
child =
let (Maybe Description
descr, Maybe Summary
summ, Tree CompactDocNode
child') = Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
go Tree DocNode
child
header' :: Header
header' = Header
header Header -> (Header -> Header) -> Header
forall a b. a -> (a -> b) -> b
& (Maybe Text -> Identity (Maybe Text)) -> Header -> Identity Header
forall s a. HasDescription s a => Lens' s a
description ((Maybe Text -> Identity (Maybe Text))
-> Header -> Identity Header)
-> Maybe Text -> Header -> Header
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Description -> Text) -> Maybe Description -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Description -> Text
getDescription Maybe Description
descr
in (Maybe Description
forall a. Maybe a
Nothing, Maybe Summary
summ, CompactDocNode -> Tree CompactDocNode -> Tree CompactDocNode
forall a. a -> Tree a -> Tree a
SingleNode (Text -> Header -> CompactDocNode
CDocResponseHeader Text
headerName Header
header') Tree CompactDocNode
child')
compactDoc (DocMethod StdMethod
m) Tree DocNode
child =
(Maybe Description
forall a. Maybe a
Nothing, Maybe Summary
forall a. Maybe a
Nothing, CompactDocNode -> Tree DocNode -> Tree CompactDocNode
addRouteDoc (StdMethod -> CompactDocNode
CDocMethod StdMethod
m) Tree DocNode
child)
compactDoc (DocPathElem Text
path) Tree DocNode
child =
(Maybe Description
forall a. Maybe a
Nothing, Maybe Summary
forall a. Maybe a
Nothing, CompactDocNode -> Tree DocNode -> Tree CompactDocNode
addRouteDoc (Text -> CompactDocNode
CDocPathElem Text
path) Tree DocNode
child)
compactDoc (DocPathVar Param
param) Tree DocNode
child =
(Maybe Description
forall a. Maybe a
Nothing, Maybe Summary
forall a. Maybe a
Nothing, CompactDocNode -> Tree DocNode -> Tree CompactDocNode
addRouteDoc (Param -> CompactDocNode
CDocPathVar Param
param) Tree DocNode
child)
compactDoc (DocQueryParam Param
param) Tree DocNode
child =
let (Maybe Description
descr, Maybe Summary
summ, Tree CompactDocNode
child') = Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
go Tree DocNode
child
param' :: Param
param' = Param
param Param -> (Param -> Param) -> Param
forall a b. a -> (a -> b) -> b
& (Maybe Text -> Identity (Maybe Text)) -> Param -> Identity Param
forall s a. HasDescription s a => Lens' s a
description ((Maybe Text -> Identity (Maybe Text)) -> Param -> Identity Param)
-> Maybe Text -> Param -> Param
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Description -> Text) -> Maybe Description -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Description -> Text
getDescription Maybe Description
descr
in (Maybe Description
forall a. Maybe a
Nothing, Maybe Summary
summ, CompactDocNode -> Tree CompactDocNode -> Tree CompactDocNode
forall a. a -> Tree a -> Tree a
SingleNode (Param -> CompactDocNode
CDocQueryParam Param
param') Tree CompactDocNode
child')
compactDoc (DocStatus Status
status) Tree DocNode
child =
let (Maybe Description
descr, Maybe Summary
summ, Tree CompactDocNode
child') = Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
go Tree DocNode
child
in (Maybe Description
forall a. Maybe a
Nothing, Maybe Summary
summ, CompactDocNode -> Tree CompactDocNode -> Tree CompactDocNode
forall a. a -> Tree a -> Tree a
SingleNode (Status -> Maybe Description -> CompactDocNode
CDocStatus Status
status Maybe Description
descr) Tree CompactDocNode
child')
compactDoc (DocSummary Summary
summ) Tree DocNode
child =
let (Maybe Description
descr, Maybe Summary
_, Tree CompactDocNode
child') = Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
go Tree DocNode
child
in (Maybe Description
descr, Summary -> Maybe Summary
forall a. a -> Maybe a
Just Summary
summ, Tree CompactDocNode
child')
compactDoc (DocDescription Description
descr) Tree DocNode
child =
let (Maybe Description
_, Maybe Summary
summ, Tree CompactDocNode
child') = Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
go Tree DocNode
child
in (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
descr, Maybe Summary
summ, Tree CompactDocNode
child')
addRouteDoc :: CompactDocNode -> Tree DocNode -> Tree CompactDocNode
addRouteDoc :: CompactDocNode -> Tree DocNode -> Tree CompactDocNode
addRouteDoc CompactDocNode
node Tree DocNode
child = case Tree DocNode
-> (Maybe Description, Maybe Summary, Tree CompactDocNode)
go Tree DocNode
child of
(Maybe Description
Nothing, Maybe Summary
Nothing, Tree CompactDocNode
child') -> CompactDocNode -> Tree CompactDocNode -> Tree CompactDocNode
forall a. a -> Tree a -> Tree a
SingleNode CompactDocNode
node Tree CompactDocNode
child'
(Maybe Description
descr, Maybe Summary
summ, Tree CompactDocNode
child') -> CompactDocNode -> Tree CompactDocNode -> Tree CompactDocNode
forall a. a -> Tree a -> Tree a
SingleNode (Maybe Summary -> Maybe Description -> CompactDocNode
CDocRouteDoc Maybe Summary
summ Maybe Description
descr) (CompactDocNode -> Tree CompactDocNode -> Tree CompactDocNode
forall a. a -> Tree a -> Tree a
SingleNode CompactDocNode
node Tree CompactDocNode
child')
postOrder :: Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder :: Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder Tree CompactDocNode
NullNode OpenApi
doc OpenApi -> OpenApi
f = OpenApi -> OpenApi
f OpenApi
doc
postOrder (SingleNode CompactDocNode
node Tree CompactDocNode
child) OpenApi
doc OpenApi -> OpenApi
f = OpenApi -> OpenApi
f (OpenApi -> OpenApi) -> OpenApi -> OpenApi
forall a b. (a -> b) -> a -> b
$ CompactDocNode -> Tree CompactDocNode -> OpenApi -> OpenApi
mergeDoc CompactDocNode
node Tree CompactDocNode
child OpenApi
doc
postOrder (BinaryNode Tree CompactDocNode
t1 Tree CompactDocNode
t2) OpenApi
doc OpenApi -> OpenApi
f =
OpenApi -> OpenApi
f (OpenApi -> OpenApi) -> OpenApi -> OpenApi
forall a b. (a -> b) -> a -> b
$ Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder Tree CompactDocNode
t1 OpenApi
doc OpenApi -> OpenApi
forall a. a -> a
id OpenApi -> OpenApi -> OpenApi
`combineOpenApi` Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder Tree CompactDocNode
t2 OpenApi
doc OpenApi -> OpenApi
forall a. a -> a
id
preOrder :: Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
preOrder :: Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
preOrder Tree CompactDocNode
NullNode OpenApi
doc OpenApi -> OpenApi
f = OpenApi -> OpenApi
f OpenApi
doc
preOrder (SingleNode CompactDocNode
node Tree CompactDocNode
child) OpenApi
doc OpenApi -> OpenApi
f = CompactDocNode -> Tree CompactDocNode -> OpenApi -> OpenApi
mergeDoc CompactDocNode
node Tree CompactDocNode
child (OpenApi -> OpenApi
f OpenApi
doc)
preOrder (BinaryNode Tree CompactDocNode
t1 Tree CompactDocNode
t2) OpenApi
doc OpenApi -> OpenApi
f =
let doc' :: OpenApi
doc' = OpenApi -> OpenApi
f OpenApi
doc
in Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder Tree CompactDocNode
t1 OpenApi
doc' OpenApi -> OpenApi
forall a. a -> a
id OpenApi -> OpenApi -> OpenApi
`combineOpenApi` Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder Tree CompactDocNode
t2 OpenApi
doc' OpenApi -> OpenApi
forall a. a -> a
id
combinePathItem :: PathItem -> PathItem -> PathItem
combinePathItem :: PathItem -> PathItem -> PathItem
combinePathItem PathItem
s PathItem
t =
PathItem :: Maybe Text
-> Maybe Text
-> Maybe Operation
-> Maybe Operation
-> Maybe Operation
-> Maybe Operation
-> Maybe Operation
-> Maybe Operation
-> Maybe Operation
-> Maybe Operation
-> [Server]
-> [Referenced Param]
-> PathItem
PathItem
{ _pathItemGet :: Maybe Operation
_pathItemGet = PathItem -> Maybe Operation
_pathItemGet PathItem
s Maybe Operation -> Maybe Operation -> Maybe Operation
forall a. Semigroup a => a -> a -> a
<> PathItem -> Maybe Operation
_pathItemGet PathItem
t
, _pathItemPut :: Maybe Operation
_pathItemPut = PathItem -> Maybe Operation
_pathItemPut PathItem
s Maybe Operation -> Maybe Operation -> Maybe Operation
forall a. Semigroup a => a -> a -> a
<> PathItem -> Maybe Operation
_pathItemPut PathItem
t
, _pathItemPost :: Maybe Operation
_pathItemPost = PathItem -> Maybe Operation
_pathItemPost PathItem
s Maybe Operation -> Maybe Operation -> Maybe Operation
forall a. Semigroup a => a -> a -> a
<> PathItem -> Maybe Operation
_pathItemPost PathItem
t
, _pathItemDelete :: Maybe Operation
_pathItemDelete = PathItem -> Maybe Operation
_pathItemDelete PathItem
s Maybe Operation -> Maybe Operation -> Maybe Operation
forall a. Semigroup a => a -> a -> a
<> PathItem -> Maybe Operation
_pathItemDelete PathItem
t
, _pathItemOptions :: Maybe Operation
_pathItemOptions = PathItem -> Maybe Operation
_pathItemOptions PathItem
s Maybe Operation -> Maybe Operation -> Maybe Operation
forall a. Semigroup a => a -> a -> a
<> PathItem -> Maybe Operation
_pathItemOptions PathItem
t
, _pathItemHead :: Maybe Operation
_pathItemHead = PathItem -> Maybe Operation
_pathItemHead PathItem
s Maybe Operation -> Maybe Operation -> Maybe Operation
forall a. Semigroup a => a -> a -> a
<> PathItem -> Maybe Operation
_pathItemHead PathItem
t
, _pathItemPatch :: Maybe Operation
_pathItemPatch = PathItem -> Maybe Operation
_pathItemPatch PathItem
s Maybe Operation -> Maybe Operation -> Maybe Operation
forall a. Semigroup a => a -> a -> a
<> PathItem -> Maybe Operation
_pathItemPatch PathItem
t
, _pathItemTrace :: Maybe Operation
_pathItemTrace = PathItem -> Maybe Operation
_pathItemTrace PathItem
s Maybe Operation -> Maybe Operation -> Maybe Operation
forall a. Semigroup a => a -> a -> a
<> PathItem -> Maybe Operation
_pathItemTrace PathItem
t
, _pathItemParameters :: [Referenced Param]
_pathItemParameters = PathItem -> [Referenced Param]
_pathItemParameters PathItem
s [Referenced Param] -> [Referenced Param] -> [Referenced Param]
forall a. Semigroup a => a -> a -> a
<> PathItem -> [Referenced Param]
_pathItemParameters PathItem
t
, _pathItemSummary :: Maybe Text
_pathItemSummary = PathItem -> Maybe Text
_pathItemSummary PathItem
s Maybe Text -> Maybe Text -> Maybe Text
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> PathItem -> Maybe Text
_pathItemSummary PathItem
t
, _pathItemDescription :: Maybe Text
_pathItemDescription = PathItem -> Maybe Text
_pathItemDescription PathItem
s Maybe Text -> Maybe Text -> Maybe Text
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> PathItem -> Maybe Text
_pathItemDescription PathItem
t
, _pathItemServers :: [Server]
_pathItemServers = PathItem -> [Server]
_pathItemServers PathItem
s [Server] -> [Server] -> [Server]
forall a. Semigroup a => a -> a -> a
<> PathItem -> [Server]
_pathItemServers PathItem
t
}
combineOpenApi :: OpenApi -> OpenApi -> OpenApi
combineOpenApi :: OpenApi -> OpenApi -> OpenApi
combineOpenApi OpenApi
s OpenApi
t =
OpenApi :: Info
-> [Server]
-> InsOrdHashMap String PathItem
-> Components
-> [SecurityRequirement]
-> InsOrdHashSet Tag
-> Maybe ExternalDocs
-> OpenApi
OpenApi
{ _openApiInfo :: Info
_openApiInfo = OpenApi -> Info
_openApiInfo OpenApi
s Info -> Info -> Info
forall a. Semigroup a => a -> a -> a
<> OpenApi -> Info
_openApiInfo OpenApi
t
, _openApiServers :: [Server]
_openApiServers = OpenApi -> [Server]
_openApiServers OpenApi
s [Server] -> [Server] -> [Server]
forall a. Semigroup a => a -> a -> a
<> OpenApi -> [Server]
_openApiServers OpenApi
t
, _openApiPaths :: InsOrdHashMap String PathItem
_openApiPaths = (PathItem -> PathItem -> PathItem)
-> InsOrdHashMap String PathItem
-> InsOrdHashMap String PathItem
-> InsOrdHashMap String PathItem
forall k v.
(Eq k, Hashable k) =>
(v -> v -> v)
-> InsOrdHashMap k v -> InsOrdHashMap k v -> InsOrdHashMap k v
Map.unionWith PathItem -> PathItem -> PathItem
combinePathItem (OpenApi -> InsOrdHashMap String PathItem
_openApiPaths OpenApi
s) (OpenApi -> InsOrdHashMap String PathItem
_openApiPaths OpenApi
t)
, _openApiComponents :: Components
_openApiComponents = OpenApi -> Components
_openApiComponents OpenApi
s Components -> Components -> Components
forall a. Semigroup a => a -> a -> a
<> OpenApi -> Components
_openApiComponents OpenApi
t
, _openApiSecurity :: [SecurityRequirement]
_openApiSecurity = OpenApi -> [SecurityRequirement]
_openApiSecurity OpenApi
s [SecurityRequirement]
-> [SecurityRequirement] -> [SecurityRequirement]
forall a. Semigroup a => a -> a -> a
<> OpenApi -> [SecurityRequirement]
_openApiSecurity OpenApi
t
, _openApiTags :: InsOrdHashSet Tag
_openApiTags = OpenApi -> InsOrdHashSet Tag
_openApiTags OpenApi
s InsOrdHashSet Tag -> InsOrdHashSet Tag -> InsOrdHashSet Tag
forall a. Semigroup a => a -> a -> a
<> OpenApi -> InsOrdHashSet Tag
_openApiTags OpenApi
t
, _openApiExternalDocs :: Maybe ExternalDocs
_openApiExternalDocs = OpenApi -> Maybe ExternalDocs
_openApiExternalDocs OpenApi
s Maybe ExternalDocs -> Maybe ExternalDocs -> Maybe ExternalDocs
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> OpenApi -> Maybe ExternalDocs
_openApiExternalDocs OpenApi
t
}
mergeDoc :: CompactDocNode -> Tree CompactDocNode -> OpenApi -> OpenApi
mergeDoc :: CompactDocNode -> Tree CompactDocNode -> OpenApi -> OpenApi
mergeDoc (CDocSecurityScheme Text
schemeName SecurityScheme
scheme) Tree CompactDocNode
child OpenApi
doc =
let
#if MIN_VERSION_openapi3(3, 2, 0)
secSchemes :: SecurityDefinitions
secSchemes = Definitions SecurityScheme -> SecurityDefinitions
SecurityDefinitions [(Text
schemeName, SecurityScheme
scheme)]
#else
secSchemes = [(schemeName, scheme)] :: Definitions SecurityScheme
#endif
secReqs :: [SecurityRequirement]
secReqs = [InsOrdHashMap Text [Text] -> SecurityRequirement
SecurityRequirement [(Text
schemeName, [])]] :: [SecurityRequirement]
in Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder Tree CompactDocNode
child OpenApi
doc ((OpenApi -> OpenApi) -> OpenApi)
-> (OpenApi -> OpenApi) -> OpenApi
forall a b. (a -> b) -> a -> b
$ \OpenApi
doc' ->
OpenApi
doc'
OpenApi -> (OpenApi -> OpenApi) -> OpenApi
forall a b. a -> (a -> b) -> b
& (Components -> Identity Components) -> OpenApi -> Identity OpenApi
forall s a. HasComponents s a => Lens' s a
components ((Components -> Identity Components)
-> OpenApi -> Identity OpenApi)
-> ((SecurityDefinitions -> Identity SecurityDefinitions)
-> Components -> Identity Components)
-> (SecurityDefinitions -> Identity SecurityDefinitions)
-> OpenApi
-> Identity OpenApi
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SecurityDefinitions -> Identity SecurityDefinitions)
-> Components -> Identity Components
forall s a. HasSecuritySchemes s a => Lens' s a
securitySchemes ((SecurityDefinitions -> Identity SecurityDefinitions)
-> OpenApi -> Identity OpenApi)
-> SecurityDefinitions -> OpenApi -> OpenApi
forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ SecurityDefinitions
secSchemes
OpenApi -> (OpenApi -> OpenApi) -> OpenApi
forall a b. a -> (a -> b) -> b
& (Operation -> Identity Operation) -> OpenApi -> Identity OpenApi
Traversal' OpenApi Operation
allOperations ((Operation -> Identity Operation) -> OpenApi -> Identity OpenApi)
-> (([SecurityRequirement] -> Identity [SecurityRequirement])
-> Operation -> Identity Operation)
-> ([SecurityRequirement] -> Identity [SecurityRequirement])
-> OpenApi
-> Identity OpenApi
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([SecurityRequirement] -> Identity [SecurityRequirement])
-> Operation -> Identity Operation
forall s a. HasSecurity s a => Lens' s a
security (([SecurityRequirement] -> Identity [SecurityRequirement])
-> OpenApi -> Identity OpenApi)
-> [SecurityRequirement] -> OpenApi -> OpenApi
forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ [SecurityRequirement]
secReqs
mergeDoc (CDocRequestBody Definitions Schema
defs RequestBody
body) Tree CompactDocNode
child OpenApi
doc =
Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder Tree CompactDocNode
child OpenApi
doc ((OpenApi -> OpenApi) -> OpenApi)
-> (OpenApi -> OpenApi) -> OpenApi
forall a b. (a -> b) -> a -> b
$ \OpenApi
doc' ->
OpenApi
doc'
OpenApi -> (OpenApi -> OpenApi) -> OpenApi
forall a b. a -> (a -> b) -> b
& (Operation -> Identity Operation) -> OpenApi -> Identity OpenApi
Traversal' OpenApi Operation
allOperations ((Operation -> Identity Operation) -> OpenApi -> Identity OpenApi)
-> ((Maybe (Referenced RequestBody)
-> Identity (Maybe (Referenced RequestBody)))
-> Operation -> Identity Operation)
-> (Maybe (Referenced RequestBody)
-> Identity (Maybe (Referenced RequestBody)))
-> OpenApi
-> Identity OpenApi
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Referenced RequestBody)
-> Identity (Maybe (Referenced RequestBody)))
-> Operation -> Identity Operation
forall s a. HasRequestBody s a => Lens' s a
requestBody ((Maybe (Referenced RequestBody)
-> Identity (Maybe (Referenced RequestBody)))
-> OpenApi -> Identity OpenApi)
-> Referenced RequestBody -> OpenApi -> OpenApi
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ RequestBody -> Referenced RequestBody
forall a. a -> Referenced a
Inline RequestBody
body
OpenApi -> (OpenApi -> OpenApi) -> OpenApi
forall a b. a -> (a -> b) -> b
& (Components -> Identity Components) -> OpenApi -> Identity OpenApi
forall s a. HasComponents s a => Lens' s a
components ((Components -> Identity Components)
-> OpenApi -> Identity OpenApi)
-> ((Definitions Schema -> Identity (Definitions Schema))
-> Components -> Identity Components)
-> (Definitions Schema -> Identity (Definitions Schema))
-> OpenApi
-> Identity OpenApi
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Definitions Schema -> Identity (Definitions Schema))
-> Components -> Identity Components
forall s a. HasSchemas s a => Lens' s a
schemas ((Definitions Schema -> Identity (Definitions Schema))
-> OpenApi -> Identity OpenApi)
-> (Definitions Schema -> Definitions Schema) -> OpenApi -> OpenApi
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Definitions Schema -> Definitions Schema -> Definitions Schema
forall a. Semigroup a => a -> a -> a
<> Definitions Schema
defs)
mergeDoc (CDocRequestHeader Param
param) Tree CompactDocNode
child OpenApi
doc =
Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder Tree CompactDocNode
child OpenApi
doc ((OpenApi -> OpenApi) -> OpenApi)
-> (OpenApi -> OpenApi) -> OpenApi
forall a b. (a -> b) -> a -> b
$ \OpenApi
doc' ->
OpenApi
doc' OpenApi -> (OpenApi -> OpenApi) -> OpenApi
forall a b. a -> (a -> b) -> b
& (Operation -> Identity Operation) -> OpenApi -> Identity OpenApi
Traversal' OpenApi Operation
allOperations ((Operation -> Identity Operation) -> OpenApi -> Identity OpenApi)
-> (([Referenced Param] -> Identity [Referenced Param])
-> Operation -> Identity Operation)
-> ([Referenced Param] -> Identity [Referenced Param])
-> OpenApi
-> Identity OpenApi
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Referenced Param] -> Identity [Referenced Param])
-> Operation -> Identity Operation
forall s a. HasParameters s a => Lens' s a
parameters (([Referenced Param] -> Identity [Referenced Param])
-> OpenApi -> Identity OpenApi)
-> [Referenced Param] -> OpenApi -> OpenApi
forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ [Param -> Referenced Param
forall a. a -> Referenced a
Inline Param
param]
mergeDoc (CDocMethod StdMethod
m) Tree CompactDocNode
child OpenApi
doc =
Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder Tree CompactDocNode
child OpenApi
doc ((OpenApi -> OpenApi) -> OpenApi)
-> (OpenApi -> OpenApi) -> OpenApi
forall a b. (a -> b) -> a -> b
$ \OpenApi
doc' ->
OpenApi
doc' OpenApi -> (OpenApi -> OpenApi) -> OpenApi
forall a b. a -> (a -> b) -> b
& (InsOrdHashMap String PathItem
-> Identity (InsOrdHashMap String PathItem))
-> OpenApi -> Identity OpenApi
forall s a. HasPaths s a => Lens' s a
paths ((InsOrdHashMap String PathItem
-> Identity (InsOrdHashMap String PathItem))
-> OpenApi -> Identity OpenApi)
-> (InsOrdHashMap String PathItem -> InsOrdHashMap String PathItem)
-> OpenApi
-> OpenApi
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (PathItem -> PathItem)
-> InsOrdHashMap String PathItem -> InsOrdHashMap String PathItem
forall v1 v2 k.
(v1 -> v2) -> InsOrdHashMap k v1 -> InsOrdHashMap k v2
Map.map (StdMethod -> PathItem -> PathItem
removeOtherMethods StdMethod
m)
mergeDoc (CDocPathElem Text
path) Tree CompactDocNode
child OpenApi
doc =
Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder Tree CompactDocNode
child OpenApi
doc ((OpenApi -> OpenApi) -> OpenApi)
-> (OpenApi -> OpenApi) -> OpenApi
forall a b. (a -> b) -> a -> b
$ String -> OpenApi -> OpenApi
prependPath (Text -> String
Text.unpack Text
path)
mergeDoc (CDocPathVar Param
param) Tree CompactDocNode
child OpenApi
doc =
Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder Tree CompactDocNode
child OpenApi
doc ((OpenApi -> OpenApi) -> OpenApi)
-> (OpenApi -> OpenApi) -> OpenApi
forall a b. (a -> b) -> a -> b
$ \OpenApi
doc' ->
String -> OpenApi -> OpenApi
prependPath (String
"{" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack (Param -> Text
_paramName Param
param) String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"}") OpenApi
doc'
OpenApi -> (OpenApi -> OpenApi) -> OpenApi
forall a b. a -> (a -> b) -> b
& (Operation -> Identity Operation) -> OpenApi -> Identity OpenApi
Traversal' OpenApi Operation
allOperations ((Operation -> Identity Operation) -> OpenApi -> Identity OpenApi)
-> (([Referenced Param] -> Identity [Referenced Param])
-> Operation -> Identity Operation)
-> ([Referenced Param] -> Identity [Referenced Param])
-> OpenApi
-> Identity OpenApi
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Referenced Param] -> Identity [Referenced Param])
-> Operation -> Identity Operation
forall s a. HasParameters s a => Lens' s a
parameters (([Referenced Param] -> Identity [Referenced Param])
-> OpenApi -> Identity OpenApi)
-> [Referenced Param] -> OpenApi -> OpenApi
forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ [Param -> Referenced Param
forall a. a -> Referenced a
Inline Param
param]
mergeDoc (CDocRouteDoc Maybe Summary
summ Maybe Description
descr) Tree CompactDocNode
child OpenApi
doc =
Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder Tree CompactDocNode
child OpenApi
doc ((OpenApi -> OpenApi) -> OpenApi)
-> (OpenApi -> OpenApi) -> OpenApi
forall a b. (a -> b) -> a -> b
$ \OpenApi
doc' ->
OpenApi
doc'
OpenApi -> (OpenApi -> OpenApi) -> OpenApi
forall a b. a -> (a -> b) -> b
& (Operation -> Identity Operation) -> OpenApi -> Identity OpenApi
Traversal' OpenApi Operation
allOperations ((Operation -> Identity Operation) -> OpenApi -> Identity OpenApi)
-> ((Maybe Text -> Identity (Maybe Text))
-> Operation -> Identity Operation)
-> (Maybe Text -> Identity (Maybe Text))
-> OpenApi
-> Identity OpenApi
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Text -> Identity (Maybe Text))
-> Operation -> Identity Operation
forall s a. HasSummary s a => Lens' s a
summary ((Maybe Text -> Identity (Maybe Text))
-> OpenApi -> Identity OpenApi)
-> (Maybe Text -> Maybe Text) -> OpenApi -> OpenApi
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Maybe Text -> Maybe Text -> Maybe Text
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Summary -> Text) -> Maybe Summary -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Summary -> Text
getSummary Maybe Summary
summ)
OpenApi -> (OpenApi -> OpenApi) -> OpenApi
forall a b. a -> (a -> b) -> b
& (Operation -> Identity Operation) -> OpenApi -> Identity OpenApi
Traversal' OpenApi Operation
allOperations ((Operation -> Identity Operation) -> OpenApi -> Identity OpenApi)
-> ((Maybe Text -> Identity (Maybe Text))
-> Operation -> Identity Operation)
-> (Maybe Text -> Identity (Maybe Text))
-> OpenApi
-> Identity OpenApi
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Text -> Identity (Maybe Text))
-> Operation -> Identity Operation
forall s a. HasDescription s a => Lens' s a
description ((Maybe Text -> Identity (Maybe Text))
-> OpenApi -> Identity OpenApi)
-> (Maybe Text -> Maybe Text) -> OpenApi -> OpenApi
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Maybe Text -> Maybe Text -> Maybe Text
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Description -> Text) -> Maybe Description -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Description -> Text
getDescription Maybe Description
descr)
mergeDoc (CDocQueryParam Param
param) Tree CompactDocNode
child OpenApi
doc =
Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder Tree CompactDocNode
child OpenApi
doc ((OpenApi -> OpenApi) -> OpenApi)
-> (OpenApi -> OpenApi) -> OpenApi
forall a b. (a -> b) -> a -> b
$ \OpenApi
doc' ->
OpenApi
doc' OpenApi -> (OpenApi -> OpenApi) -> OpenApi
forall a b. a -> (a -> b) -> b
& (Operation -> Identity Operation) -> OpenApi -> Identity OpenApi
Traversal' OpenApi Operation
allOperations ((Operation -> Identity Operation) -> OpenApi -> Identity OpenApi)
-> (([Referenced Param] -> Identity [Referenced Param])
-> Operation -> Identity Operation)
-> ([Referenced Param] -> Identity [Referenced Param])
-> OpenApi
-> Identity OpenApi
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Referenced Param] -> Identity [Referenced Param])
-> Operation -> Identity Operation
forall s a. HasParameters s a => Lens' s a
parameters (([Referenced Param] -> Identity [Referenced Param])
-> OpenApi -> Identity OpenApi)
-> [Referenced Param] -> OpenApi -> OpenApi
forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ [Param -> Referenced Param
forall a. a -> Referenced a
Inline Param
param]
mergeDoc (CDocStatus Status
status Maybe Description
descr) Tree CompactDocNode
child OpenApi
doc =
Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
preOrder Tree CompactDocNode
child OpenApi
doc ((OpenApi -> OpenApi) -> OpenApi)
-> (OpenApi -> OpenApi) -> OpenApi
forall a b. (a -> b) -> a -> b
$ \OpenApi
doc' ->
let resp :: Response
resp =
Monoid Response => Response
forall a. Monoid a => a
mempty @Response
Response -> (Response -> Response) -> Response
forall a b. a -> (a -> b) -> b
& (Text -> Identity Text) -> Response -> Identity Response
forall s a. HasDescription s a => Lens' s a
description ((Text -> Identity Text) -> Response -> Identity Response)
-> Text -> Response -> Response
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Text -> (Description -> Text) -> Maybe Description -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" Description -> Text
getDescription Maybe Description
descr
opr :: Operation
opr =
Monoid Operation => Operation
forall a. Monoid a => a
mempty @Operation
Operation -> (Operation -> Operation) -> Operation
forall a b. a -> (a -> b) -> b
& Index Operation -> Lens' Operation (Maybe (IxValue Operation))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at (Status -> Int
HTTP.statusCode Status
status) ((Maybe (Referenced Response)
-> Identity (Maybe (Referenced Response)))
-> Operation -> Identity Operation)
-> Referenced Response -> Operation -> Operation
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Response -> Referenced Response
forall a. a -> Referenced a
Inline Response
resp
pathItem :: PathItem
pathItem =
Monoid PathItem => PathItem
forall a. Monoid a => a
mempty @PathItem
PathItem -> (PathItem -> PathItem) -> PathItem
forall a b. a -> (a -> b) -> b
& (Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem
forall s a. HasGet s a => Lens' s a
get ((Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem)
-> Operation -> PathItem -> PathItem
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Operation
opr
PathItem -> (PathItem -> PathItem) -> PathItem
forall a b. a -> (a -> b) -> b
& (Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem
forall s a. HasPut s a => Lens' s a
put ((Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem)
-> Operation -> PathItem -> PathItem
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Operation
opr
PathItem -> (PathItem -> PathItem) -> PathItem
forall a b. a -> (a -> b) -> b
& (Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem
forall s a. HasPost s a => Lens' s a
post ((Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem)
-> Operation -> PathItem -> PathItem
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Operation
opr
PathItem -> (PathItem -> PathItem) -> PathItem
forall a b. a -> (a -> b) -> b
& (Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem
forall s a. HasDelete s a => Lens' s a
delete ((Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem)
-> Operation -> PathItem -> PathItem
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Operation
opr
PathItem -> (PathItem -> PathItem) -> PathItem
forall a b. a -> (a -> b) -> b
& (Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem
forall s a. HasOptions s a => Lens' s a
options ((Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem)
-> Operation -> PathItem -> PathItem
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Operation
opr
PathItem -> (PathItem -> PathItem) -> PathItem
forall a b. a -> (a -> b) -> b
& (Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem
forall s a. HasHead s a => Lens' s a
head_ ((Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem)
-> Operation -> PathItem -> PathItem
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Operation
opr
PathItem -> (PathItem -> PathItem) -> PathItem
forall a b. a -> (a -> b) -> b
& (Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem
forall s a. HasPatch s a => Lens' s a
patch ((Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem)
-> Operation -> PathItem -> PathItem
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Operation
opr
PathItem -> (PathItem -> PathItem) -> PathItem
forall a b. a -> (a -> b) -> b
& (Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem
forall s a. HasTrace s a => Lens' s a
trace ((Maybe Operation -> Identity (Maybe Operation))
-> PathItem -> Identity PathItem)
-> Operation -> PathItem -> PathItem
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Operation
opr
in OpenApi
doc' OpenApi -> (OpenApi -> OpenApi) -> OpenApi
forall a b. a -> (a -> b) -> b
& (InsOrdHashMap String PathItem
-> Identity (InsOrdHashMap String PathItem))
-> OpenApi -> Identity OpenApi
forall s a. HasPaths s a => Lens' s a
paths ((InsOrdHashMap String PathItem
-> Identity (InsOrdHashMap String PathItem))
-> OpenApi -> Identity OpenApi)
-> InsOrdHashMap String PathItem -> OpenApi -> OpenApi
forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ [(String
"/", PathItem
pathItem)]
mergeDoc (CDocResponseBody Definitions Schema
defs MediaType
mediaType MediaTypeObject
mediaTypeObject) Tree CompactDocNode
child OpenApi
doc =
Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder Tree CompactDocNode
child OpenApi
doc ((OpenApi -> OpenApi) -> OpenApi)
-> (OpenApi -> OpenApi) -> OpenApi
forall a b. (a -> b) -> a -> b
$ \OpenApi
doc' ->
let resp :: Response
resp = Monoid Response => Response
forall a. Monoid a => a
mempty @Response Response -> (Response -> Response) -> Response
forall a b. a -> (a -> b) -> b
& (InsOrdHashMap MediaType MediaTypeObject
-> Identity (InsOrdHashMap MediaType MediaTypeObject))
-> Response -> Identity Response
forall s a. HasContent s a => Lens' s a
content ((InsOrdHashMap MediaType MediaTypeObject
-> Identity (InsOrdHashMap MediaType MediaTypeObject))
-> Response -> Identity Response)
-> InsOrdHashMap MediaType MediaTypeObject -> Response -> Response
forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ [(MediaType
mediaType, MediaTypeObject
mediaTypeObject)]
in OpenApi
doc'
OpenApi -> (OpenApi -> OpenApi) -> OpenApi
forall a b. a -> (a -> b) -> b
& (Operation -> Identity Operation) -> OpenApi -> Identity OpenApi
Traversal' OpenApi Operation
allOperations ((Operation -> Identity Operation) -> OpenApi -> Identity OpenApi)
-> ((InsOrdHashMap Int (Referenced Response)
-> Identity (InsOrdHashMap Int (Referenced Response)))
-> Operation -> Identity Operation)
-> (InsOrdHashMap Int (Referenced Response)
-> Identity (InsOrdHashMap Int (Referenced Response)))
-> OpenApi
-> Identity OpenApi
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Responses -> Identity Responses)
-> Operation -> Identity Operation
forall s a. HasResponses s a => Lens' s a
responses ((Responses -> Identity Responses)
-> Operation -> Identity Operation)
-> ((InsOrdHashMap Int (Referenced Response)
-> Identity (InsOrdHashMap Int (Referenced Response)))
-> Responses -> Identity Responses)
-> (InsOrdHashMap Int (Referenced Response)
-> Identity (InsOrdHashMap Int (Referenced Response)))
-> Operation
-> Identity Operation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (InsOrdHashMap Int (Referenced Response)
-> Identity (InsOrdHashMap Int (Referenced Response)))
-> Responses -> Identity Responses
forall s a. HasResponses s a => Lens' s a
responses ((InsOrdHashMap Int (Referenced Response)
-> Identity (InsOrdHashMap Int (Referenced Response)))
-> OpenApi -> Identity OpenApi)
-> (InsOrdHashMap Int (Referenced Response)
-> InsOrdHashMap Int (Referenced Response))
-> OpenApi
-> OpenApi
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Referenced Response -> Referenced Response)
-> InsOrdHashMap Int (Referenced Response)
-> InsOrdHashMap Int (Referenced Response)
forall v1 v2 k.
(v1 -> v2) -> InsOrdHashMap k v1 -> InsOrdHashMap k v2
Map.map (Referenced Response -> Referenced Response -> Referenced Response
forall m. SwaggerMonoid m => m -> m -> m
`swaggerMappend` Response -> Referenced Response
forall a. a -> Referenced a
Inline Response
resp)
OpenApi -> (OpenApi -> OpenApi) -> OpenApi
forall a b. a -> (a -> b) -> b
& (Components -> Identity Components) -> OpenApi -> Identity OpenApi
forall s a. HasComponents s a => Lens' s a
components ((Components -> Identity Components)
-> OpenApi -> Identity OpenApi)
-> ((Definitions Schema -> Identity (Definitions Schema))
-> Components -> Identity Components)
-> (Definitions Schema -> Identity (Definitions Schema))
-> OpenApi
-> Identity OpenApi
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Definitions Schema -> Identity (Definitions Schema))
-> Components -> Identity Components
forall s a. HasSchemas s a => Lens' s a
schemas ((Definitions Schema -> Identity (Definitions Schema))
-> OpenApi -> Identity OpenApi)
-> (Definitions Schema -> Definitions Schema) -> OpenApi -> OpenApi
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Definitions Schema -> Definitions Schema -> Definitions Schema
forall a. Semigroup a => a -> a -> a
<> Definitions Schema
defs)
mergeDoc (CDocResponseHeader Text
headerName Header
header) Tree CompactDocNode
child OpenApi
doc =
Tree CompactDocNode -> OpenApi -> (OpenApi -> OpenApi) -> OpenApi
postOrder Tree CompactDocNode
child OpenApi
doc ((OpenApi -> OpenApi) -> OpenApi)
-> (OpenApi -> OpenApi) -> OpenApi
forall a b. (a -> b) -> a -> b
$ \OpenApi
doc' ->
let resp :: Response
resp = Monoid Response => Response
forall a. Monoid a => a
mempty @Response Response -> (Response -> Response) -> Response
forall a b. a -> (a -> b) -> b
& (InsOrdHashMap Text (Referenced Header)
-> Identity (InsOrdHashMap Text (Referenced Header)))
-> Response -> Identity Response
forall s a. HasHeaders s a => Lens' s a
headers ((InsOrdHashMap Text (Referenced Header)
-> Identity (InsOrdHashMap Text (Referenced Header)))
-> Response -> Identity Response)
-> InsOrdHashMap Text (Referenced Header) -> Response -> Response
forall a s t. Semigroup a => ASetter s t a a -> a -> s -> t
<>~ [(Text
headerName, Header -> Referenced Header
forall a. a -> Referenced a
Inline Header
header)]
in OpenApi
doc' OpenApi -> (OpenApi -> OpenApi) -> OpenApi
forall a b. a -> (a -> b) -> b
& (Operation -> Identity Operation) -> OpenApi -> Identity OpenApi
Traversal' OpenApi Operation
allOperations ((Operation -> Identity Operation) -> OpenApi -> Identity OpenApi)
-> ((InsOrdHashMap Int (Referenced Response)
-> Identity (InsOrdHashMap Int (Referenced Response)))
-> Operation -> Identity Operation)
-> (InsOrdHashMap Int (Referenced Response)
-> Identity (InsOrdHashMap Int (Referenced Response)))
-> OpenApi
-> Identity OpenApi
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Responses -> Identity Responses)
-> Operation -> Identity Operation
forall s a. HasResponses s a => Lens' s a
responses ((Responses -> Identity Responses)
-> Operation -> Identity Operation)
-> ((InsOrdHashMap Int (Referenced Response)
-> Identity (InsOrdHashMap Int (Referenced Response)))
-> Responses -> Identity Responses)
-> (InsOrdHashMap Int (Referenced Response)
-> Identity (InsOrdHashMap Int (Referenced Response)))
-> Operation
-> Identity Operation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (InsOrdHashMap Int (Referenced Response)
-> Identity (InsOrdHashMap Int (Referenced Response)))
-> Responses -> Identity Responses
forall s a. HasResponses s a => Lens' s a
responses ((InsOrdHashMap Int (Referenced Response)
-> Identity (InsOrdHashMap Int (Referenced Response)))
-> OpenApi -> Identity OpenApi)
-> (InsOrdHashMap Int (Referenced Response)
-> InsOrdHashMap Int (Referenced Response))
-> OpenApi
-> OpenApi
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Referenced Response -> Referenced Response)
-> InsOrdHashMap Int (Referenced Response)
-> InsOrdHashMap Int (Referenced Response)
forall v1 v2 k.
(v1 -> v2) -> InsOrdHashMap k v1 -> InsOrdHashMap k v2
Map.map (Referenced Response -> Referenced Response -> Referenced Response
forall m. SwaggerMonoid m => m -> m -> m
`swaggerMappend` Response -> Referenced Response
forall a. a -> Referenced a
Inline Response
resp)
removeOtherMethods :: HTTP.StdMethod -> PathItem -> PathItem
removeOtherMethods :: StdMethod -> PathItem -> PathItem
removeOtherMethods StdMethod
method PathItem{[Server]
[Referenced Param]
Maybe Text
Maybe Operation
_pathItemParameters :: [Referenced Param]
_pathItemServers :: [Server]
_pathItemTrace :: Maybe Operation
_pathItemPatch :: Maybe Operation
_pathItemHead :: Maybe Operation
_pathItemOptions :: Maybe Operation
_pathItemDelete :: Maybe Operation
_pathItemPost :: Maybe Operation
_pathItemPut :: Maybe Operation
_pathItemGet :: Maybe Operation
_pathItemDescription :: Maybe Text
_pathItemSummary :: Maybe Text
_pathItemServers :: PathItem -> [Server]
_pathItemDescription :: PathItem -> Maybe Text
_pathItemSummary :: PathItem -> Maybe Text
_pathItemParameters :: PathItem -> [Referenced Param]
_pathItemTrace :: PathItem -> Maybe Operation
_pathItemPatch :: PathItem -> Maybe Operation
_pathItemHead :: PathItem -> Maybe Operation
_pathItemOptions :: PathItem -> Maybe Operation
_pathItemDelete :: PathItem -> Maybe Operation
_pathItemPost :: PathItem -> Maybe Operation
_pathItemPut :: PathItem -> Maybe Operation
_pathItemGet :: PathItem -> Maybe Operation
..} =
case StdMethod
method of
StdMethod
HTTP.GET -> PathItem
forall a. Monoid a => a
mempty{Maybe Operation
_pathItemGet :: Maybe Operation
_pathItemGet :: Maybe Operation
_pathItemGet, Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary, Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription, [Server]
_pathItemServers :: [Server]
_pathItemServers :: [Server]
_pathItemServers, [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters}
StdMethod
HTTP.PUT -> PathItem
forall a. Monoid a => a
mempty{Maybe Operation
_pathItemPut :: Maybe Operation
_pathItemPut :: Maybe Operation
_pathItemPut, Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary, Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription, [Server]
_pathItemServers :: [Server]
_pathItemServers :: [Server]
_pathItemServers, [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters}
StdMethod
HTTP.POST -> PathItem
forall a. Monoid a => a
mempty{Maybe Operation
_pathItemPost :: Maybe Operation
_pathItemPost :: Maybe Operation
_pathItemPost, Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary, Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription, [Server]
_pathItemServers :: [Server]
_pathItemServers :: [Server]
_pathItemServers, [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters}
StdMethod
HTTP.DELETE -> PathItem
forall a. Monoid a => a
mempty{Maybe Operation
_pathItemDelete :: Maybe Operation
_pathItemDelete :: Maybe Operation
_pathItemDelete, Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary, Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription, [Server]
_pathItemServers :: [Server]
_pathItemServers :: [Server]
_pathItemServers, [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters}
StdMethod
HTTP.HEAD -> PathItem
forall a. Monoid a => a
mempty{Maybe Operation
_pathItemHead :: Maybe Operation
_pathItemHead :: Maybe Operation
_pathItemHead, Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary, Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription, [Server]
_pathItemServers :: [Server]
_pathItemServers :: [Server]
_pathItemServers, [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters}
StdMethod
HTTP.TRACE -> PathItem
forall a. Monoid a => a
mempty{Maybe Operation
_pathItemTrace :: Maybe Operation
_pathItemTrace :: Maybe Operation
_pathItemTrace, Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary, Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription, [Server]
_pathItemServers :: [Server]
_pathItemServers :: [Server]
_pathItemServers, [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters}
StdMethod
HTTP.OPTIONS -> PathItem
forall a. Monoid a => a
mempty{Maybe Operation
_pathItemOptions :: Maybe Operation
_pathItemOptions :: Maybe Operation
_pathItemOptions, Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary, Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription, [Server]
_pathItemServers :: [Server]
_pathItemServers :: [Server]
_pathItemServers, [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters}
StdMethod
HTTP.PATCH -> PathItem
forall a. Monoid a => a
mempty{Maybe Operation
_pathItemPatch :: Maybe Operation
_pathItemPatch :: Maybe Operation
_pathItemPatch, Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary, Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription, [Server]
_pathItemServers :: [Server]
_pathItemServers :: [Server]
_pathItemServers, [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters}
StdMethod
HTTP.CONNECT -> PathItem
forall a. Monoid a => a
mempty{Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary :: Maybe Text
_pathItemSummary, Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription :: Maybe Text
_pathItemDescription, [Server]
_pathItemServers :: [Server]
_pathItemServers :: [Server]
_pathItemServers, [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters :: [Referenced Param]
_pathItemParameters}