Closed the-guitarman closed 8 years ago
You have to mark mandatory properties as required, otherwise JSON Schema does not care whether they're there or not. So if you want team_name
to be a required property, your schema should look like this:
%{
"type" => "object",
"properties" => %{
"team_name" => %{"type" => "string"},
"matches" => %{
"type" => "array",
"properties" => %{
"start_at" => %{"type" => "string"},
"home" => %{"type" => "string"},
"guest" => %{"type" => "string"}
}
}
},
"required" => ["team_name"]
}
I would also recommend to have your dates in ISO 8601, then you can use "format": "date-time"
for that property in your schema to have them properly validated.
For all who are looking for more information. See: Validating Data in Elixir with ExJsonSchema
Yes, that's a good article. I'd also recommend checking out http://spacetelescope.github.io/understanding-json-schema/ for a more extensive JSON Schema tutorial.
My schema expects the
team_name
field to be astring
field.But the given json string has no
team_name
field.I decode the string and get a map.
I validate the map and get
:ok
.I expect to get an
:error
. There's something wrong.Elixir 1.2.2 ex_json_schema 0.3.1