Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.0.1 - XML documentation parser not very forgiving with param comment for missing parameter #214

Closed
latenightcoder opened this issue Mar 6, 2015 · 1 comment
Milestone

Comments

@latenightcoder
Copy link

Hi again,

Turns out if the XML documentation has a param element specified but there are no parameters defined in the action, it blows up.

Example :-

        /// <summary>
        /// Gets basic profile data of logged-in user
        /// </summary>
        /// <param></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResponse<VM.UserInfo>> Info()

Exception :-

Value cannot be null. Parameter name: source ---> System.ArgumentNullException: Value cannot be null. Parameter name: source

at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at Swashbuckle.Swagger.Filters.ApplyXmlActionComments.ApplyParamComments(Operation operation, XPathNavigator methodNode) in c:\Users\Joel\Documents\GitHub\Swashbuckle\Swashbuckle.Core\Swagger\Filters\ApplyXmlActionComments.cs:line 70
at Swashbuckle.Swagger.Filters.ApplyXmlActionComments.Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) in c:\Users\Joel\Documents\GitHub\Swashbuckle\Swashbuckle.Core\Swagger\Filters\ApplyXmlActionComments.cs:line 40
at Swashbuckle.Swagger.SwaggerGenerator.CreateOperation(ApiDescription apiDescription, SchemaRegistry schemaRegistry) in c:\Users\Joel\Documents\GitHub\Swashbuckle\Swashbuckle.Core\Swagger\SwaggerGenerator.cs:line 153
at Swashbuckle.Swagger.SwaggerGenerator.CreatePathItem(IEnumerable`1 apiDescriptions, SchemaRegistry schemaRegistry) in c:\Users\Joel\Documents\GitHub\Swashbuckle\Swashbuckle.Core\Swagger\SwaggerGenerator.cs:line 97
at Swashbuckle.Swagger.SwaggerGenerator.<>c__DisplayClass7.<GetSwagger>b__4(IGrouping`2 group) in c:\Users\Joel\Documents\GitHub\Swashbuckle\Swashbuckle.Core\Swagger\SwaggerGenerator.cs:line 48
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
at Swashbuckle.Swagger.SwaggerGenerator.GetSwagger(String rootUrl, String apiVersion) in c:\Users\Joel\Documents\GitHub\Swashbuckle\Swashbuckle.Core\Swagger\SwaggerGenerator.cs:line 44
at Swashbuckle.Application.SwaggerDocsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) in c:\Users\Joel\Documents\GitHub\Swashbuckle\Swashbuckle.Core\Application\SwaggerDocsHandler.cs:line 32
at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Web.Http.HttpServer.<SendAsync>d__0.MoveNext()

Joel

@latenightcoder
Copy link
Author

Removing the param element fixes things but it seems like a null check on operation.parameters would be handy.

private static void ApplyParamComments(Operation operation, XPathNavigator methodNode)
        {
            var paramNodes = methodNode.Select(ParameterExpression);
            while (paramNodes.MoveNext())
            {
                var paramNode = paramNodes.Current;
                var parameter = operation.parameters.SingleOrDefault(param => param.name == paramNode.GetAttribute("name", ""));
                if (parameter != null)
                    parameter.description = paramNode.Value.Trim();
            }
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants