HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduleswagger2-2.9.1Haskell2010

Data.Swagger.Operation

Helper traversals and functions for Swagger operations manipulations. These might be useful when you already have Swagger specification generated by something else.

Contents
  1. Operation traversals
  2. Manipulation
  3. Tags
  4. Extensions
  5. Responses
  6. Paths
  7. Miscellaneous
Synopsis
  • Packageswagger2-2.9.1
  • Exports12
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceOperation.hs

Operation traversals

operationsOf sub will traverse only those operations that are present in sub. Note that Operation is determined by both path and method.

Example5 expressions
let ok = (mempty :: Operation) & at 200 ?~ "OK"let api = (mempty :: Swagger) & paths .~ IOHM.fromList [("/user", mempty & get ?~ ok & post ?~ ok)]let sub = (mempty :: Swagger) & paths .~ IOHM.fromList [("/user", mempty & get ?~ mempty)]encode api"{\"swagger\":\"2.0\",\"info\":{\"title\":\"\",\"version\":\"\"},\"paths\":{\"/user\":{\"get\":{\"responses\":{\"200\":{\"description\":\"OK\"}}},\"post\":{\"responses\":{\"200\":{\"description\":\"OK\"}}}}}}"encode $ api & operationsOf sub . at 404 ?~ "Not found""{\"swagger\":\"2.0\",\"info\":{\"title\":\"\",\"version\":\"\"},\"paths\":{\"/user\":{\"get\":{\"responses\":{\"200\":{\"description\":\"OK\"},\"404\":{\"description\":\"Not found\"}}},\"post\":{\"responses\":{\"200\":{\"description\":\"OK\"}}}}}}"

Manipulation

Tags

Extensions

Responses

Set response for all operations. This will also update global schema definitions.

If the response already exists it will be overwritten.

setResponse = setResponseFor allOperations

Example:

Example3 expressions
let api = (mempty :: Swagger) & paths .~ IOHM.fromList [("/user", mempty & get ?~ mempty)]let res = declareResponse (Proxy :: Proxy Day)encode $ api & setResponse 200 res"{\"swagger\":\"2.0\",\"info\":{\"title\":\"\",\"version\":\"\"},\"paths\":{\"/user\":{\"get\":{\"responses\":{\"200\":{\"description\":\"\",\"schema\":{\"$ref\":\"#/definitions/Day\"}}}}}},\"definitions\":{\"Day\":{\"example\":\"2016-07-22\",\"format\":\"date\",\"type\":\"string\"}}}"

See also setResponseWith.

Paths

Prepend path piece to all operations of the spec. Leading and trailing slashes are trimmed/added automatically.

Example2 expressions
let api = (mempty :: Swagger) & paths .~ IOHM.fromList [("/info", mempty)]encode $ prependPath "user/{user_id}" api ^. paths"{\"/user/{user_id}/info\":{}}"

Miscellaneous

Construct a response with Schema while declaring all necessary schema definitions.

Example1 expression
encode $ runDeclare (declareResponse (Proxy :: Proxy Day)) mempty"[{\"Day\":{\"example\":\"2016-07-22\",\"format\":\"date\",\"type\":\"string\"}},{\"description\":\"\",\"schema\":{\"$ref\":\"#/definitions/Day\"}}]"