rbeauchamp / Swashbuckle.OData

Extends Swashbuckle with OData v4 support!
Other
129 stars 96 forks source link

Swagger generation fails for Entities having DataContractAttribute fails with "Sequence contains no matching element" when used in OData Actions. #197

Closed kspbhat closed 3 years ago

kspbhat commented 3 years ago

I am using an action with the following definition. Here, I have added an entity having DataContract as an entity parameter to the action.

This generates the EDMType fullname as "Sample.Models.queueInfo". But the CLR Typename would still be be Sample.Models.QueueInfo.

As per my analysis, TypeHelper.cs has a static method - FindType that tries to find the Type based on EDM Type FullName. Since this method first loads all CLR Types and then compares with the EDMType full name, it fails with Sequence contains no matching element error.

This method should do a case insensitive comparison in order to fix the issue.

Any thoughts / opinions in this regard is highly appreciated.

Action Definition:

var actionEnqueue = builder.EntityType<Document>().Action("enqueue");            
actionEnqueue.EntityParameter<Models.QueueInfo>("queueInfo");

Entity:

namespace Sample.Models
{
[DataContract(Name = "queueInfo")]
    public class QueueInfo
    {
        [Key]
        [DataMember(Name = "name")]
        public  string Name { get; set; }

        [DataMember(Name = "eventName")]
        public  string EventName { get; set; }      
    }
}

TypeHelper.cs

internal static Type FindType(string fullName)
{
    return GetLoadedTypes()
        .First(t => t.FullName.Equals(fullName));
}
rbeauchamp commented 3 years ago

Closing issues and archiving this project as no one has signed up to maintain it.