RicoSuter/NSwag

Cannot escape variable value with space

Open

#1,318 opened on May 14, 2018

View on GitHub
 (6 comments) (0 reactions) (0 assignees)C# (1,189 forks)batch import
help wantedtype: enhancement

Repository metrics

Stars
 (6,291 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

I try to pass the output directory as a variable to command line nswag tool via MsBuild. nswag file:

{
  "runtime": "WinX86",
  "defaultVariables": "OutDir=bin\\x86\\Debug",
  "swaggerGenerator": {
    "webApiToSwagger": {
      ...
      "assemblyPaths": [
        "$(OutDir)\\target.dll"
      ],
      "assemblyConfig": "",
      "referencePaths": []
      ...
    }
  }
  ...

MsBuild Script fragment:

<PostBuildEvent>$(NSwagExe_x86) run $(ProjectDir)MyProject.nswag /variables:OutDir=$(OutDir)</PostBuildEvent>

If the output directory has a space in it, this does not work (obviously), and invalid path io error is reported, because the path fragment after the first space is not picked up.

I tried to escape the variable like this:

<PostBuildEvent>$(NSwagExe_x86) run $(ProjectDir)MyProject.nswag "/variables:OutDir=$(OutDir)"</PostBuildEvent>

or like this:

<PostBuildEvent>$(NSwagExe_x86) run $(ProjectDir)MyProject.nswag /variables:OutDir="$(OutDir)"</PostBuildEvent>

but the end result is in both cases illegal characters in path exception, bacuse the quotes are included in the variable value.

System.ArgumentException: Illegal characters in path. at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional) at System.IO.Path.IsPathRooted(String path) at NSwag.Commands.NSwagDocument.ConvertToAbsolutePath(String pathToConvert) at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at NSwag.Commands.NSwagDocumentBase.ConvertToAbsolutePaths() at NSwag.Commands.NSwagDocumentBase.FromJson[TDocument](String filePath, String data) at NSwag.Commands.NSwagDocumentBase.<>c__DisplayClass35_0`1.<b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NSwag.Commands.NSwagDocument.d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NSwag.Commands.Document.ExecuteDocumentCommand.d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NSwag.Commands.Document.ExecuteDocumentCommand.d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NConsole.CommandLineProcessor.d__12.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NConsole.CommandLineProcessor.d__11.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NConsole.CommandLineProcessor.Process(String[] args, Object input) at NSwag.Commands.NSwagCommandProcessor.Process(String[] args)

Is there a way to escape spaces in variables? Or is this not supported?

Contributor guide