Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML comments file could not be found - Swagger

This is certainly one of those that drives you nuts. As the title indicates all I'm simply trying to do is display comments pulled from an xml file using swagger.

I appear to have taken all steps according to the swagger documentation but to no avail. Hopefully you kind folk can point me in the right direction.

Steps Taken: enter image description here

Ensured file exists:

enter image description here

Configured SwaggerConfig.cs

enter image description here

I've tried changing the path too: @"bin/....xml"

Nothing seems to work.

**The Error "Could not find file": **

enter image description here

Can anyone point me in the right direction please?

Regards,

like image 998
Tez Wingfield Avatar asked Jun 22 '16 12:06

Tez Wingfield


People also ask

How to comment in Swagger?

Click on the + button on the left of each line of the Swagger spec to add your comment from the Comment Bar. The Comment Bar houses all the comments, both resolved and unresolved, on the API spec, sorted by line. You can access the Comment Bar anytime from the Swagger UI.

How do I put comments in XML?

An XML comment encountered outside the document type declaration is represented by the Comment value syntax element. It contains the comment text from the XML message. If the value of the element contains the character sequence --> , the sequence is replaced with the text --> .


2 Answers

in .net core 3.0

<GenerateDocumentationFile>true</GenerateDocumentationFile> 

in PropertyGroup tag of .csproj file

like image 116
mosess Avatar answered Sep 23 '22 02:09

mosess


These are the steps I needed in .Net Core 2.2:

Put this in Startup.cs:

    public void ConfigureServices(IServiceCollection services)     {          ...          // Register the Swagger generator, defining 1 or more Swagger documents         services.AddSwaggerGen(c =>             {                 ...                  var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";                 var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);                 c.IncludeXmlComments(xmlPath);             });     } 

Edit your .csproj file and add / change these nodes:

  <PropertyGroup>     ...     <!--      Make sure documentation XML is also included when publishing (not only when testing)     see https://github.com/Azure/service-fabric-issues/issues/190     -->     <GenerateDocumentationFile>true</GenerateDocumentationFile>   </PropertyGroup>    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">     ...     <DocumentationFile>bin\$(Configuration)\$(AssemblyName).xml</DocumentationFile>   </PropertyGroup> 
like image 39
Jpsy Avatar answered Sep 24 '22 02:09

Jpsy