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

Moduleswagger2-2.8.9Haskell2010

Data.Swagger.ParamSchema

Types and functions for working with Swagger parameter schema.

  • 1 type
  • 1 class
  • 6 values
  • Packageswagger2-2.8.9
  • Exports8
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceParamSchema.hs

Encoding

1 declaration
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, …

Generic schema encoding

2 declarations

Schema templates

3 declarations

Generic encoding configuration

2 declarations
datadata SchemaOptions
#

Options that specify how to encode your type to Swagger schema.

Constructors