avsc
avsc copied to clipboard
Support ?-syntax for optional fields in avdl
I'm trying to parse a avdl file with an optional field but it seems that avsc does not support using the ?-syntax to describe a optional/nullable field.
Example
.avdl file
protocol Protocol {
record Record {
string? text;
}
}
Code:
const path = path.resolve('./path-to-avdl-file.avdl');
const schema = fs.readFileSync(path, { encoding: 'utf8' });
const protocol = avsc.readProtocol(schema);
Resulting in error:
Error: invalid token {"pos":47,"id":"operator","val":"?"}: expected ID name
Is this a known issue or is it possible to work around this?
Context: https://avro.apache.org/docs/1.11.1/idl-language/#unions
Hi @adamlindqvist. Thanks for reporting - the optional shorthand isn't currently supported (PR very welcome!).
You'll need to stick to the long form until it is:
protocol Protocol {
record Record {
union { null, string } text;
}
}
@mtth Since the corresponding PR is now merged, any chance to release a new version to NPM to make this feature accessible?