1602/json-schema/1.1.0

NOTE: this package is not compatible with Elm 0.19.1

Json.Schema.Definitions

This module contains low-level structures JSON Schema build from. Normally you wouldn't need to use any of those definitions.

If you really need this low-level API you might need JSON Schema spec as guidance.

Feel free to open issue to describe your use-case, it will affect development roadmap of this library.

Definitions

type Schema
= BooleanSchema Bool
| ObjectSchema SubSchema

Schema can be either boolean or actual object containing validation and meta properties

type alias SubSchema =
{ type_ : Type
, id : Maybe String
, ref : Maybe String
, title : Maybe String
, description : Maybe String
, default : Maybe Value
, examples : Maybe (List Value)
, definitions : Maybe Schemata
, multipleOf : Maybe Float
, maximum : Maybe Float
, exclusiveMaximum : Maybe Float
, minimum : Maybe Float
, exclusiveMinimum : Maybe Float
, maxLength : Maybe Int
, minLength : Maybe Int
, pattern : Maybe String
, format : Maybe String
, items : Items
, additionalItems : Maybe Schema
, maxItems : Maybe Int
, minItems : Maybe Int
, uniqueItems : Maybe Bool
, contains : Maybe Schema
, maxProperties : Maybe Int
, minProperties : Maybe Int
, required : Maybe (List String)
, properties : Maybe Schemata
, patternProperties : Maybe Schemata
, additionalProperties : Maybe Schema
, dependencies : List ( String, Dependency )
, propertyNames : Maybe Schema
, enum : Maybe (List Value)
, const : Maybe Value
, allOf : Maybe (List Schema)
, anyOf : Maybe (List Schema)
, oneOf : Maybe (List Schema)
, not : Maybe Schema
}

This object holds all draft-6 schema properties

= Schemata (List ( String, Schema ))

List of schema-properties used in properties, definitions and patternProperties

type Items
= NoItems
| ItemDefinition Schema
| ArrayOfItems (List Schema)

Items definition.

= ArrayPropNames (List String)
| PropSchema Schema

Dependency definition.

type Type
= AnyType
| SingleType SingleType
| NullableType SingleType
| UnionType (List SingleType)

Type property in json schema can be a single type or array of them, this type definition wraps up this complexity, also it introduces concept of nullable type, which is array of "null" type and a single type speaking JSON schema language, but also a useful concept to treat it separately from list of types.

= IntegerType
| NumberType
| StringType
| BooleanType
| ArrayType
| ObjectType
| NullType
blankSchema : Schema

Create blank JSON Schema {}.

blankSubSchema : SubSchema

Decoding / encoding

decoder : Decoder Schema
encode : Schema -> Value

Misc

stringToType : String -> Result String SingleType

Attempt to parse string into a single type, it recognises the following list of types:

  • integer
  • number
  • string
  • boolean
  • array
  • object
  • null