Namotion.Reflection icon indicating copy to clipboard operation
Namotion.Reflection copied to clipboard

Documentation not being generated for models from NuGet packages

Open jeremyVignelles opened this issue 5 years ago • 22 comments
trafficstars

I have some models exposed in my APIs that come from NuGetPackages.

While those types are properly documented (I can see the doc in intellisense), they have no documentation in the generated OpenApi spec.

This does not happen on netcoreapp2.1, but does happen on netcoreapp3.1.

To highlight this issue, please see this repro: 3.1 branch : https://github.com/jeremyVignelles/TestNSwagNetCoreApp/blob/repro/doc-external-models/TestNSwagNetCoreApp/Hello.cs#L42

2.1 branch: https://github.com/jeremyVignelles/TestNSwagNetCoreApp/blob/repro/doc-external-models-netcoreapp2.1/TestNSwagNetCoreApp/Hello.cs#L42

I used a type from the NSwag NuGet package to highlight the issue.

jeremyVignelles avatar Jan 09 '20 15:01 jeremyVignelles

Looks like .net core 3 uses another way to reference dlls in packages so that xml docs files cannot be found.

We need to repro and fix this here: https://github.com/RicoSuter/Namotion.Reflection

RicoSuter avatar Jan 11 '20 19:01 RicoSuter

@RicoSuter Is there a workaround for that in the meantime? This is pretty painful for us. Too late to go back to .net core 2.x unfortunately.

bpaczkowski avatar Feb 28 '20 09:02 bpaczkowski

Moved to Namotion.Reflection - please repro and fix here.

RicoSuter avatar Mar 05 '20 13:03 RicoSuter

Related: https://github.com/RicoSuter/Namotion.Reflection/issues/23

RicoSuter avatar Mar 05 '20 13:03 RicoSuter

Here is a repro for the bug using only Namotion as a NuGet package. https://github.com/jeremyVignelles/TestNamotion

I don't know why, I didn't manage to get the XML documentation of my Program class...

jeremyVignelles avatar Mar 05 '20 18:03 jeremyVignelles

Just added a test and it seems that the XML doc file is not part of the output - only the DLL:

image

(there should be a NJsonSchema.xml)

RicoSuter avatar Mar 06 '20 08:03 RicoSuter

With .NET Core 2.1 the DLL is referenced in the NuGet cache where the XML is available:

image

RicoSuter avatar Mar 06 '20 09:03 RicoSuter

PR: https://github.com/RicoSuter/Namotion.Reflection/pull/34

RicoSuter avatar Mar 06 '20 09:03 RicoSuter

Any idea how we can instruct the compiler to not only output NuGet DLLs but also the XML Docs?

/cc @pranavkm sorry to bother you again - is this possible?

RicoSuter avatar Mar 06 '20 09:03 RicoSuter

I'd have thought setting <GenerateDocumentationFile>true</GenerateDocumentationFile> should suffice which your project files have set - https://github.com/RicoSuter/Namotion.Reflection/pull/34/files#diff-a0b803fa5e2b2695ee9b80fe5a60a373R5

pranavkm avatar Mar 06 '20 16:03 pranavkm

<GenerateDocumentationFile>true</GenerateDocumentationFile>

Only outputs the xml docs for the project itself but not for the referenced NuGet packages. So this is quite the breaking change in .net core 3.0/3.1 it seems

RicoSuter avatar Mar 06 '20 16:03 RicoSuter

Ahh, are the xml files from package references no longer being copied to the output directory?

pranavkm avatar Mar 06 '20 16:03 pranavkm

Ahh, are the xml files from package references no longer being copied to the output directory?

It seems that this is not the case anymore... see my screenshots. The question is whether there is a csproj config where we can enable that again.

RicoSuter avatar Mar 06 '20 17:03 RicoSuter

I'm not entirely sure if this was a change in the 3.x SDK. You might have much better luck asking this question of https://github.com/dotnet/core-sdk/issues.

pranavkm avatar Mar 06 '20 21:03 pranavkm

@bpaczkowski here is a workarround https://github.com/RicoSuter/NSwag/issues/2161#issuecomment-606091808

danielmeza avatar Mar 30 '20 16:03 danielmeza

Here is other solution, copy the .xml from nuget folder to the build folder https://snede.net/add-nuget-package-xml-documentation-to-swagger/

danielmeza avatar Mar 30 '20 16:03 danielmeza

Ref https://github.com/dotnet/sdk/issues/1458#issuecomment-420456386 https://github.com/dotnet/sdk/issues/1458#issuecomment-695119194

Adding this here works for me (at least in the test project): https://github.com/dotnet/sdk/issues/1458#issuecomment-401497095

RicoSuter avatar Oct 21 '20 20:10 RicoSuter

v1.0.20 might be a version where this is improved but might not be fixed in all scenarios.

RicoSuter avatar May 04 '21 15:05 RicoSuter

Ref: https://github.com/dotnet/sdk/issues/9498

https://twitter.com/RicoSuter/status/1468312527637467137

RicoSuter avatar Dec 10 '21 16:12 RicoSuter

It looks to be a bug in XmlDocsExtensions.GetXmlDocsPathFromNuGetCacheFile which happens on Linux:

                var matches = Regex.Matches(json, $"\"((.*?){assemblyName.Name}((\\\\\\\\)|(////)){assemblyName.Version.ToString(3)})((\\\\\\\\)|(////))(.*?)\"", RegexOptions.IgnoreCase);

It should be a single forward slash - not four because no escaping is needed. Same could be applicable to runtimeConfigRegex declared in the same file.

mediawolf avatar May 12 '23 11:05 mediawolf