feat: support JSON array request bodies with type:"array" tag and enh… #294
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
type:"array"数组请求体支持当接口需要接收 JSON 数组格式的请求体时,可以在
g.Meta中使用type:"array"标签。这在批量数据处理、批量操作等场景中非常有用。1 使用示例
2 请求体格式
使用
type:"array"后,请求体应为 JSON 数组格式:[ {"role": "user", "content": "hello"}, {"role": "assistant", "content": "world"} ]生成的
OpenAPIv3文档中,请求体的schema.type将为"array",而不会生成对象类型的 Components Schema。3 嵌套结构支持
type:"array"完全支持嵌套结构,包括对象嵌套和数组嵌套:嵌套 JSON 请求体示例:
[ { "role": "user", "content": "hello", "extra": { "key1": "value1", "key2": 123, "tags": ["tag1", "tag2"] } }, { "role": "assistant", "content": "world", "extra": { "key1": "value2", "key2": 456, "tags": ["tag3"] } } ]4 注意事项
type:"array"需要与mime:"application/json"配合使用type:"file"互斥,不应同时使用