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

Moduleswagger2-2.8.9Haskell2010

Data.Swagger.Internal.Schema.Validation

Validate JSON values with Swagger Schema.

  • 4 types
  • 30 values
  • Packageswagger2-2.8.9
  • Exports34
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceValidation.hs

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": "#/definitions/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 swagger2-2.8.9 · Data.Swagger.Internal.Schema.Validation
  • Functor ResultDefined in swagger2-2.8.9 · Data.Swagger.Internal.Schema.Validation
  • Applicative ResultDefined in swagger2-2.8.9 · Data.Swagger.Internal.Schema.Validation
  • Alternative ResultDefined in swagger2-2.8.9 · Data.Swagger.Internal.Schema.Validation
  • Eq a => Eq (Result a)Defined in swagger2-2.8.9 · Data.Swagger.Internal.Schema.Validation
  • Show a => Show (Result a)Defined in swagger2-2.8.9 · Data.Swagger.Internal.Schema.Validation
newtypenewtype Validation s a
#

Value validation.

Constructors

Instances6Choice, Profunctor, Monad, Functor, Applicative, Alternative
  • Choice ValidationDefined in swagger2-2.8.9 · Data.Swagger.Internal.Schema.Validation
  • Profunctor ValidationDefined in swagger2-2.8.9 · Data.Swagger.Internal.Schema.Validation
  • Monad (Validation s)Defined in swagger2-2.8.9 · Data.Swagger.Internal.Schema.Validation
  • Functor (Validation s)Defined in swagger2-2.8.9 · Data.Swagger.Internal.Schema.Validation
  • Applicative (Validation schema)Defined in swagger2-2.8.9 · Data.Swagger.Internal.Schema.Validation
  • Alternative (Validation schema)Defined in swagger2-2.8.9 · Data.Swagger.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 [SwaggerString]
Example1 expression
inferSchemaTypes <$> decode "{\"maxItems\": 0}"Just [SwaggerArray]

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

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