swagger-api / swagger-api/swagger-codegen

C# code generation project does not compile (but here is the fix)

Open
#10,136 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

The code generated on website https://editor.swagger.io/ for csharp is wrong
(i did not test for csharp-dotnet2)

I did one thing to make the code to compile :
In file ApiClient.cs I added the method:

        public FileParameter ParameterToFile(string name, byte[] bytes)
        {
            return FileParameter.Create(name, bytes, "no_file_name_provided");
        }

Now, at runtime there is still an error (related to RestSharp dependency),
I got this (mesage translated to english):
System.UriFormatException: 'URI not valid: Cannot determinate URI format'
on the line
RestClient = new RestClient(basePath);
in the constructor
public ApiClient(String basePath = "/")
So I changed in Configuration.cs:
BasePath = "/";
by
BasePath = "http://localhost";

Note also that the code does not compile if we update RestSharp to the latest stable version
(106.10.1 currently)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated ApiClient.cs and Configuration.cs described in the report, then compare the C# output from editor.swagger.io with the RestSharp version in use. Reproduce the compilation failure, the basePath runtime error, and the latest-RestSharp incompatibility; done means the generated project compiles and initializes without those errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.