Swashbuckle.WebApi: Swashbuckle doesn't work properly with inheritdoc
I have following xmldoc generated:
<member name="P:Gate.GateConfig.Connection"> <inheritdoc /> </member>
And this member is inherited from an interface. Visual Studio shows this properly, but output swagger is generated without information from parent.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 47
- Comments: 20
Are there are news here? It’s been over 4 years this has been opened.
I got into this situation today as well while doing some cleanup on some of our models. We have an interface defining a few properties that many DTOs have and changed the classes to use
<inheritdoc />only to find that the text vanished from the schema.In the meantime this is how you can workaround the problem
dotnet tool -g install InheritDoc@julealgon I just ran into this issue myself today. Seems like they haven’t implemented it because you can do it yourself pretty easily by pre-processing the XML docs before adding them to Swagger. Here is the code I am using (inspired by this):
The
ArgOptionsvariable refers to an instance ofSwaggerGenOptionswhich you use to add the XML files.People say this to anything even if it’s 56 lines of code…
Thanks! I had to run a slightly different command on my end:
You would have to “dereference the pointer” similar to the example I showed, but with some modifications to locate the
<member>element containing the docs from the base class and copy those XML elements to the<member>element for the child class. Example: the base class XML docs may look like this:The child class will then use
<inheritdoc>and look something like this:The task is then to (1) use XPath to find all
<member>elements that contain an<inheritdoc/>element, (2) get the value from thenameattribute (which isM:MyNameSpace.MyChildClass.MyMethodFooin the above example), (3) map that value to the name in the base class (which isM:MyNameSpace.MyBaseClass.MyMethodFooin the above example), (4) use the mapped name and XPath to locate the<member>element containing docs for the base class, (5) copy XML nodes from the base class docs and replace them into the<member>element for the child class which originally contained the<inheritdoc/>element.The tricky part is mapping from M:MyNameSpace.MyChildClass.MyMethodFoo to M:MyNameSpace.MyBaseClass.MyMethodFoo in order to locate the base class docs. The rest (using XPath, replacing XML nodes, etc) is shown in the code I gave earlier.
Hopefully that points you in the right direction!
Just ran into this myself - not actually sure if this is possible, as the generated XML doc doesn’t seem to contain any information relating to the inheritance chain. I expect Visual Studio needs to deal with this before Swagger can.
yeah, nothing changed!