I have the following code:
import Control.Lens ((&), (.~), (?~), (%~))
import Data.Swagger (Swagger)
import Data.Swagger.Lens (paths, operationId, info, description)
import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
import Data.Text (Text(..), pack)
genOpIds :: Swagger -> Swagger
genOpIds = paths %~ InsOrdHashMap.mapWithKey (\k v -> v & operationId ?~ (pack "hello"))
Generating the following compile error:
• No instance for (Data.Swagger.Lens.HasOperationId
Data.Swagger.Internal.PathItem (Maybe Text))
arising from a use of ‘operationId’
• In the first argument of ‘(?~)’, namely ‘operationId’
In the second argument of ‘(&)’, namely
‘operationId ?~ (pack "hello")’
In the expression: v & operationId ?~ (pack "hello")
|
12 | genOpIds = paths %~ InsOrdHashMap.mapWithKey (\k v -> v & operationId ?~ (pack "hello"))
| ^^^^^^^^^^^
I'm finding it a bit difficult to diagnose, as I think makeLenses is used to generate the class instances. I'm struggling a bit to see how this is different to the following (which compiles fine):
writeInfoTitle :: Swagger -> Swagger
writeInfoTitle = info.description ?~ (pack "whatever description")
as the type hierarchy involved is similar at the bottom. I suspect there's a fundamental bit of understanding I'm missing here, but I've read the lens tutorial, including the section on traversals; various bits of the servant swagger code, and some other examples and haven't managed to figure this out.
To recreate the error message easily, you could clone the following repo and stack build
:
https://github.com/msk-/improved-spork