klarna / erlavro

Avro support for Erlang/Elixir (http://avro.apache.org/)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parser should validate the default values

Leden opened this issue · comments

commented

In Avro specification, it is said that only certain values are allowed to be used as defaults (depending on the field's type), but the library does not validate that. For example, this produces a valid output:

1> Schema = "{ \"type\": \"long\", \"name\": \"field8\", \"default\":\"fff\" }".
2> avro_json_decoder.decode_schema(Schema)
{avro_primitive_type, "long", [{"default", "fff"}]}

But such schema does not make any sense as "fff" string is not a valid value for long type.
It would be better if parser raised an error to signify that given default value is invalid.

Hi @Leden
I wold like to understand your use case first.
erlavro does not make use of default values
and it does not produce bad default values either.
so, why would you care ?

The latest commit b5debfa removed default value validation to accommodate someone only about 2 weeks ago. I'm surprised to see another issue raised for the exact opposite. :)

commented

My use case is to know if a given json is, in fact, a valid avro schema. So I use erlavro to try to decode user input and see if it failed. We're building a service somewhat similar to Confluent Schema Registry and it would be extremely useful to not allow users to register invalid schemas. They aren't going to work anyway, but the earlier we discover the problem - the better.

If that functionality was already present but then removed, we may just opt to use the older version. I'll check that.

Or it may be a good idea to have an option that switches such validation on if passed explicitly.

OK. Will add a new API to have strict validation on JSON schema.

commented

Awesome! Thank you so much!