[英]How can I get ServiceStack's Swagger implementation to use XML content-type?
您无法更改Content Swagger使用的内容,但是ServiceStack Services提供了自动内容协商功能,因此您可以使用.xml
扩展名查询XML,例如:
或在?format=
查询字符串中指定格式:
或通过添加Accept: application/xml
HTTP请求标头。
Swagger不会更改内容类型,但是您可以使用更通用的工具,例如ServiceStack的Postman支持或Fiddler。
我只是增加了一个变化中ServiceStack的最新v4.0.53这是目前可在MyGet ,可以让你改变由ServiceStack返回扬鞭响应,您可以使用填充消耗 ,并在这两个API宣言和操作水平产生 :
Plugins.Add(new SwaggerFeature {
ApiDeclarationFilter = x =>
x.Consumes = x.Produces = new[] { MimeTypes.Json, MimeTypes.Xml }.ToList(),
OperationFilter = x =>
x.Consumes = x.Produces = new[] { MimeTypes.Json, MimeTypes.Xml }.ToList()
});
但这似乎对Swagger UI没有太大影响,我唯一看到的变化是POST请求中的body参数现在可以发送XML了:
在Swagger规范(由ServiceStack生成)中,如果要同时在swagger-ui的下拉菜单中显示,则需要更新端点的produces
以同时包含“ application / xml”和“ application / json”。
这是一个例子:
"produces": [
"application/json",
"application/xml"
],
参考: https : //github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.json#L77
OpenAPI Spec produces
: https : //github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.