Reputation: 341
.net Swagger model schema is empty only for GET formed by UNION (a simple GET shows the right model schema)
How could I show a good model schema for the method swagger shows an empty schema?
Upvotes: 0
Views: 937
Reputation: 341
Part of the problem was observed by @HelderSepu , the response I sent was not IEnumerable (because of the "Select" in Linq).
So I needed to create a model class, in order to have the right model schema:
namespace SupplierB_api.Models {
public class SupplierResponse {
public int SupplierID;
public string SupplierName;
public char SupplierType; }
}
Then, I use the model in Linq:
var SuppliersDistributor = entities.tblD.Take(5).AsEnumerable()
.Select(d => new SupplierResponse { SupplierID = d.distributor_id, SupplierName = d.distributor_name, SupplierType = 'D'});
var SuppliersPublisher = entities.tblN.Take(5).AsEnumerable()
.Select(p => new SupplierResponse { SupplierID = p.publisher_id, SupplierName = p.publisher_name, SupplierType = 'P' });
Then, I use SwaggerResponse (as suggested by @HelderSepu):
[SwaggerResponse(HttpStatusCode.OK, "response", typeof(IOrderedEnumerable<SupplierResponse>))]
Upvotes: 0
Reputation: 17614
Use SwaggerResponse like this one:
[SwaggerResponse(HttpStatusCode.OK, "List of customers", typeof(IEnumerable<int>))]
[SwaggerResponse(HttpStatusCode.BadRequest, Type = typeof(BadRequestErrorMessageResult))]
[SwaggerResponse(HttpStatusCode.NotFound, Type = typeof(NotFoundResult))]
public IHttpActionResult GetById(int id)
{
if (id > 0)
return Ok(new int[] { 1, 2 });
else if (id == 0)
return NotFound();
else
return BadRequest("id must be greater than 0");
}
The difference between yours is that one uses HttpResponseMessage
Upvotes: 1