如何包装 JSON 对象? [英] How do I wrap JSON objects?
问题描述
我目前正在寻找一种将 JSON 包装到 Swagger UI 组件中的方法.
I'm currently looking for a way to wrap JSON in the Swagger UI component.
在 YAML 中,我的对象声明是:
In YAML my object declaration is:
restException:
properties:
message:
type: string
Swagger UI 生成的输出是(我同意,是正确的):<代码>{消息":字符串"}
The output generated by Swagger UI is (whic I agree, is correct):
{
"message": "string"
}
而我想要的是:
"restException": {
"message": "string"
}
我只是通过在 YAML 文件中明确声明包装器找到了一种丑陋的方法.但这很糟糕,因为它也是在我使用Swagger Codegen"生成客户端或服务器代码时生成的.
I've just find a ugly way to do it by explicitely declaring the wrapper in the YAML file. But it's verry bad since it's also generates when I use "Swagger Codegen" to generate client or server code.
<代码>休息异常容器:休息异常:特性:信息:类型:字符串
如果需要,我可以在 Swagger UI 文件中添加代码!需要您的帮助才能找到位置:)
I'm ok for adding code in the Swagger UI file if needed ! Need your help to find where :)
推荐答案
你应该将restException记录为一个对象(类型:对象).
You should document restException as an object (type: object).
请参考https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml#L646举个例子,看看 Pet 和 Category 是如何定义的.
Please refer to https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml#L646 as an example and look at how Pet and Category are defined.
Pet:
type: object
required:
- name
- photoUrls
properties:
id:
type: integer
format: int64
category:
$ref: '#/definitions/Category'
其中类别定义为:
Category:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
这篇关于如何包装 JSON 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!