unchase / Unchase.Swashbuckle.AspNetCore.Extensions

:hammer: A library contains a bunch of extensions (filters) for Swashbuckle.AspNetCore.
https://www.nuget.org/packages/Unchase.Swashbuckle.AspNetCore.Extensions
Apache License 2.0
115 stars 16 forks source link

NullReferenceException when using routing attribute #10

Closed jaroslavcervenka closed 4 years ago

jaroslavcervenka commented 4 years ago

Hi.

I have a problem with your awesome library. When I'm using routing attribute with a variable which is used by middleware or by service (not in controller action) the generator fails with "Null reference exception" becouse there is neither ParameterInfo nor PropertyInfo in https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/blob/ced7630eaa9e094aab42e27edfe12a433273927f/src/Unchase.Swashbuckle.AspNetCore.Extensions/Filters/XEnumNamesParameterFilter.cs#L65

You can try to use routing attribute [Route("{version}")] above controller action. I suggest to adjust a code block in XEnumNamesParameterFilter with:

var typeInfo = context.ParameterInfo?.ParameterType ?? context.PropertyInfo?.PropertyType;

if (typeInfo == null)
{
    return;
}

Thanks and regards. Jarek

unchase commented 4 years ago

@jaroslavcervenka The bug was fixed in the last release. Thanks for the report.