Skip to content

Conversation

@thanhvg
Copy link
Contributor

@thanhvg thanhvg commented Oct 15, 2025

This commit adds support for array as root schema type for Avro schemas. The AvroSchemaParser now handles cases where the root schema is an array containing a single item. The loadMainSchema function has been updated to coerce the array into a json object with type array and items set to the JSONObject. The resolveLocalReferences function has been updated to handle the case where the root schema is an array and return the resolved schema as an array. Added tests to verify the new functionality.

In an old version of this plugin a few versions ago. We were able to register a subject of array type as simple as [ foo]. This MR brings it back for arvo parser.

The change is a bit hacky because I had to work around the limitation of org.json. But the good news is it is self contained inside AvroSchemaParser which is hopefully not too bad.

This commit adds support for array as root schema type for Avro
schemas. The AvroSchemaParser now handles cases where the root
schema is an array containing a single JSONObject. The
loadMainSchema function has been updated to coerce the array into a
json object with type array and items set to the JSONObject. The
resolveLocalReferences function has been updated to handle the case
where the root schema is an array and return the resolved schema as
an array. Added tests to verify the new functionality.
Comment on lines +222 to +225
if (parsedInput.length() == 1) {
val mySchema = JSONObject();
mySchema.put("type", "array")
mySchema.put("items", parsedInput.get(0))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I see in the spec, it allows multiple primitive values. Things like ["string", "null"] is valid.

Comment on lines +228 to +234
} else {
throw IllegalArgumentException("Invalid schema format: array must contain exactly one JSONObject")
}
}
else -> {
throw IllegalArgumentException("Invalid schema format: must be a JSONObject or an array containing a JSONObject")
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this based on the specifications.
For me, we could have multiple items in the array and that represent an union, could be primitive types or objects.

WDYT ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants