@@ -39,6 +39,7 @@ import Data.List.Compat
3939import Data.Maybe (mapMaybe)
4040import Data.Proxy
4141import qualified Data.Set as Set
42+import Data.Text (Text)
4243
4344import Data.Swagger.Declare
4445import Data.Swagger.Internal
@@ -118,12 +119,14 @@ applyTagsFor ops ts swag = swag
118119-- | Construct a response with @'Schema'@ while declaring all
119120-- necessary schema definitions.
120121--
122+-- FIXME doc
123+--
121124-- >>> encode $ runDeclare (declareResponse (Proxy :: Proxy Day)) mempty
122125-- "[{\"Day\":{\"example\":\"2016-07-22\",\"format\":\"date\",\"type\":\"string\"}},{\"description\":\"\",\"schema\":{\"$ref\":\"#/definitions/Day\"}}]"
123−declareResponse :: ToSchema a => Proxy a -> Declare (Definitions Schema) Response
124−declareResponse proxy = do
126+declareResponse :: ToSchema a => Text -> Proxy a -> Declare (Definitions Schema) Response
127+declareResponse cType proxy = do
125128 s <- declareSchemaRef proxy
126− return (mempty & schema ?~ s)
129+ return (mempty & content.at cType ?~ (mempty & schema ?~ s))
127130
128131-- | Set response for all operations.
129132-- This will also update global schema definitions.
@@ -167,7 +170,7 @@ setResponseWith = setResponseForWith allOperations
167170-- See also @'setResponseForWith'@.
168171setResponseFor :: Traversal' Swagger Operation -> HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger
169172setResponseFor ops code dres swag = swag
170− & definitions %~ (<> defs)
173+ & components.schemas %~ (<> defs)
171174 & ops . at code ?~ Inline res
172175 where
173176 (defs, res) = runDeclare dres mempty
@@ -181,12 +184,12 @@ setResponseFor ops code dres swag = swag
181184-- See also @'setResponseFor'@.
182185setResponseForWith :: Traversal' Swagger Operation -> (Response -> Response -> Response) -> HttpStatusCode -> Declare (Definitions Schema) Response -> Swagger -> Swagger
183186setResponseForWith ops f code dres swag = swag
184− & definitions %~ (<> defs)
187+ & components.schemas %~ (<> defs)
185188 & ops . at code %~ Just . Inline . combine
186189 where
187190 (defs, new) = runDeclare dres mempty
188191
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
190193 Just old -> f old new
191194 Nothing -> new -- response name can't be dereferenced, replacing with new response
192195 combine (Just (Inline old)) = f old new