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

Moduleopenapi3-3.2.5Haskell2010

Data.OpenApi.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
  • Packageopenapi3-3.2.5
  • Exports8
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceParamSchema.hs

Encoding

classclass ToParamSchema a where

Convert a type into a plain Schema.

In previous versions of the package there was a separate type called ParamSchema, which was included in a greater Schema. Now this is a single class, but distinction for schema generators for "simple" types is preserved.

ToParamSchema is suited only for primitive-like types without nested fields and such.

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_ ?~ OpenApiString
     & 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 -> Schema

    Convert a type into a plain parameter schema.

    Example1 expression
    BSL.putStrLn $ encodePretty $ toParamSchema (Proxy :: Proxy Integer){    "type": "integer"}
Instances48ToParamSchema, …

Generic schema encoding

Schema templates

Default schema for password string. "password" format is used to hint UIs the input needs to be obscured.

Generic encoding configuration

datadata SchemaOptions

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

Constructors