Copyright | (c) Gareth Tan 2017 |
---|---|
License | MIT |
Safe Haskell | None |
Language | Haskell2010 |
Provides a set of utilities to combine JSON documents or JSON Schemas into a single schema.
All JSON documents provided mustbe completely dereferenced. JSON
references found as $ref
keys within the document will be treated
as regular key-value pairs. No attempt will be made to determine
where those references point to.
In unfiying schemas we will only attempt the unification of the following :
maximum
, exclusiveMaximum
, minimum
, exclusiveMinimum
,
maxLength
, minLength
, items
, additionalItems
, maxItems
,
minItems
, uniqueItems
, required
, properties
, additionalProperties
,
maxProperties
, minProperties
, patternProperties
and type
.
Keys that are not in this list are subject to arbitrary overriding when unifying multiple schemas. For example, when unifying two schemas with differing versions, only one of them will be kept.
- jsonToSchema :: Value -> Schema
- jsonToSchemaWithConfig :: SchemaGenerationConfig -> Value -> Schema
- jsonsToSchema :: (Foldable f, Functor f) => f Value -> Maybe Schema
- jsonsToSchemaWithConfig :: (Foldable f, Functor f) => SchemaGenerationConfig -> f Value -> Maybe Schema
- schemasToSchema :: (Foldable f, Functor f) => f Schema -> Maybe Schema
- unifySchemas :: Schema -> Schema -> Schema
Documentation
jsonToSchema :: Value -> Schema Source #
Converts a single JSON document into a JSON schema which the
document will validate against by using the default options specified
in defaultSchemaGenerationConfig
.
jsonToSchemaWithConfig :: SchemaGenerationConfig -> Value -> Schema Source #
Converts a single JSON document into a JSON schema which the document will validate against. Configuration options allow customizing how the original JSON document should be interpreted when it is converted into a schema.
The options provided control how even recursively nested schemas will be interpreted. There is currently no option to interpret a JSON document one way given one path and another way at another path.
jsonsToSchema :: (Foldable f, Functor f) => f Value -> Maybe Schema Source #
Combines multiple JSON documents into a single schema by first converting each into a schema and
folding across the schemas using unifySchemas
. The documents are converted into schemas using
the default options specified in defaultSchemaGenerationConfig
.
jsonsToSchemaWithConfig :: (Foldable f, Functor f) => SchemaGenerationConfig -> f Value -> Maybe Schema Source #
Combines multiple JSON documents into a single schema by first converting each into a schema and
folding across the schemas using unifySchemas
. This allows a specific configuration for parsing
the JSON documents into the schemas to be provided.
schemasToSchema :: (Foldable f, Functor f) => f Schema -> Maybe Schema Source #
Combines multiple schemas into a single schema by folding across them using
unifySchemas
. The Maybe
accounts for the case where it is passed
an empty Foldable
.
unifySchemas :: Schema -> Schema -> Schema Source #
The primary function used to combine multiple JSON schemas.
This relation cannot be the binary operation of a monoid because
the empty schema will act to remove the required
property of
any JSON Schema it is unified with.
This relation is also not commutative because we arbitrarily select
from the alternatives for properties such as the schema version
that cannot be unified. In addition, when one items schema is
an array and another is an object, we simply choose arbitrarily
because there is no sensible way of unifying the schemas while
preserving all relevant information.