RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.78k stars 1.29k forks source link

Adding comments to generated OpenAPI file does not work on macos #4116

Open dasMulli opened 2 years ago

dasMulli commented 2 years ago

Using nswag MSBuild tool's aspnetcore2openapi command does not correctly resolve the XML documentation on macos.

See this repro: https://github.com/dasMulli/nswag-macos-issue

After building the project on macos, the generated openapi.json file in the root directory does not contain the summary of the WeatherForecastController/Get method.

It seems that it can be fixed with a patch to Namotion.Reflection, but I'm not sure if that's the necessary fix here (provided that it seems to work on linux):

XmlDocsExtensions.cs ```diff --- a/src/Namotion.Reflection/XmlDocsExtensions.cs +++ b/src/Namotion.Reflection/XmlDocsExtensions.cs @@ -771,7 +771,7 @@ namespace Namotion.Reflection if (!string.IsNullOrEmpty(codeBase)) { path = DynamicApis.PathCombine(DynamicApis.PathGetDirectoryName(codeBase - .Replace("file:///", string.Empty)), assemblyName.Name + ".xml") + .Replace("file://", string.Empty)), assemblyName.Name + ".xml") .Replace("file:\\", string.Empty); if (DynamicApis.FileExists(path)) ```
Fennixx commented 2 years ago

This issue is preventing me to work on my project on MacBook. @RicoSuter please help.

Fennixx commented 2 years ago

Fixed by not using aspnetcore2openapi command. Used nswag with config instead.

andrew-potachits commented 1 year ago

Fixed by not using aspnetcore2openapi command. Used nswag with config instead.

@Fennixx How did you use nswag before and what did you do to resolve (overcome) the issue? I'm having the same issue with API comments missing when I run it on MacOS.

Fennixx commented 1 year ago

Fixed by not using aspnetcore2openapi command. Used nswag with config instead.

@Fennixx How did you use nswag before and what did you do to resolve (overcome) the issue? I'm having the same issue with API comments missing when I run it on MacOS.

Unfortunatelly, I dont have access to code base where I had the issue any more, but as an example, you need to create the nswag.json file with the configuration what you need. Basic example:

{
  "runtime": "NetCore31",
  "defaultVariables": "Configuration=Release",
  "documentGenerator": {
    "aspNetCoreToOpenApi": {
      "project": "./path/to/YourProject.csproj",
      "configuration": "Release",
      "output": "./output/swagger.json",
      "verbose": true
    }
  },
  "codeGenerators": {
    "openApiToTypeScriptClient": {
      "className": "ApiClient",
      "output": "./output/api-client.ts"
    }
  }
}

then you will call instead of aspnetcore2openapi something like this:

nswag run /runtime:NetCore31 /variables:Configuration=Release /input:nswag.json
andrew-potachits commented 1 year ago

I'm currently using the webApiToOpenApi generator, worth trying the aspNetCoreToOpenApi instead. Thanks.