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

Moduleopenapi3-3.2.4Haskell2010

Data.OpenApi.Internal.Schema.Validation

Validate JSON values with Swagger Schema.

  • 4 types
  • 29 values
  • Packageopenapi3-3.2.4
  • Exports33
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceValidation.hs
Example1 expression
import Data.OpenApi.Internal.Schema.Validation

Pretty print validation errors together with actual JSON and Swagger Schema (using encodePretty).

Example10 expressions
import Data.Aeson as Aesonimport Data.Foldable (traverse_)import GHC.Genericsdata Phone = Phone { value :: String } deriving (Generic)data Person = Person { name :: String, phone :: Phone } deriving (Generic)instance ToJSON Person where toJSON p = object [ "name" Aeson..= name p ]instance ToSchema Phoneinstance ToSchema Personlet person = Person { name = "John", phone = Phone "123456" }traverse_ putStrLn $ renderValidationErrors validateToJSON personValidation against the schema fails:  * property "phone" is required, but not found in "{\"name\":\"John\"}"JSON value:{    "name": "John"}Swagger Schema:{    "properties": {        "name": {            "type": "string"        },        "phone": {            "$ref": "#/components/schemas/Phone"        }    },    "required": [        "name",        "phone"    ],    "type": "object"}Swagger Description Context:{    "Phone": {        "properties": {            "value": {                "type": "string"            }        },        "required": [            "value"        ],        "type": "object"    }}
datadata Result a
#

Validation result type.

Constructors

Instances6Monad, Functor, Applicative, Alternative, Eq, Show
  • Monad ResultDefined in openapi3-3.2.4 · Data.OpenApi.Internal.Schema.Validation
  • Functor ResultDefined in openapi3-3.2.4 · Data.OpenApi.Internal.Schema.Validation
  • Applicative ResultDefined in openapi3-3.2.4 · Data.OpenApi.Internal.Schema.Validation
  • Alternative ResultDefined in openapi3-3.2.4 · Data.OpenApi.Internal.Schema.Validation
  • Eq a => Eq (Result a)Defined in openapi3-3.2.4 · Data.OpenApi.Internal.Schema.Validation
  • Show a => Show (Result a)Defined in openapi3-3.2.4 · Data.OpenApi.Internal.Schema.Validation
newtypenewtype Validation s a
#

Value validation.

Constructors

Instances6Choice, Profunctor, Monad, Functor, Applicative, Alternative
  • Choice ValidationDefined in openapi3-3.2.4 · Data.OpenApi.Internal.Schema.Validation
  • Profunctor ValidationDefined in openapi3-3.2.4 · Data.OpenApi.Internal.Schema.Validation
  • Monad (Validation s)Defined in openapi3-3.2.4 · Data.OpenApi.Internal.Schema.Validation
  • Functor (Validation s)Defined in openapi3-3.2.4 · Data.OpenApi.Internal.Schema.Validation
  • Applicative (Validation schema)Defined in openapi3-3.2.4 · Data.OpenApi.Internal.Schema.Validation
  • Alternative (Validation schema)Defined in openapi3-3.2.4 · Data.OpenApi.Internal.Schema.Validation
valuecheck :: Lens' s (Maybe a) -> (a -> Validation s ()) -> Validation s ()
#

Validate schema's property given a lens into that property and property checker. If property is missing in schema, consider it valid.

Infer schema type based on used properties.

Example1 expression
inferSchemaTypes <$> decode "{\"minLength\": 2}"Just [OpenApiString]
Example1 expression
inferSchemaTypes <$> decode "{\"maxItems\": 0}"Just [OpenApiArray]

From numeric properties OpenApiInteger type is inferred. If you want OpenApiNumber instead, you must specify it explicitly.

Example1 expression
inferSchemaTypes <$> decode "{\"minimum\": 1}"Just [OpenApiInteger]