Skip to content

Commit

Permalink
fix parsing of default values for unions (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
radai-rosenblatt authored Jun 15, 2022
1 parent ed885a0 commit ba4ec6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,14 @@ private AvroNamedSchema parseNamedSchema(
AvroLiteral defaultValue = null;
if (fieldDefaultValueNode != null) {
if (fieldSchema.isResolved()) {
LiteralOrIssue defaultValurOrIssue = parseLiteral(fieldDefaultValueNode, fieldSchema.getSchema(), fieldName.getValue(), context);
AvroSchema defaultValueExpectedSchema = fieldSchema.getSchema();
if (defaultValueExpectedSchema.type() == AvroType.UNION) {
//(legal) default values are expected to match the 1st union branch
defaultValueExpectedSchema = ((AvroUnionSchema) defaultValueExpectedSchema).getTypes().get(0).getSchema();
}
LiteralOrIssue defaultValurOrIssue = parseLiteral(fieldDefaultValueNode, defaultValueExpectedSchema, fieldName.getValue(), context);
if (defaultValurOrIssue.getIssue() == null) {
//TODO - allow parsing default values that are branch != 0 (and add an issue)
defaultValue = defaultValurOrIssue.getLiteral();
}
//TODO - handle issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
"type": "string",
"default": "yes please"
},
{
"name": "simpleUnionField",
"type": ["null", "int", "string"],
"default": null
},
{
"name": "enumField",
"type": {
Expand Down

0 comments on commit ba4ec6b

Please sign in to comment.