RicoSuter / NSwag

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

different client code in docker vs in rider... #4850

Closed mdzieg closed 2 months ago

mdzieg commented 2 months ago

I have a weird issue. When I build project in Rider (net8, debug) I have correct code in swaggerClient.cs. The code has correct handling of 200 and 204 status codes:

                        if (status_ == "200") 
                        {
                            return;
                        }
                        else
                        if (status_ != "200" && status_ != "204")
                        {

When I do a docker build on Linux, using:

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
(...)
RUN dotnet build "XXXX.csproj" -c Debug -o /app/build

FROM build AS publish
ARG Version=1.0.0
RUN dotnet publish "XXXX.csproj" -c Debug -o /app/publish /p:Version=$Version

I have swaggerClient.cs containing wrong code (204 results in exception):

            int status_ = (int) response_.StatusCode;
            if (status_ == 200)
            {
              ...
            }
            else
            {

In the output i can see nswag being called with this command:

dotnet --roll-forward-on-no-candidate-fx 2 "/root/.nuget/packages/nswag.msbuild/14.0.7/buildTransitive/../tools/Net80//dotnet-nswag.dll" openapi2csclient /className:swaggerClient /namespace:XXXX /input:"/src/YYYY/openapi/swagger.json" /output:"obj/swaggerClient.cs"

Is it my fault or is it a bug of some kind?

I tried building with the same commands on win11 and I have dll with correct code.

In the project file we have:

  <ItemGroup>
    <OpenApiReference Include="..\YYYY\openapi\swagger.json" CodeGenerator="NSwagCSharp" Link="OpenAPIs\swagger.json" />
  </ItemGroup>

Project references only:

    <PackageReference Include="NSwag.ApiDescription.Client" Version="14.0.7">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
mdzieg commented 2 months ago

@RicoSuter downgraded back to <PackageReference Include="NSwag.ApiDescription.Client" Version="13.6.2"> and with this version all is okay

so looks like a bug in one of the above versions...

EDIT: the next version after 13.6.2 introduces this problem. i have this problem on 13.7.0

mdzieg commented 2 months ago

i checked changes: https://github.com/RicoSuter/NSwag/commit/e1f7657efe3ac8b4b4f79ffac482e0c0aee21ff1#diff-65b33706483249f53a8138451372e3d3276b904d815dcb71d0ed0c8786ea2e70

and it seems that on my local box old template is used, where status codes are strings, whereas when building on azuredevops new version of the template is used.

i removed all packages from cache and did a rebuild.