Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten c# interfaces #4893

Open
pgpaccuratech opened this issue May 13, 2024 · 0 comments
Open

Flatten c# interfaces #4893

pgpaccuratech opened this issue May 13, 2024 · 0 comments

Comments

@pgpaccuratech
Copy link

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

      "PurchaseOrder": {
        "type": "object",
        "x-abstract": true,
        "additionalProperties": false,
        "properties": {
          "vendorId": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          }
        }
      }

I have openApiConfiguration.SchemaSettings.FlattenInheritanceHierarchy = true; in AddOpenApiDocument(), but that does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant