{-# LANGUAGE RankNTypes #-}
module Data.Swagger.Operation (
allOperations,
operationsOf,
applyTags,
applyTagsFor,
addExtensions,
addExtensionsFor,
setResponse,
setResponseWith,
setResponseFor,
setResponseForWith,
prependPath,
declareResponse,
) where
import Prelude ()
import Prelude.Compat
import Control.Lens
import Data.Aeson (Value)
import Data.Data.Lens
import Data.List.Compat
import Data.Maybe (mapMaybe)
import Data.Proxy
import qualified Data.Set as Set
import Data.Text (Text)
import Data.Swagger.Declare
import Data.Swagger.Internal
import Data.Swagger.Lens
import Data.Swagger.Schema
import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
import Data.HashMap.Strict.InsOrd (InsOrdHashMap)
import qualified Data.HashSet.InsOrd as InsOrdHS
prependPath :: FilePath -> Swagger -> Swagger
prependPath :: FilePath -> Swagger -> Swagger
prependPath FilePath
path = (InsOrdHashMap FilePath PathItem
-> Identity (InsOrdHashMap FilePath PathItem))
-> Swagger -> Identity Swagger
forall s a. HasPaths s a => Lens' s a
paths ((InsOrdHashMap FilePath PathItem
-> Identity (InsOrdHashMap FilePath PathItem))
-> Swagger -> Identity Swagger)
-> (InsOrdHashMap FilePath PathItem
-> InsOrdHashMap FilePath PathItem)
-> Swagger
-> Swagger
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (FilePath -> FilePath)
-> InsOrdHashMap FilePath PathItem
-> InsOrdHashMap FilePath PathItem
forall k' k v.
(Eq k', Hashable k') =>
(k -> k') -> InsOrdHashMap k v -> InsOrdHashMap k' v
InsOrdHashMap.mapKeys (FilePath
path FilePath -> FilePath -> FilePath
</>)
where
FilePath
x </> :: FilePath -> FilePath -> FilePath
</> FilePath
y = case FilePath -> FilePath
trim FilePath
y of
FilePath
"" -> FilePath
"/" FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath -> FilePath
trim FilePath
x
FilePath
y' -> FilePath
"/" FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath -> FilePath
trim FilePath
x FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath
"/" FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath
y'
trim :: FilePath -> FilePath
trim = (Char -> Bool) -> FilePath -> FilePath
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'/') (FilePath -> FilePath)
-> (FilePath -> FilePath) -> FilePath -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> FilePath -> FilePath
forall a. (a -> Bool) -> [a] -> [a]
dropWhileEnd (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'/')
allOperations :: Traversal' Swagger Operation
allOperations :: (Operation -> f Operation) -> Swagger -> f Swagger
allOperations = (InsOrdHashMap FilePath PathItem
-> f (InsOrdHashMap FilePath PathItem))
-> Swagger -> f Swagger
forall s a. HasPaths s a => Lens' s a
paths((InsOrdHashMap FilePath PathItem
-> f (InsOrdHashMap FilePath PathItem))
-> Swagger -> f Swagger)
-> ((Operation -> f Operation)
-> InsOrdHashMap FilePath PathItem
-> f (InsOrdHashMap FilePath PathItem))
-> (Operation -> f Operation)
-> Swagger
-> f Swagger
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(PathItem -> f PathItem)
-> InsOrdHashMap FilePath PathItem
-> f (InsOrdHashMap FilePath PathItem)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse((PathItem -> f PathItem)
-> InsOrdHashMap FilePath PathItem
-> f (InsOrdHashMap FilePath PathItem))
-> ((Operation -> f Operation) -> PathItem -> f PathItem)
-> (Operation -> f Operation)
-> InsOrdHashMap FilePath PathItem
-> f (InsOrdHashMap FilePath PathItem)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Operation -> f Operation) -> PathItem -> f PathItem
forall s a. (Data s, Typeable a) => Traversal' s a
template
operationsOf :: Swagger -> Traversal' Swagger Operation
operationsOf :: Swagger -> Traversal' Swagger Operation
operationsOf Swagger
sub = (InsOrdHashMap FilePath PathItem
-> f (InsOrdHashMap FilePath PathItem))
-> Swagger -> f Swagger
forall s a. HasPaths s a => Lens' s a
paths((InsOrdHashMap FilePath PathItem
-> f (InsOrdHashMap FilePath PathItem))
-> Swagger -> f Swagger)
-> ((Operation -> f Operation)
-> InsOrdHashMap FilePath PathItem
-> f (InsOrdHashMap FilePath PathItem))
-> (Operation -> f Operation)
-> Swagger
-> f Swagger
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Indexed FilePath PathItem (f PathItem)
-> InsOrdHashMap FilePath PathItem
-> f (InsOrdHashMap FilePath PathItem)
forall i (t :: * -> *) a b.
TraversableWithIndex i t =>
IndexedTraversal i (t a) (t b) a b
itraversed(Indexed FilePath PathItem (f PathItem)
-> InsOrdHashMap FilePath PathItem
-> f (InsOrdHashMap FilePath PathItem))
-> ((Operation -> f Operation)
-> Indexed FilePath PathItem (f PathItem))
-> (Operation -> f Operation)
-> InsOrdHashMap FilePath PathItem
-> f (InsOrdHashMap FilePath PathItem)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.((FilePath, PathItem) -> f (FilePath, PathItem))
-> Indexed FilePath PathItem (f PathItem)
forall i (p :: * -> * -> *) (f :: * -> *) s j t.
(Indexable i p, Functor f) =>
p (i, s) (f (j, t)) -> Indexed i s (f t)
withIndex(((FilePath, PathItem) -> f (FilePath, PathItem))
-> Indexed FilePath PathItem (f PathItem))
-> ((Operation -> f Operation)
-> (FilePath, PathItem) -> f (FilePath, PathItem))
-> (Operation -> f Operation)
-> Indexed FilePath PathItem (f PathItem)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Operation -> f Operation)
-> (FilePath, PathItem) -> f (FilePath, PathItem)
Traversal' (FilePath, PathItem) Operation
subops
where
subops :: Traversal' (FilePath, PathItem) Operation
subops :: (Operation -> f Operation)
-> (FilePath, PathItem) -> f (FilePath, PathItem)
subops Operation -> f Operation
f (FilePath
path, PathItem
item) = case FilePath -> InsOrdHashMap FilePath PathItem -> Maybe PathItem
forall k v. (Eq k, Hashable k) => k -> InsOrdHashMap k v -> Maybe v
InsOrdHashMap.lookup FilePath
path (Swagger
sub Swagger
-> Getting
(InsOrdHashMap FilePath PathItem)
Swagger
(InsOrdHashMap FilePath PathItem)
-> InsOrdHashMap FilePath PathItem
forall s a. s -> Getting a s a -> a
^. Getting
(InsOrdHashMap FilePath PathItem)
Swagger
(InsOrdHashMap FilePath PathItem)
forall s a. HasPaths s a => Lens' s a
paths) of
Just PathItem
subitem -> (,) FilePath
path (PathItem -> (FilePath, PathItem))
-> f PathItem -> f (FilePath, PathItem)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PathItem -> (Operation -> f Operation) -> PathItem -> f PathItem
PathItem -> Traversal' PathItem Operation
methodsOf PathItem
subitem Operation -> f Operation
f PathItem
item
Maybe PathItem
Nothing -> (FilePath, PathItem) -> f (FilePath, PathItem)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (FilePath
path, PathItem
item)
methodsOf :: PathItem -> Traversal' PathItem Operation
methodsOf :: PathItem -> Traversal' PathItem Operation
methodsOf PathItem
pathItem = Traversing
(->) f PathItem PathItem (Maybe Operation) (Maybe Operation)
-> LensLike f PathItem PathItem [Maybe Operation] [Maybe Operation]
forall (f :: * -> *) s t a.
Functor f =>
Traversing (->) f s t a a -> LensLike f s t [a] [a]
partsOf Traversing
(->) f PathItem PathItem (Maybe Operation) (Maybe Operation)
forall s a. (Data s, Typeable a) => Traversal' s a
template LensLike f PathItem PathItem [Maybe Operation] [Maybe Operation]
-> ((Operation -> f Operation)
-> [Maybe Operation] -> f [Maybe Operation])
-> (Operation -> f Operation)
-> PathItem
-> f PathItem
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Indexed Int (Maybe Operation) (f (Maybe Operation))
-> [Maybe Operation] -> f [Maybe Operation]
forall i (t :: * -> *) a b.
TraversableWithIndex i t =>
IndexedTraversal i (t a) (t b) a b
itraversed (Indexed Int (Maybe Operation) (f (Maybe Operation))
-> [Maybe Operation] -> f [Maybe Operation])
-> ((Operation -> f Operation)
-> Indexed Int (Maybe Operation) (f (Maybe Operation)))
-> (Operation -> f Operation)
-> [Maybe Operation]
-> f [Maybe Operation]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Bool)
-> Optical'
(->) (Indexed Int) f (Maybe Operation) (Maybe Operation)
forall i (p :: * -> * -> *) (f :: * -> *) a.
(Indexable i p, Applicative f) =>
(i -> Bool) -> Optical' p (Indexed i) f a a
indices (Int -> [Int] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Int]
ns) Optical' (->) (Indexed Int) f (Maybe Operation) (Maybe Operation)
-> ((Operation -> f Operation)
-> Maybe Operation -> f (Maybe Operation))
-> (Operation -> f Operation)
-> Indexed Int (Maybe Operation) (f (Maybe Operation))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Operation -> f Operation)
-> Maybe Operation -> f (Maybe Operation)
forall a b. Prism (Maybe a) (Maybe b) a b
_Just
where
ops :: [Maybe Operation]
ops = PathItem
pathItem PathItem
-> Getting (Endo [Maybe Operation]) PathItem (Maybe Operation)
-> [Maybe Operation]
forall s a. s -> Getting (Endo [a]) s a -> [a]
^.. Getting (Endo [Maybe Operation]) PathItem (Maybe Operation)
forall s a. (Data s, Typeable a) => Traversal' s a
template :: [Maybe Operation]
ns :: [Int]
ns = ((Int, Maybe Operation) -> Maybe Int)
-> [(Int, Maybe Operation)] -> [Int]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (((Int, Operation) -> Int) -> Maybe (Int, Operation) -> Maybe Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int, Operation) -> Int
forall a b. (a, b) -> a
fst (Maybe (Int, Operation) -> Maybe Int)
-> ((Int, Maybe Operation) -> Maybe (Int, Operation))
-> (Int, Maybe Operation)
-> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, Maybe Operation) -> Maybe (Int, Operation)
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA) ([(Int, Maybe Operation)] -> [Int])
-> [(Int, Maybe Operation)] -> [Int]
forall a b. (a -> b) -> a -> b
$ [Int] -> [Maybe Operation] -> [(Int, Maybe Operation)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0..] [Maybe Operation]
ops
applyTags :: [Tag] -> Swagger -> Swagger
applyTags :: [Tag] -> Swagger -> Swagger
applyTags = Traversal' Swagger Operation -> [Tag] -> Swagger -> Swagger
applyTagsFor Traversal' Swagger Operation
allOperations
addExtensions :: (Value -> Value -> Value) -> InsOrdHashMap Text Value -> Swagger -> Swagger
addExtensions :: (Value -> Value -> Value)
-> InsOrdHashMap Text Value -> Swagger -> Swagger
addExtensions = Traversal' Swagger Operation
-> (Value -> Value -> Value)
-> InsOrdHashMap Text Value
-> Swagger
-> Swagger
addExtensionsFor Traversal' Swagger Operation
allOperations
addExtensionsFor :: Traversal' Swagger Operation -> (Value -> Value -> Value) -> InsOrdHashMap Text Value -> Swagger -> Swagger
addExtensionsFor :: Traversal' Swagger Operation
-> (Value -> Value -> Value)
-> InsOrdHashMap Text Value
-> Swagger
-> Swagger
addExtensionsFor Traversal' Swagger Operation
ops Value -> Value -> Value
merge InsOrdHashMap Text Value
add Swagger
swag = Swagger
swag
Swagger -> (Swagger -> Swagger) -> Swagger
forall a b. a -> (a -> b) -> b
& (Operation -> Identity Operation) -> Swagger -> Identity Swagger
Traversal' Swagger Operation
ops ((Operation -> Identity Operation) -> Swagger -> Identity Swagger)
-> ((InsOrdHashMap Text Value
-> Identity (InsOrdHashMap Text Value))
-> Operation -> Identity Operation)
-> (InsOrdHashMap Text Value
-> Identity (InsOrdHashMap Text Value))
-> Swagger
-> Identity Swagger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (InsOrdHashMap Text Value -> Identity (InsOrdHashMap Text Value))
-> Operation -> Identity Operation
forall s a. HasExtensions s a => Lens' s a
extensions ((InsOrdHashMap Text Value -> Identity (InsOrdHashMap Text Value))
-> Swagger -> Identity Swagger)
-> (InsOrdHashMap Text Value -> InsOrdHashMap Text Value)
-> Swagger
-> Swagger
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Value -> Value -> Value)
-> InsOrdHashMap Text Value
-> InsOrdHashMap Text Value
-> InsOrdHashMap Text Value
forall k v.
(Eq k, Hashable k) =>
(v -> v -> v)
-> InsOrdHashMap k v -> InsOrdHashMap k v -> InsOrdHashMap k v
InsOrdHashMap.unionWith Value -> Value -> Value
merge InsOrdHashMap Text Value
add
applyTagsFor :: Traversal' Swagger Operation -> [Tag] -> Swagger -> Swagger
applyTagsFor :: Traversal' Swagger Operation -> [Tag] -> Swagger -> Swagger
applyTagsFor Traversal' Swagger Operation
ops [Tag]
ts Swagger
swag = Swagger
swag
Swagger -> (Swagger -> Swagger) -> Swagger
forall a b. a -> (a -> b) -> b
& (Operation -> Identity Operation) -> Swagger -> Identity Swagger
Traversal' Swagger Operation
ops ((Operation -> Identity Operation) -> Swagger -> Identity Swagger)
-> ((InsOrdHashSet Text -> Identity (InsOrdHashSet Text))
-> Operation -> Identity Operation)
-> (InsOrdHashSet Text -> Identity (InsOrdHashSet Text))
-> Swagger
-> Identity Swagger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (InsOrdHashSet Text -> Identity (InsOrdHashSet Text))
-> Operation -> Identity Operation
forall s a. HasTags s a => Lens' s a
tags ((InsOrdHashSet Text -> Identity (InsOrdHashSet Text))
-> Swagger -> Identity Swagger)
-> (InsOrdHashSet Text -> InsOrdHashSet Text) -> Swagger -> Swagger
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (InsOrdHashSet Text -> InsOrdHashSet Text -> InsOrdHashSet Text
forall a. Semigroup a => a -> a -> a
<> [Text] -> InsOrdHashSet Text
forall k. (Eq k, Hashable k) => [k] -> InsOrdHashSet k
InsOrdHS.fromList ((Tag -> Text) -> [Tag] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Tag -> Text
_tagName [Tag]
ts))
Swagger -> (Swagger -> Swagger) -> Swagger
forall a b. a -> (a -> b) -> b
& (InsOrdHashSet Tag -> Identity (InsOrdHashSet Tag))
-> Swagger -> Identity Swagger
forall s a. HasTags s a => Lens' s a
tags ((InsOrdHashSet Tag -> Identity (InsOrdHashSet Tag))
-> Swagger -> Identity Swagger)
-> (InsOrdHashSet Tag -> InsOrdHashSet Tag) -> Swagger -> Swagger
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (InsOrdHashSet Tag -> InsOrdHashSet Tag -> InsOrdHashSet Tag
forall a. Semigroup a => a -> a -> a
<> [Tag] -> InsOrdHashSet Tag
forall k. (Eq k, Hashable k) => [k] -> InsOrdHashSet k
InsOrdHS.fromList [Tag]
ts)
declareResponse :: ToSchema a => Proxy a -> Declare (Definitions Schema) Response
declareResponse :: Proxy a -> Declare (Definitions Schema) Response
declareResponse Proxy a
proxy = do
Referenced Schema
s <- Proxy a -> Declare (Definitions Schema) (Referenced Schema)
forall a.
ToSchema a =>
Proxy a -> Declare (Definitions Schema) (Referenced Schema)
declareSchemaRef Proxy a
proxy
Response -> Declare (Definitions Schema) Response
forall (m :: * -> *) a. Monad m => a -> m a
return (Response
forall a. Monoid a => a
mempty Response -> (Response -> Response) -> Response
forall a b. a -> (a -> b) -> b
& (Maybe (Referenced Schema) -> Identity (Maybe (Referenced Schema)))
-> Response -> Identity Response
forall s a. HasSchema s a => Lens' s a
schema ((Maybe (Referenced Schema)
-> Identity (Maybe (Referenced Schema)))
-> Response -> Identity Response)
-> Referenced Schema -> Response -> Response
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Referenced Schema
s)
setResponse :: HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger
setResponse :: Int -> Declare (Definitions Schema) Response -> Swagger -> Swagger
setResponse = Traversal' Swagger Operation
-> Int
-> Declare (Definitions Schema) Response
-> Swagger
-> Swagger
setResponseFor Traversal' Swagger Operation
allOperations
setResponseWith :: (Response -> Response -> Response) -> HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger
setResponseWith :: (Response -> Response -> Response)
-> Int
-> Declare (Definitions Schema) Response
-> Swagger
-> Swagger
setResponseWith = Traversal' Swagger Operation
-> (Response -> Response -> Response)
-> Int
-> Declare (Definitions Schema) Response
-> Swagger
-> Swagger
setResponseForWith Traversal' Swagger Operation
allOperations
setResponseFor :: Traversal' Swagger Operation -> HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger
setResponseFor :: Traversal' Swagger Operation
-> Int
-> Declare (Definitions Schema) Response
-> Swagger
-> Swagger
setResponseFor Traversal' Swagger Operation
ops Int
code Declare (Definitions Schema) Response
dres Swagger
swag = Swagger
swag
Swagger -> (Swagger -> Swagger) -> Swagger
forall a b. a -> (a -> b) -> b
& (Definitions Schema -> Identity (Definitions Schema))
-> Swagger -> Identity Swagger
forall s a. HasDefinitions s a => Lens' s a
definitions ((Definitions Schema -> Identity (Definitions Schema))
-> Swagger -> Identity Swagger)
-> (Definitions Schema -> Definitions Schema) -> Swagger -> Swagger
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)
Swagger -> (Swagger -> Swagger) -> Swagger
forall a b. a -> (a -> b) -> b
& (Operation -> Identity Operation) -> Swagger -> Identity Swagger
Traversal' Swagger Operation
ops ((Operation -> Identity Operation) -> Swagger -> Identity Swagger)
-> ((Maybe (Referenced Response)
-> Identity (Maybe (Referenced Response)))
-> Operation -> Identity Operation)
-> (Maybe (Referenced Response)
-> Identity (Maybe (Referenced Response)))
-> Swagger
-> Identity Swagger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index Operation -> Lens' Operation (Maybe (IxValue Operation))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at Int
Index Operation
code ((Maybe (Referenced Response)
-> Identity (Maybe (Referenced Response)))
-> Swagger -> Identity Swagger)
-> Referenced Response -> Swagger -> Swagger
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Response -> Referenced Response
forall a. a -> Referenced a
Inline Response
res
where
(Definitions Schema
defs, Response
res) = Declare (Definitions Schema) Response
-> Definitions Schema -> (Definitions Schema, Response)
forall d a. Declare d a -> d -> (d, a)
runDeclare Declare (Definitions Schema) Response
dres Definitions Schema
forall a. Monoid a => a
mempty
setResponseForWith :: Traversal' Swagger Operation -> (Response -> Response -> Response) -> HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger
setResponseForWith :: Traversal' Swagger Operation
-> (Response -> Response -> Response)
-> Int
-> Declare (Definitions Schema) Response
-> Swagger
-> Swagger
setResponseForWith Traversal' Swagger Operation
ops Response -> Response -> Response
f Int
code Declare (Definitions Schema) Response
dres Swagger
swag = Swagger
swag
Swagger -> (Swagger -> Swagger) -> Swagger
forall a b. a -> (a -> b) -> b
& (Definitions Schema -> Identity (Definitions Schema))
-> Swagger -> Identity Swagger
forall s a. HasDefinitions s a => Lens' s a
definitions ((Definitions Schema -> Identity (Definitions Schema))
-> Swagger -> Identity Swagger)
-> (Definitions Schema -> Definitions Schema) -> Swagger -> Swagger
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)
Swagger -> (Swagger -> Swagger) -> Swagger
forall a b. a -> (a -> b) -> b
& (Operation -> Identity Operation) -> Swagger -> Identity Swagger
Traversal' Swagger Operation
ops ((Operation -> Identity Operation) -> Swagger -> Identity Swagger)
-> ((Maybe (Referenced Response)
-> Identity (Maybe (Referenced Response)))
-> Operation -> Identity Operation)
-> (Maybe (Referenced Response)
-> Identity (Maybe (Referenced Response)))
-> Swagger
-> Identity Swagger
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index Operation -> Lens' Operation (Maybe (IxValue Operation))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at Int
Index Operation
code ((Maybe (Referenced Response)
-> Identity (Maybe (Referenced Response)))
-> Swagger -> Identity Swagger)
-> (Maybe (Referenced Response) -> Maybe (Referenced Response))
-> Swagger
-> Swagger
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Referenced Response -> Maybe (Referenced Response)
forall a. a -> Maybe a
Just (Referenced Response -> Maybe (Referenced Response))
-> (Maybe (Referenced Response) -> Referenced Response)
-> Maybe (Referenced Response)
-> Maybe (Referenced Response)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response -> Referenced Response
forall a. a -> Referenced a
Inline (Response -> Referenced Response)
-> (Maybe (Referenced Response) -> Response)
-> Maybe (Referenced Response)
-> Referenced Response
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe (Referenced Response) -> Response
combine
where
(Definitions Schema
defs, Response
new) = Declare (Definitions Schema) Response
-> Definitions Schema -> (Definitions Schema, Response)
forall d a. Declare d a -> d -> (d, a)
runDeclare Declare (Definitions Schema) Response
dres Definitions Schema
forall a. Monoid a => a
mempty
combine :: Maybe (Referenced Response) -> Response
combine (Just (Ref (Reference Text
n))) = case Swagger
swag Swagger
-> Getting (Maybe Response) Swagger (Maybe Response)
-> Maybe Response
forall s a. s -> Getting a s a -> a
^. (Definitions Response
-> Const (Maybe Response) (Definitions Response))
-> Swagger -> Const (Maybe Response) Swagger
forall s a. HasResponses s a => Lens' s a
responses((Definitions Response
-> Const (Maybe Response) (Definitions Response))
-> Swagger -> Const (Maybe Response) Swagger)
-> ((Maybe Response -> Const (Maybe Response) (Maybe Response))
-> Definitions Response
-> Const (Maybe Response) (Definitions Response))
-> Getting (Maybe Response) Swagger (Maybe Response)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Index (Definitions Response)
-> Lens'
(Definitions Response) (Maybe (IxValue (Definitions Response)))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at Text
Index (Definitions Response)
n of
Just Response
old -> Response -> Response -> Response
f Response
old Response
new
Maybe Response
Nothing -> Response
new
combine (Just (Inline Response
old)) = Response -> Response -> Response
f Response
old Response
new
combine Maybe (Referenced Response)
Nothing = Response
new