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

Moduleopenapi3-3.2.4Haskell2010

Data.OpenApi.Internal.ParamSchema

  • 1 type
  • 3 classes
  • 6 values
  • Packageopenapi3-3.2.4
  • Exports11
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceParamSchema.hs
valuepasswordSchema :: Schema
#

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

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

A configurable generic Schema creator.

Example3 expressions
:set -XDeriveGenericdata Color = Red | Blue deriving GenericBSL.putStrLn $ encodePretty $ genericToParamSchema defaultSchemaOptions (Proxy :: Proxy Color){    "enum": [        "Red",        "Blue"    ],    "type": "string"}
classclass GToParamSchema (f :: Type -> Type) where
#
Instances5GToParamSchema
Example2 expressions
import Data.Aeson (encode)import Data.OpenApi.Internal.Utils