I'm using the C++ api to do validation outside what I can specify in the schema spec.
On Mon, Nov 27, 2017 at 11:12 AM, Martin Mucha <[email protected]> wrote: > Following schema: > { > "name" : "ARecord", > "type" : "record", > "namespace" : "AAA", > "fields" : [ > {"name": "A", "type": "string" } > ] > } > > > does not validate json > > {} > > as valid one. It's invalid. A is required, as would be expected by me. > > --- > I'm getting lost here. > What is the resolution? I kinda wanted to use avro schema to validate > described JSON, and now based on what you said IIUC validation in "xschema > style": "1 of this, followed by 2 of that" is not possible with avro schema. > Correct? > > > Btw. what do you use to validate JSON using avro? I used avro-utils.jar > executed from command line, which proved as incapable of deserializing & > validating optional fields if they are set (if optional field is set, I have > to pass value in json like: {"string":"value"}). So now I'm using for > testing purposes actual flow through NIFI, which is extremely cumbersome. > > 2017-11-27 16:19 GMT+01:00 Dan Schmitt <[email protected]>: >> >> The top level object in all the examples is a record (of which you can >> have 0 or more.) >> >> So, right now, even the top level is failing the spec: >> >> IV) valid (0 ARecords): >> { } >> >> V) valid (2 ARecords): >> { >> "id": "...", >> "B": { >> "C": "..." >> } >> } , >> "id": "...", >> "B": { >> "C": "..." >> } >> } >> >> On Mon, Nov 27, 2017 at 9:47 AM, Martin Mucha <[email protected]> wrote: >> > I don't understand where "or more" is comming from. >> >> Because of the use of nested records. Anywhere you put a record you can >> have 0, >> or more than 1. I don't know of a pure schema way to enforce only >> 1/optional. >> >> If you are doing something with any of the APIs you could add a validation >> step >> that says "must have only 1 ARecord, and must have only 1 BRecord" after >> you >> read the data and throw an error for the 0 or 1+ situations, but you'd >> need to write >> some code somewhere with one of the APIs and build your own validator. > >
