rbeauchamp / Swashbuckle.OData

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

Custom type parameters for OData functions #189

Closed blackmore466 closed 4 years ago

blackmore466 commented 6 years ago

Hi!

I have OData function:

public class ItemsController : ODataController
    {
        [HttpGet]
        public async Task<IHttpActionResult> SomeFunc([FromODataUri]SomethingDTO something)
        {
            return Ok(1);
        }
    }

SomethingDTO:

public class SomethingDTO
    {
        public int Name { get; set; }
    }

And ODataConfig:

public static class WebApiConfig
    {
        public static void Configure(HttpConfiguration config)
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EnableLowerCamelCase();
            builder.EntitySet<Item>("Items");

            var itemsEntityType = builder.EntitySet<Item>("Items").EntityType;

            var func = itemsEntityType.Collection.Function("SomeFunc");
            func.Parameter<SomethingDTO>("something");
            func.Returns<int>();

            config.MapODataServiceRoute("odata", "odata", builder.GetEdmModel());
        }
    }

This works fine, but when I open swagger page, app throws exception:

An exception of type 'System.ArgumentOutOfRangeException' occurred in Swashbuckle.OData.dll but was not handled in user code
ParameterName: TypeKind

When I remove this string func.Parameter<SomethingDTO>("something"); from OData config, Swagger page works correctly. But OData function breaks down.

How to define complex parameter for OData function in Swashbuckle.OData?

.NET 4.5.2

Microsoft.AspNet.OData version="6.0.0"

Swashbuckle version="5.6.0"

Swashbuckle.Core version="5.6.0"

Swashbuckle.OData version="3.5.0"

gkiran1 commented 5 years ago

I am facing the same issue. @blackmore466 were you able to fix the issue yet?