question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation is not generated for routes with generic parameters or return types.

See original GitHub issue

In our organization, we have generic abstract controllers that we use as base controllers for all our data access APIs. The current algorithm that swagger uses to generate the documentation doesn’t know how to handle this scenario because the method documentation signature has generic heuristics.

Here is an example of what the controller looks like with one of the generic methods included.

public abstract class ReadController<TEntity, TKey, TContext, TFilter, TInclude> :
        ApiController
        where TEntity : class, new()
        where TContext : IDbContext
        where TFilter : class, new()
        where TInclude : struct, IComparable, IConvertible, IFormattable
    {
        /// <summary>
        /// Gets the entity by the given key.
        /// </summary>
        [Route("{key}")]
        [HttpGet]
        public virtual async Task<HttpResponseMessage> Get(TKey key, [FromUri] ICollection<TInclude?> includes = null, [FromUri] ICollection<string> fields = null)
        {
        }
}

The XML that is generated for this method output by MSbuild is as follows:

<member name="M:Jane.Data.WebHost.ReadController`5.Get(`1,System.Collections.Generic.ICollection{System.Nullable{`4}},System.Collections.Generic.ICollection{System.String})">
  <summary>
    Gets the entity by the given key.
  </summary>
</member>

Even though we are including this XML file in the bin folder and ensure it gets added through the swagger call IncludeXmlComments(), no documentation is added to the route in the SwaggerUI.

The issue lies in the ApplyXmlActionComments.Apply() method in Swashbuckle.Swagger; essentially, it just fails to comprehend this method signature in the XML file and therefore cannot match the generic method to its documentation.

Would be nice to have this scenario accounted for so as to make generic routes display documentation as desired.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:46 (22 by maintainers)

github_iconTop GitHub Comments

3reactions
mikeandikecommented, May 6, 2016

I have the same issue!

1reaction
heldersepucommented, Oct 14, 2017

@yojagad Done the update version is on nuget.org: https://www.nuget.org/packages/Swagger-Net/8.3.3.103

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation is not generated for routes with generic ...
I think it is related to #749. Seems like Swashbuckle can't extract comments when parameter is of generic array type TEntity[] . [Route( ......
Read more >
c# - Multiple HttpGet that differ by route parameter cannot ...
It appears that swagger is getting upset because both endpoints return a type that contains the same transfer object.
Read more >
Springdoc with a generic return type - java
Ideally, I would be able to do @Schema(implementation = CustomPage<ReducedVersion>.class) , but it's not possible in Java. Does Spring provide a ...
Read more >
Using parameters in routes
Parameters can be used to pass dynamic values from the URI to the controller.
Read more >
Documentation comments - C# language specification
This appendix describes XML comments that are used to document your program.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found