git.iko.soy/typeable/openapi3
on master help sign in
Update Operations.hs
eadb30aMaxim Koltsov
src/Data/Swagger/Operation.hs+9−6
@@ -39,6 +39,7 @@ import Data.List.Compat
39import Data.Maybe (mapMaybe)
39import Data.Maybe (mapMaybe)
40import Data.Proxy
40import Data.Proxy
41import qualified Data.Set as Set
41import qualified Data.Set as Set
42+import Data.Text (Text)
42
43
43import Data.Swagger.Declare
44import Data.Swagger.Declare
44import Data.Swagger.Internal
45import Data.Swagger.Internal
@@ -118,12 +119,14 @@ applyTagsFor ops ts swag = swag
118-- | Construct a response with @'Schema'@ while declaring all
119-- | Construct a response with @'Schema'@ while declaring all
119-- necessary schema definitions.
120-- necessary schema definitions.
120--
121--
122+-- FIXME doc
123+--
121-- >>> encode $ runDeclare (declareResponse (Proxy :: Proxy Day)) mempty
124-- >>> encode $ runDeclare (declareResponse (Proxy :: Proxy Day)) mempty
122-- "[{\"Day\":{\"example\":\"2016-07-22\",\"format\":\"date\",\"type\":\"string\"}},{\"description\":\"\",\"schema\":{\"$ref\":\"#/definitions/Day\"}}]"
125-- "[{\"Day\":{\"example\":\"2016-07-22\",\"format\":\"date\",\"type\":\"string\"}},{\"description\":\"\",\"schema\":{\"$ref\":\"#/definitions/Day\"}}]"
123−declareResponse :: ToSchema a => Proxy a -> Declare (Definitions Schema) Response
126+declareResponse :: ToSchema a => Text -> Proxy a -> Declare (Definitions Schema) Response
124−declareResponse proxy = do
127+declareResponse cType proxy = do
125 s <- declareSchemaRef proxy
128 s <- declareSchemaRef proxy
126− return (mempty & schema ?~ s)
129+ return (mempty & content.at cType ?~ (mempty & schema ?~ s))
127
130
128-- | Set response for all operations.
131-- | Set response for all operations.
129-- This will also update global schema definitions.
132-- This will also update global schema definitions.
@@ -167,7 +170,7 @@ setResponseWith = setResponseForWith allOperations
167-- See also @'setResponseForWith'@.
170-- See also @'setResponseForWith'@.
168setResponseFor :: Traversal' Swagger Operation -> HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger
171setResponseFor :: Traversal' Swagger Operation -> HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger
169setResponseFor ops code dres swag = swag
172setResponseFor ops code dres swag = swag
170− & definitions %~ (<> defs)
173+ & components.schemas %~ (<> defs)
171 & ops . at code ?~ Inline res
174 & ops . at code ?~ Inline res
172 where
175 where
173 (defs, res) = runDeclare dres mempty
176 (defs, res) = runDeclare dres mempty
@@ -181,12 +184,12 @@ setResponseFor ops code dres swag = swag
181-- See also @'setResponseFor'@.
184-- See also @'setResponseFor'@.
182setResponseForWith :: Traversal' Swagger Operation -> (Response -> Response -> Response) -> HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger
185setResponseForWith :: Traversal' Swagger Operation -> (Response -> Response -> Response) -> HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger
183setResponseForWith ops f code dres swag = swag
186setResponseForWith ops f code dres swag = swag
184− & definitions %~ (<> defs)
187+ & components.schemas %~ (<> defs)
185 & ops . at code %~ Just . Inline . combine
188 & ops . at code %~ Just . Inline . combine
186 where
189 where
187 (defs, new) = runDeclare dres mempty
190 (defs, new) = runDeclare dres mempty
188
191
189− combine (Just (Ref (Reference n))) = case swag ^. responses.at n of
192+ combine (Just (Ref (Reference n))) = case swag ^. components.responses.at n of
190 Just old -> f old new
193 Just old -> f old new
191 Nothing -> new -- response name can't be dereferenced, replacing with new response
194 Nothing -> new -- response name can't be dereferenced, replacing with new response
192 combine (Just (Inline old)) = f old new
195 combine (Just (Inline old)) = f old new