Skip to content

examples in schema produce validation error #140

@vances

Description

@vances

If I include examples in a schema, validation fails:

{
     "type":  "string",
     "format": "date-time",
     "examples": [
          "2024-01-09T08:00:00Z"
     ]
}
1> {ok, Bin} = file:read_file("date-time.json").
{ok,<<"{\n\t\"type\": \"string\",\n\t\"format\": \"date-time\",\n\t\"examples\": [\n\t\t\"2024-01-09T08:00:00Z\"\n\t]\n}\n">>}
2> Schema1 = json:decode(Bin).
#{<<"examples">> => [<<"2024-01-09T08:00:00Z">>],
  <<"format">> => <<"date-time">>,<<"type">> => <<"string">>}
3> jesse:add_schema("test1", Schema1).
ok
4> jesse:validate("test", <<"2024-01-09T08:00:00Z">>).
{error,[{data_invalid,#{<<"$id">> =>
                            <<"file:///Users/vances/cgf.build/shell/test">>,
                        <<"examples">> => [<<"2024-01-09T08:00:00Z">>],
                        <<"format">> => <<"date-time">>,<<"type">> => <<"string">>},
                      not_array,<<"2024-01-09T08:00:00Z">>,[]}]}

Removing examples allows validation to succeed:

5> Schema2 = maps:remove(<<"examples">>, Schema1).
#{<<"format">> => <<"date-time">>,<<"type">> => <<"string">>}
6> jesse:add_schema("test2", Schema2).
ok
7> jesse:validate("test2", <<"2024-01-09T08:00:00Z">>).
{ok,<<"2024-01-09T08:00:00Z">>}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions