Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Hydra.JSONSchema
Synopsis
- prop_validateJSONSchema :: forall a. (ToJSON a, Arbitrary a, Show a) => String -> SpecificationSelector -> Property
- prop_specIsComplete :: forall a. (Arbitrary a, Show a) => String -> SpecificationSelector -> Property
- type SpecificationSelector = Traversal' Value Value
- withJsonSpecifications :: MonadIO m => (FilePath -> m r) -> m r
- addField :: ToJSON a => Key -> a -> Value -> Value
- ensureSystemRequirements :: IO ()
Documentation
prop_validateJSONSchema Source #
Arguments
:: forall a. (ToJSON a, Arbitrary a, Show a) | |
=> String | Path to the JSON file holding the schema. |
-> SpecificationSelector | Selector into the JSON file pointing to the schema to be validated. |
-> Property |
Validate an Arbitrary
value against a JSON schema.
The second argument is a lens that says which part of the JSON file to use to do the validation, for example:
@
key "components" . key "schemas" . key Address
@
which selects the JSON schema for Address types in a bigger specification, say an asyncapi description.
prop_specIsComplete :: forall a. (Arbitrary a, Show a) => String -> SpecificationSelector -> Property Source #
Check specification is complete wr.t. to generated data This second sub-property ensures that any key found in the specification corresponds to a constructor in the corresponding data-type. This makes sure the document is kept in sync and make sure we don't left behind constructors which no longer exists.
The second argument is a lens that says which part of the specification to select to check completeness of the specification w.r.t. constructors for the datatype, for example:
@
key "properties" . key "message"
@
which selects the list of elements under properties > message
path
in the specification file. This element should be a schema fragment that has
a property oneOf
containing a list of objects having a title
property.
Given the above selector, this schema fragment is fine:
@
properties:
message:
oneOf:
- title: APIServer
type: object
...
@
type SpecificationSelector = Traversal' Value Value Source #
An alias for a traversal selecting some part of a Value
This alleviates the need for users of this module to import explicitly the types
from aeson and lens.
withJsonSpecifications :: MonadIO m => (FilePath -> m r) -> m r Source #
Prepare the environment (temp directory) with the JSON specifications. We maintain a YAML version of a JSON-schema, for it is more convenient to write. But tools (and in particular jsonschema) only works from JSON, so this function makes sure to also convert our local yaml into JSON.
ensureSystemRequirements :: IO () Source #
Make sure that the required `check-jsonschema` tool is available on the system. Mark a test as pending when not available.