HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduleswagger2-2.9.1Haskell2010

Data.Swagger.ParamSchema

Types and functions for working with Swagger parameter schema.

Contents
  1. Encoding
  2. Generic schema encoding
  3. Schema templates
  4. Generic encoding configuration
Synopsis
  • Packageswagger2-2.9.1
  • Exports8
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceParamSchema.hs

Encoding

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

Schema templates

Generic encoding configuration

datadata SchemaOptions

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

Constructors