I have a DB entity that includes a lot of information for various kinds of orders. But when using the REST interface, I would like to filter the irrelevant data away from the API. My idea was to use interfaces to do this.
Example:
public interface IOrderBase
{
public int Id { get; set; }
}
public interface ISalesOrder : IOrderBase
{
public int? CustomerId { get; set; }
}
public interface IPurchaseOrder : IOrderBase
{
public int? VendorId { get; set; }
}
public class OrderEntity : IPurchaseOrder, ISalesOrder
{
public int Id { get; set; }
public int? CustomerId { get; set; }
public int? VendorId { get; set; }
}
[HttpGet("{id}")]
[Route("purchaseOrder")]
public IPurchaseOrder GetPurchaseOrder(int id)
{
OrderEntity purchaseOrder = // use entity framework to fetch record
return (IPurchaseOrder)purchaseOrder;
}
Unfortunately, the API does not include OrderID in the PurchaseOrder.
From the schemas
I have a DB entity that includes a lot of information for various kinds of orders. But when using the REST interface, I would like to filter the irrelevant data away from the API. My idea was to use interfaces to do this. Example:
Unfortunately, the API does not include
OrderID
in thePurchaseOrder
. From the schemasI have
openApiConfiguration.SchemaSettings.FlattenInheritanceHierarchy = true;
inAddOpenApiDocument()
, but that does not work.