Nswag: AspNetCoreToSwagger : Wrong output path when setting the "configuration" parameter

Created on 29 Jul 2018  路  9Comments  路  Source: RicoSuter/NSwag

Hi,

When I try to change the configuration parameter of the AspNetCoreToSwagger generator, NSwag searches the output in the wrong directory

I use NSwag.MSBuild 11.17.21

This is my original config and it works fine:

csproj

  <Target Name="NSwag" AfterTargets="Build">
    <Exec Command="$(NSwagExe_Core21) run nswag.json" />
  </Target>

nswag.json

//
{
  "runtime": "NetCore21",
  "swaggerGenerator": {
    "aspNetCoreToSwagger": {
      "project": "MyProj.csproj",
      "output": "wwwroot/dev/swagger/v1/swagger.json",
      "noBuild": true,
      "defaultEnumHandling": "String",
      "defaultPropertyNameHandling": "CamelCase",
      "defaultReferenceTypeNullHandling" : "NotNull"
    }
  }
}

As soon as I try to change the configuration, NSwag introduces the absolute path to Debug folder again.

System.InvalidOperationException: Project outputs could not be located in '/home/sro/projects/xxx/src/MyProj/bin/home/sro/projects/xxx/src/MyProj/Debug/netcoreapp2.1/'. Ensure that the project has been built.

this is the modified config:

csproj

  <Target Name="NSwag" AfterTargets="Build">
    <Exec Command="$(NSwagExe_Core21) run nswag.json /variables:Configuration=$(Configuration)" />
  </Target>

nswag.json

//
{
  "runtime": "NetCore21",
  "defaultVariables": "Configuration=Debug",
  "swaggerGenerator": {
    "aspNetCoreToSwagger": {
      "project": "MyProj.csproj",
      "configuration": "$(Configuration)",
      "output": "wwwroot/dev/swagger/v1/swagger.json",
      "noBuild": true,
      "defaultEnumHandling": "String",
      "defaultPropertyNameHandling": "CamelCase",
      "defaultReferenceTypeNullHandling" : "NotNull"
    }
  }
}

I tried both on Linux and Windows, same problem

Thanks for your help!

NSwag.AspNetCore bug

Most helpful comment

Sorry for the delay, I haven't seen the notifications :(

Here is a sample project based on the "dotnet new webapi" template
I tried with the sdk 2.1.302

If you remove the "configuration" property from nswag.json, it works as expected

nswag_issue.zip

All 9 comments

Can you provide a sample project?

(Sorry, referenced wrong issue... commit closes https://github.com/RSuter/NSwag/issues/1484)

@pranavkm Do you have time to look into this?

Sure, I'll give this a try sometime today.

Btw, a sample project will greatly expedite the time it takes to investigate 馃憤

Sorry for the delay, I haven't seen the notifications :(

Here is a sample project based on the "dotnet new webapi" template
I tried with the sdk 2.1.302

If you remove the "configuration" property from nswag.json, it works as expected

nswag_issue.zip

@RSuter looks like the issue is here -

https://github.com/RSuter/NSwag/blob/master/src/NSwag.Commands/NSwagDocumentBase.cs#L338-L339

It turns the string Debug to a folder path /src/MyProj/Debug which messes up things. Any idea why that's treated as path?

This looks like a bug. I will look into this, thank you.

v11.18.1

Was this page helpful?
0 / 5 - 0 ratings