HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleopenapi3-3.2.4Haskell2010

Data.OpenApi.Operation

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

  • 10 values
  • Packageopenapi3-3.2.4
  • Exports10
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceOperation.hs

Operation traversals

2 declarations

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 :: OpenApi) & paths .~ IOHM.fromList [("/user", mempty & get ?~ ok & post ?~ ok)]let sub = (mempty :: OpenApi) & paths .~ IOHM.fromList [("/user", mempty & get ?~ mempty)]BSL.putStrLn $ encodePretty api{    "components": {},    "info": {        "title": "",        "version": ""    },    "openapi": "3.0.0",    "paths": {        "/user": {            "get": {                "responses": {                    "200": {                        "description": "OK"                    }                }            },            "post": {                "responses": {                    "200": {                        "description": "OK"                    }                }            }        }    }}BSL.putStrLn $ encodePretty $ api & operationsOf sub . at 404 ?~ "Not found"{    "components": {},    "info": {        "title": "",        "version": ""    },    "openapi": "3.0.0",    "paths": {        "/user": {            "get": {                "responses": {                    "200": {                        "description": "OK"                    },                    "404": {                        "description": "Not found"                    }                }            },            "post": {                "responses": {                    "200": {                        "description": "OK"                    }                }            }        }    }}

Manipulation

0 declarations

Tags

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 :: OpenApi) & paths .~ IOHM.fromList [("/user", mempty & get ?~ mempty)]let res = declareResponse "application/json" (Proxy :: Proxy Day)BSL.putStrLn $ encodePretty $ api & setResponse 200 res{    "components": {        "schemas": {            "Day": {                "example": "2016-07-22",                "format": "date",                "type": "string"            }        }    },    "info": {        "title": "",        "version": ""    },    "openapi": "3.0.0",    "paths": {        "/user": {            "get": {                "responses": {                    "200": {                        "content": {                            "application/json": {                                "schema": {                                    "$ref": "#/components/schemas/Day"                                }                            }                        },                        "description": ""                    }                }            }        }    }}

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 :: OpenApi) & paths .~ IOHM.fromList [("/info", mempty)]BSL.putStrLn $ encodePretty $ prependPath "user/{user_id}" api ^. paths{    "/user/{user_id}/info": {}}

Miscellaneous

1 declaration

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

FIXME doc

Example1 expression
BSL.putStrLn $ encodePretty $ runDeclare (declareResponse "application/json" (Proxy :: Proxy Day)) mempty[    {        "Day": {            "example": "2016-07-22",            "format": "date",            "type": "string"        }    },    {        "content": {            "application/json": {                "schema": {                    "$ref": "#/components/schemas/Day"                }            }        },        "description": ""    }]