rbeauchamp / Swashbuckle.OData

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

ODataQueryOptions causes extra definitions to be created #168

Closed andyward closed 6 years ago

andyward commented 6 years ago

When an OData controller action has an ODataQueryOptions parameter this seems to cause the ODataQueryOptions type to be picked up as a normal input parameter, which the gets defined in the the Swagger JSON definitions/params. This also results in the Swagger UI expecting the OData options to be supplied as a parameter.

E.g. Amending the CustomersController in the Samples projects as follows:

[EnableQuery(PageSize = 5)]
public async Task<IHttpActionResult> Get(ODataQueryOptions<Customer> options)
{
    var customers = await _db.Customers.ToListAsync();
    return Ok(customers);
}

... results in this Swagger output image

In the Swagger UI this is manifested as an extra parameter on the Action. E.g. image

I've got a simple fix for this, with a covering test. Happy to put in a PR if that helps. It's a one-line fix to ODataActionDescriptorMapperBase.CreateParameterDescriptions to check parameterBinding.Descriptor.IsODataLibraryType() before adding.

rbeauchamp commented 6 years ago

Fixed in https://www.nuget.org/packages/Swashbuckle.OData/3.4.1