SkywardApps / popcorn

Popcorn is a .Net Middleware for your RESTful API that allows your consumers to request exactly as much or as little as they need, with no effort from you.
https://skywardapps.github.io/popcorn/
MIT License
59 stars 19 forks source link

Polymorphism in DefaultIncludes #19

Closed alexbarbato closed 7 years ago

alexbarbato commented 7 years ago

Possible Solution

  1. We can make it so the [IncludeByDefault]'s are respected for a base class and all of it's derived classes
  2. We can also optionally (or additionally) add a attribute that can be specified on a base class that indicates whether its sub class [IncludeByDefault]'s should be included.

Steps to Reproduce

Given the following projections

    public class BaseProjection
    {
        [IncludeByDefault]
        public Guid? Id { get; set; }
        public string Name { get; set; }
    }

    public class SubProjection:BaseProjection
    {
        [IncludeByDefault]
        public Guid? SubId { get; set; }
        [IncludeByDefault]
        public string SubName { get; set; }
    }

If then we make a hypothetical call as shown below (that for sake of example is just a call for an object that contains a property that correlates to BaseProjection) , we get the following response:

http://localhost:5000/api/1/object?include=[Base]
{
    "Success": true,
    "Data":
        {
            "Base": {
                    "SubId": "709cf9c6-dc56-44b4-ba7b-f204c342e8ed",
                    "SubName": "asdf",
              }
       }
}

Expected Behavior

We would minimally expect the "Id" for the BaseProjection to be included as well

Actual Behavior

Note that the "Id" property isn't included.

Possible Implementation

It's a bit up for debate how we could choose to implement this, but here is a note from a chat we had on whether this is a bug or enhancement: Well, the question is what the expectation was; should it have included the base properties marked include by default? There's arguments either way. If they are included by default, it is hard (or potentially impossible) for me to then exclude them in a subclass. If they are not, then it is hard (or potentially impossible) for me to then additionally include them in a subclass. (Either case is probably solved by an explicit include on the request)

alexbarbato commented 7 years ago

As I wrote the buggy code, I suppose it's only fair I fix it