全部 ApiPost使用 后端 前端 接口测试 IOS Android 数据库 2022 测试技术 工具
问答 / 问答详情

requst body json中数组字段在调试时不能生成正确数据或丢失方括号

ApiPost使用 154次浏览

在request body, 字段userGroups是array类型,但生成的数据没有方括号,并且item没有按定义的方式生成。

requst body json中数组字段在调试时不能生成正确数据或丢失方括号

{
    "type": "object",
    "properties": {
        "id": {
            "type": "integer"
        },
        "jsonrpc": {
            "type": "string",
            "mock": {
                "mock": "2.0"
            }
        },
        "method": {
            "type": "string",
            "mock": {
                "mock": "serverUserAdd"
            }
        },
        "params": {
            "type": "object",
            "properties": {
                "query": {
                    "type": "object",
                    "properties": {
                        "sessionId": {
                            "type": "string",
                            "mock": {
                                "mock": "{{sessionId}}"
                            }
                        },
                        "userName": {
                            "APIPOST_ORDERS": [
                                "f7dd1a13b4d64ec9bb1095f036832a10"
                            ],
                            "APIPOST_REFS": {
                                "f7dd1a13b4d64ec9bb1095f036832a10": {
                                    "ref": "cd1feef2-6671-4e67-baa4-183b8aa413c3"
                                }
                            },
                            "properties": {},
                            "type": "string"
                        },
                        "userPassword": {
                            "APIPOST_ORDERS": [
                                "129ae8b3029e417aa2466008747065d6"
                            ],
                            "APIPOST_REFS": {
                                "129ae8b3029e417aa2466008747065d6": {
                                    "ref": "cd1feef2-6671-4e67-baa4-183b8aa413c3"
                                }
                            },
                            "properties": {},
                            "type": "string"
                        },
                        "userGroups": {
                            "type": "array",
                            "items": {
                                "ref": "bedd83b7-2768-4d3a-b3c0-337edb71df83",
                                "type": "anyOf",
                                "anyOf": [
                                    {
                                        "type": "string",
                                        "mock": {
                                            "mock": "admin"
                                        }
                                    },
                                    {
                                        "type": "string",
                                        "mock": {
                                            "mock": "user"
                                        }
                                    },
                                    {
                                        "type": "string",
                                        "mock": {
                                            "mock": "observer"
                                        }
                                    }
                                ]
                            },
                            "anyOf": [
                                {
                                    "type": "string",
                                    "mock": {
                                        "mock": "admin"
                                    }
                                },
                                {
                                    "type": "string",
                                    "mock": {
                                        "mock": "user"
                                    }
                                },
                                {
                                    "type": "string",
                                    "mock": {
                                        "mock": "observer"
                                    }
                                }
                            ],
                            "uniqueItems": true,
                            "maxItems": 3,
                            "minItems": 1,
                            "properties": {
                                "": {
                                    "type": "string",
                                    "APIPOST_NEW_EMPTY_ROW": true
                                }
                            },
                            "APIPOST_ORDERS": [
                                ""
                            ]
                        }
                    },
                    "APIPOST_ORDERS": [
                        "sessionId",
                        "userName",
                        "userPassword",
                        "userGroups"
                    ],
                    "required": [
                        "sessionId",
                        "userName",
                        "userPassword",
                        "userGroups"
                    ]
                }
            },
            "APIPOST_ORDERS": [
                "query"
            ],
            "required": [
                "query"
            ]
        }
    },
    "APIPOST_ORDERS": [
        "id",
        "jsonrpc",
        "method",
        "params"
    ],
    "required": [
        "id",
        "jsonrpc",
        "method",
        "params"
    ]
}


generated body in debug

requst body json中数组字段在调试时不能生成正确数据或丢失方括号

{
    "id": -3191540258205644,
    "jsonrpc": "2.0",
    "method": "serverUserAdd",
    "params": {
        "query": {
            "sessionId": "{{sessionId}}",
            "userName": "空教矿须将心",
            "userPassword": "来多提厂",
            "userGroups": "厂油龙常王每界社派速"
        }
    }
}
| 0 收藏

5 个回答

您意思是可视化结构生成数组,json里怎么写吗?

@Apipost  

在图1设计阶段,我把字段userGroups设成了array,但在调试阶段生成的数据不是array.

数组这里要进行设置,里面选择最小元素个数

@Apipost

数组元素个数之前已设置。

requst body json中数组字段在调试时不能生成正确数据或丢失方括号

大概找到原因了,用Raw编辑,把没用的误引入的内容删掉,比如 "ref": "bedd83b7-2768-4d3a-b3c0-337edb71df83",编辑后的userGroups字段如下

"userGroups": {
    "type": "array",
    "items": {
        "type": "oneOf",
        "oneOf": [
            {
                "type": "string",
                "mock": {
                    "mock": "admin"
                }
            },
            {
                "type": "string",
                "mock": {
                    "mock": "user"
                }
            },
            {
                "type": "string",
                "mock": {
                    "mock": "observer"
                }
            }
        ]
    },
    "minItems": 1,
    "maxItems": 3,
    "uniqueItems": true
}

感谢反馈~

Apipost 私有化火热进行中

撰写答案

只服务于

前后端、移动端、测试人员

提问题 发布您遇到的Bug和问题,上万名大牛和开发者来帮您解决!