在我们的REST API中,我们支持XML和JSON作为输入/输出格式,在生成Swagger文档时,Swagger生成的示例输入不会显示JSON输入的根节点值,但会显示XML示例。
由于我们的REST API也需要JSON的根节点,我如何让Swagger在示例中显示根节点?
Swagger示例XML -
<Request>
<EmployeeNumber>string</EmployeeNumber>
<Department>
<DepartmentId>string</DepartmentId>
<DepartmentName>string</DepartmentName>
<DepartmentHead>string</DepartmentHead>
<DepartmentLocation>string</DepartmentLocation>
</Department>
</Request>
Swagger示例JSON -
{
"EmployeeNumber": "string",
"Department": {
"DepartmentId": "string",
"DepartmentName": "string",
"DepartmentHead": "string",
"DepartmentLocation": "string"
}
}
应为JSON示例-
{
"Request": {
"EmployeeNumber": "string",
"Department": {
"DepartmentId": "string",
"DepartmentName": "string",
"DepartmentHead": "string",
"DepartmentLocation": "string"
}
}
}
如何在swagger注解中提供示例样本,而不是自动生成一个?
2条答案
按热度按时间cqoc49vn1#
我在使用openApi swagger时也遇到了同样的问题。我通过添加一个OpenApiCustomiser解决了这个问题:
ExampleBuilder的Maven依赖项:
结果真是太棒了,我得到了我所需要的。如果你正在使用swagger,我建议你转移到OpenApi。
3z6pesqy2#
https://github.com/swagger-api/swagger-core/wiki/annotations
看看这个。希望对你有帮助。