title: Response content types in swagger, .net core api
body: <p>I had some problems to render my api response as xml in swagger, finally I got it to render in the correct format, application/xml with my first action below, but it still says I can only render it as application/json. </p>
  
  <p>I tried to remove application/json from Produces attribute, but still shows only application/json. </p>
  
  <p>Any ideas why its behaving in this way?</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddMvc().AddMvcOptions(o =&gt; o.OutputFormatters.Add(new XmlDataContractSerializerOutputFormatter()));
      app.UseSwagger();
      app.UseSwaggerUI(c =&gt;
      {
          c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
          c.RoutePrefix = "";
      });
      services.AddSwaggerGen(c =&gt;
      {
          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&lt;string, IEnumerable&lt;string&gt;&gt; {
              { "Bearer", Enumerable.Empty&lt;string&gt;() },
          });
      });
  }
  </code></pre>
  
  <p>And action:</p>
  
  <pre><code>[Produces("application/json", "application/xml")]
  public ContentResult GetByAddress(string address)
  {
      var addressId = GetAddressIdByAddress(address);
      string result = _soapApi.GetResultById(addressId);
      return Content(result, "application/xml", Encoding.UTF8);
  }
  </code></pre>
  
  <p>Same result with:</p>
  
  <pre><code>[Produces("application/json", "application/xml")]
  public IActionResult GetByAddress(string address)
  {
      var addressId = GetAddressIdByAddress(address);
      string result = _soapApi.GetResultById(addressId);
      return Content(result, "application/xml", Encoding.UTF8);
  }
  </code></pre>
  
  <p>Results in:</p>
  
  <p><a href="https://i.stack.imgur.com/IgZRI.png" rel="noreferrer"><img src="https://i.stack.imgur.com/IgZRI.png" alt="Results in this"></a>
  When clicking excecute I get the result in the correct XML-format though.</p>
  
  <p>While this:</p>
  
  <pre><code>[Produces("application/json", "application/xml")]
  public string GetByAddress(string address)
  {
      var addressId = GetAddressIdByAddress(address);
      string result = _soapApi.GetResultById(addressId);
      return result;
  }
  </code></pre>
  
  <p>Or this:</p>
  
  <pre><code>[Produces("application/json", "application/xml")]
  public List&lt;Address&gt; GetByAddreses()
  {
      string result = _soapApi.GetResults();
      return result;
  }
  </code></pre>
  
  <p>Results in:</p>
  
  <p><a href="https://i.stack.imgur.com/TYm7Y.png" rel="noreferrer"><img src="https://i.stack.imgur.com/TYm7Y.png" alt="enter image description here"></a></p>
  
  <p>I am not able to return a list of parsed objects due to different data-structure returned for different parameters. So at this point I only receive raw soap xml-data and have to parse/deserialize it. But to actually be able to see the raw response I also need to show it as Content from string with content-type application/xml. And it gives me a nice output like (even though it still says only application/json is possible):</p>
  
  <p><a href="https://i.stack.imgur.com/tEcSu.png" rel="noreferrer"><img src="https://i.stack.imgur.com/tEcSu.png" alt="enter image description here"></a></p>
  
  <p>To summarize it:</p>
  
  <p>I did not get it work with response content-type showing the correct content-type (in "Response Content Type" -filter) when a string was parsed to its actual format like below. Even though this results in the correct output for application/xml that was the most important (see screenshot above);</p>
  
  <pre><code>[Produces("application/json", "application/xml")]
  public ContentResult GetByAddress(string address)
  {
      return Content("&lt;xml&gt;...&lt;/xml&gt;", "application/xml", Encoding.UTF8);
  } 
  </code></pre>