0
的自動推導產生的場我有以下類型:定製由ToSchema
data Device = Device { _deviceId :: DeviceId
, _deviceName :: Text
, _deviceDtype :: DType }
deriving (Show, Eq, Generic)
makeFields ''Device
$(deriveJSON (mkOptions "_device") ''Device)
這裏我使用deriveJSON
代替Generic
機制,因爲我需要適應的JSON的字段的名稱此數據類型的表示:
-- | Make JSON conversion options.
mkOptions :: String -> Options
mkOptions prefix = defaultOptions { fieldLabelModifier = removePrefix prefix
, unwrapUnaryRecords = True
}
需要前綴來爲類型生成鏡頭,但在JSON表示中不需要。
現在我試圖使用servant-swagger生成Swagger文檔,這需要Device
的ToSchema
實例。現在問題是生成的模式將具有上述訪問器函數的給定前綴名稱(_deviceId
,_deviceName
,_deviceDType
)。相反,我會有修改後的版本(id
,name
和dtype
)。
有沒有辦法以這種方式定製泛型派生過程?