-- Copyright (c) 2024 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at:
--         http://license.coscl.org.cn/MulanPSL2
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.

local res = ReqBody.OriginResources and cjson.json_object_ordered_encode(ReqBody.OriginResources) or ''

local origin_resources = ReqBody.OriginResources
if not origin_resources or not cjson.json_object_is_array(origin_resources) then  -- 预期为非空json数组对象
    return ''
end

for _, v in pairs(origin_resources) do
    if cjson.json_object_is_object(v) and #v ~= 0 then   -- 存在非空对象,返回encode后的字符串
        return res
    end
end

return ''   -- 输入为全空对象时返回空字符串
