I reference an OpenAPI service using the "Connected Services" feature in Visual Studio (2002 Prev 5, but same behavior in VS 2019). This tool is based on NSwag. The docs say that I can apply all settings from Nswag in certain elements of <OpenApiReference>
element in *.csproj.
This works, but I want to use an output path different from the default (obj) and this setting can't handle .. paths and paths with spaces. The same setting on Nswag's command line tool works as expected.
My first approach in *.csproj with an output path without spaces:
<ItemGroup>
<OpenApiReference Include="swagger.json"
CodeGenerator="NSwagCSharp" Namespace="Demo.Proxy"
ClassName="ContractService"
OutputPath="ConnectedServices\Backend\ContractService.cs"
>
<Options>/DateTimeType:DateTime /GenerateClientInterfaces:true</Options>
</OpenApiReference>
</ItemGroup>
This results in a file obj\ConnectedServices\Backend\ContractService.cs. Correct.
But I want to use the "Connected Services" folder (with a space):
<ItemGroup>
<OpenApiReference Include="swagger.json"
CodeGenerator="NSwagCSharp" Namespace="Demo.Proxy"
ClassName="ContractService"
OutputPath="Connected Services\Backend\ContractService.cs"
>
<Options>/DateTimeType:DateTime /GenerateClientInterfaces:true</Options>
</OpenApiReference>
</ItemGroup>
This results in a file obj/Connected. It stops before the space. Not correct.
I tried:
%20
--> same result, stop before space"
from begin to end --> invalid character error..\
path to get out of obj --> invalid character error
Also, just out of curiosity, I used properties like this:
<PropertyGroup>
<ServicesPath>ConnectedServices\ContractService.cs</ServicesPath>
</PropertyGroup>
<ItemGroup>
<OpenApiReference Include="swagger.json" CodeGenerator="NSwagCSharp" Namespace="Demo.Proxy" ClassName="ContractService"
OutputPath="$([System.IO.Path]::Combine($(MSBuildProjectDirectory),$(ServicesPath)))"
>
<Options>/DateTimeType:DateTime /GenerateClientInterfaces:true</Options>
</OpenApiReference>
</ItemGroup>
Same result here: "ConnectedServices" works, "Connected Services" doesn't; the space kills the path and the result is just "Connected", remaining part ignored.
However, this fixes the "obj" folder issue and moves the file to the proper level.
I think it's a bug in OpenApiReference but I want to ask before I file a bug report because I could have overlooked something. Just in case.