HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleswagger2-2.8.9Haskell2010

Data.Swagger.Internal.ParamSchema

  • 1 type
  • 3 classes
  • 6 values
  • Packageswagger2-2.8.9
  • Exports11
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceParamSchema.hs
classclass ToParamSchema a where
#

Convert a type into a plain ParamSchema.

An example type and instance:

{-# LANGUAGE OverloadedStrings #-}   -- allows to write Text literals

import Control.Lens

data Direction = Up | Down

instance ToParamSchema Direction where
  toParamSchema _ = mempty
     & type_ ?~ SwaggerString
     & enum_ ?~ [ "Up", "Down" ]

Instead of manually writing your ToParamSchema instance you can use a default generic implementation of toParamSchema.

To do that, simply add deriving Generic clause to your datatype and declare a ToParamSchema instance for your datatype without giving definition for toParamSchema.

For instance, the previous example can be simplified into this:

{-# LANGUAGE DeriveGeneric #-}

import GHC.Generics (Generic)

data Direction = Up | Down deriving Generic

instance ToParamSchema Direction

Methods

  • toParamSchema :: Proxy a -> ParamSchema t

    Convert a type into a plain parameter schema.

    Example1 expression
    encode $ toParamSchema (Proxy :: Proxy Integer)"{\"type\":\"integer\"}"
Instances48ToParamSchema, …
classclass GToParamSchema (f :: Type -> Type) where
#
Instances5GToParamSchema
Example1 expression
import Data.Aeson (encode)