如何包装JSON对象? [英] How do I wrap JSON objects?
问题描述
我目前正在寻找一种在Swagger UI组件中包装JSON的方法.
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生成的输出是(我同意,这是正确的):
{
"message": "string"
}
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.
restExceptionContainer:
restException:
properties:
message:
type: string
restExceptionContainer:
restException:
properties:
message:
type: string
如果可以的话,我可以在Swagger UI文件中添加代码!需要您的帮助以找到位置:)
I'm ok for adding code in the Swagger UI file if needed ! Need your help to find where :)
推荐答案
您应将restException文档记录为对象(类型:object).
You should document restException as an object (type: object).
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屋!