2

The following model makes Swashbuckle throw an exception when it tries to generate the document. Please, notice that I'm decorating the properties Predicate and OrderParts with the [BindNever] attribute (they are assigned with values in an action filter) but property Predicate is causing the issues. Below the model and the exception message. Any help on this is much appreciated.

Version: v5.0.0.0

    /// <summary>
    /// Defines the request to get, filter, order, and paginate the vessels.
    /// </summary>
    public sealed class GetPageOfVesselsRequest : IPaginationRequest, IFilterRequest<Vessel>, IOrderRequest<Vessel>
    {
        /// <summary>
        /// Defines the page id.
        /// </summary>
        [FromQuery(Name = GlobalRequestsNamesReference.Page)]
        public int? Page { get; set; }

        /// <summary>
        /// Defines the page size.
        /// </summary>
        [FromQuery(Name = GlobalRequestsNamesReference.Size)]
        public int? Size { get; set; }

        /// <summary>
        /// Defines the RQL filter expression.
        /// </summary>
        [FromQuery(Name = GlobalRequestsNamesReference.Filter)]
        public string Filter { get; set; }

        /// <summary>
        /// Defines the predicate associated to the filter expression (if applicable).
        /// </summary>
        [BindNever]
        public Func<Vessel, bool> Predicate { get; set; }

        /// <summary>
        /// Defines the RQL order expression.
        /// </summary>
        [FromQuery(Name = GlobalRequestsNamesReference.Order)]
        public string Order { get; set; }

        /// <summary>
        /// Defines the order parts associated to the order expression (if applicable).
        /// </summary>
        [BindNever]
        public IEnumerable<OrderPart> OrderParts { get; set; }
    }

Exception Stacktrace: An unhandled exception has occurred while executing the request. System.Collections.Generic.KeyNotFoundException: The given key 'System.Reflection.TypeInfo' was not present in the dictionary. at System.Collections.Generic.Dictionary2.get_Item(TKey key) at Swashbuckle.AspNetCore.SwaggerGen.PrimitiveSchemaGenerator.GenerateSchemaFor(Type type, SchemaRepository schemaRepository) at Swashbuckle.AspNetCore.SwaggerGen.ChainableSchemaGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository) at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository) at Swashbuckle.AspNetCore.SwaggerGen.ArraySchemaGenerator.GenerateSchemaFor(Type type, SchemaRepository schemaRepository) at Swashbuckle.AspNetCore.SwaggerGen.ChainableSchemaGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository) at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateParameter(ApiDescription apiDescription, ApiParameterDescription apiParameter, SchemaRepository schemaRepository) at System.Linq.Enumerable.WhereSelectListIterator2.ToList() at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperation(ApiDescription apiDescription, SchemaRepository schemaRepository) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperations(IEnumerable1 apiDescriptions, SchemaRepository schemaRepository) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)

Thanks

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
EmilioV
  • 232
  • 2
  • 10
  • I'm not sure if this is relevant to the ASP.NET Core version, but take a look at [this answer](https://stackoverflow.com/a/48454933/3181933). – ProgrammingLlama Jan 15 '21 at 06:14
  • No, unfortunately, using an operation filter or a schema filter doesn't work here, the exception is thrown before the filters are called. – EmilioV Jan 15 '21 at 06:17
  • Ah. I don't know then, I'm afraid. Hopefully someone else does :) – ProgrammingLlama Jan 15 '21 at 06:26
  • [This documentation](https://learn.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-5.0#attributes-for-complex-type-targets) seems to indicate that those attributes do not impact this scenario – Aluan Haddad Jan 15 '21 at 06:39
  • Why are you using version 5.0.0? The latest one is 5.6.3. There is a few similar issues in their github, which was fixed in newest versions – Pavel Anikhouski Jan 15 '21 at 09:08
  • @Aluan Haddad, the [BindNever] attribute should prevent Swashbuckle to generate any documentation about the property and/or parameter being decorated. The documentation that you have linked serves to me to reaffirms that the [BindNever] attribute shouldn't be considered by Swashbuckle to generate any documentation. – EmilioV Jan 15 '21 at 15:25
  • @Pavel Anikhouski, unfortunately, I'm referencing an internal package (some required filters are defined in it) that targets that version (v5.0.0.0) and using .net core 2.2. – EmilioV Jan 15 '21 at 15:30
  • @EmilioV It shouldn't be a problem, you can use upgraded version 5.6.3 instead of transitive from internal package – Pavel Anikhouski Jan 15 '21 at 16:05
  • 1
    @PavelAnikhouski I have upgraded Swashbuckle.AspNetCore to its latest version (5.6.3) and yes, the exception disappeared but now a lot of unrequired schemes and parameters are being generated, all them related to the property [BindNever] public Func Predicate { get; set; }. I have reported this issue in the Swashbuckle.AspNetCore's GitHub project site but no answer yet. – EmilioV Jan 19 '21 at 14:32

0 Answers0