小编Sge*_*dda的帖子

swagger、.net core api 中的响应内容类型

我在 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)

c# swagger asp.net-core

7
推荐指数
1
解决办法
3万
查看次数

标签 统计

asp.net-core ×1

c# ×1

swagger ×1