我在 swagger 中将 api 响应渲染为 xml 时遇到了一些问题,最后我用下面的第一个操作将其渲染为正确的格式 application/xml ,但它仍然说我只能将其渲染为 application/json 。
我尝试从 Produces 属性中删除 application/json,但仍然仅显示 application/json。
有什么想法为什么会这样吗?
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddMvcOptions(o => o.OutputFormatters.Add(new XmlDataContractSerializerOutputFormatter()));
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
c.RoutePrefix = "";
});
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
c.AddSecurityDefinition("Bearer", new ApiKeyScheme { In = "header", Description = "Please enter JWT with Bearer into field", Name = "Authorization", Type = "apiKey" });
c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>> { …Run Code Online (Sandbox Code Playgroud)