3kis opened a new pull request, #12390: URL: https://github.com/apache/apisix/pull/12390
### Description In the `grpc-transcode` plugin, when a `repeated` field in the gRPC response is empty, it is incorrectly encoded as an empty JSON object (`{}`) instead of an empty JSON array (`[]`). This behavior does not comply with the gRPC-JSON transcoding specification and can cause type-related errors on the client-side, which expects an array. This PR fixes this issue by ensuring that empty `repeated` fields are correctly serialized to `[]`. ### Checklist - [x] I have explained the need for this PR and the problem it solves - [x] I have explained the changes or the new features added to this PR - [] I have added tests corresponding to this change - [] I have updated the documentation to reflect this change - [x] I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first) ### Changes or the new features added to this PR The main changes are in the `response.lua` file to correctly handle the serialization of `repeated` fields. 1. **Identify `repeated` fields**: A new function `fetch_proto_array_names` has been added. It recursively traverses the loaded Protobuf schema definition to identify and collect the names of all fields marked as `repeated`. 2. **Ensure correct JSON array serialization**: * A new function `set_default_array` has been introduced. After the gRPC response is decoded into a Lua table, this function traverses the table. * For any field that was identified as `repeated`, it sets a specific metatable (`core.json.array_mt`). * This metatable forces the `core.json.encode` function to serialize the corresponding Lua table as a JSON array (`[]`), even when it is empty. This logic is applied just before the decoded response is encoded into the final JSON output, ensuring the structure is correct. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org