@@ -31,6 +31,10 @@ prependPath path = paths %~ mapKeys (path </>)
32 trim = dropWhile (== '/') . dropWhileEnd (== '/')
32 trim = dropWhile (== '/') . dropWhileEnd (== '/')
34+-- | All operations of a Swagger spec.
35+allOperations :: Traversal' Swagger Operation
36+allOperations = paths.traverse.template
35-- >>> import Data.Aeson
39-- >>> import Data.Aeson
36-- >>> import Data.Proxy
40-- >>> import Data.Proxy
@@ -66,9 +70,9 @@ operationsOf sub = paths.itraversed.withIndex.subops
67-- | Apply tags to a part of Swagger spec and update the global
71-- | Apply tags to a part of Swagger spec and update the global
68-- list of tags.
72-- list of tags.
69−applyTagsFor :: Swagger -> [Tag] -> Swagger -> Swagger
73+applyTagsFor :: Traversal' Swagger Operation -> [Tag] -> Swagger -> Swagger
70−applyTagsFor sub ts swag = swag
74+applyTagsFor ops ts swag = swag
71− & operationsOf sub . tags %~ (map _tagName ts ++)
75+ & ops . tags %~ (map _tagName ts ++)
72 & tags %~ (ts ++)
76 & tags %~ (ts ++)
74-- | Construct a response with @'Schema'@ while declaring all
78-- | Construct a response with @'Schema'@ while declaring all
@@ -81,17 +85,17 @@ declareResponse proxy = do
81 s <- declareSchemaRef proxy
85 s <- declareSchemaRef proxy
82 return (mempty & schema ?~ s)
86 return (mempty & schema ?~ s)
84−-- | Set response for all operations of a subspec.
88+-- | Set response for specified operations.
85-- This will also update global schema definitions.
89-- This will also update global schema definitions.
87-- >>> let api = (mempty :: Swagger) & paths .~ [("/user", mempty & get ?~ mempty)]
91-- >>> let api = (mempty :: Swagger) & paths .~ [("/user", mempty & get ?~ mempty)]
88-- >>> let res = declareResponse (Proxy :: Proxy Day)
92-- >>> let res = declareResponse (Proxy :: Proxy Day)
89−-- >>> encode $ api & setResponseFor api 200 res
93+-- >>> encode $ api & setResponseFor allOperations 200 res
90-- "{\"swagger\":\"2.0\",\"info\":{\"version\":\"\",\"title\":\"\"},\"definitions\":{\"Day\":{\"format\":\"date\",\"type\":\"string\"}},\"paths\":{\"/user\":{\"get\":{\"responses\":{\"200\":{\"schema\":{\"$ref\":\"#/definitions/Day\"},\"description\":\"\"}}}}}}"
94-- "{\"swagger\":\"2.0\",\"info\":{\"version\":\"\",\"title\":\"\"},\"definitions\":{\"Day\":{\"format\":\"date\",\"type\":\"string\"}},\"paths\":{\"/user\":{\"get\":{\"responses\":{\"200\":{\"schema\":{\"$ref\":\"#/definitions/Day\"},\"description\":\"\"}}}}}}"
91−setResponseFor :: Swagger -> HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger
95+setResponseFor :: Traversal' Swagger Operation -> HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger
92−setResponseFor sub code dres swag = swag
96+setResponseFor ops code dres swag = swag
93 & definitions %~ (<> defs)
97 & definitions %~ (<> defs)
94− & operationsOf sub . at code ?~ Inline res
98+ & ops . at code ?~ Inline res
96 (defs, res) = runDeclare dres mempty
100 (defs, res) = runDeclare dres mempty