swagger-api / swagger-api/swagger-codegen
Cookie header is not passed by C# client
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When generating the Client it is not possible to specify the Cookie header and have it passed through to the server.
Swagger-codegen version
2.2.1
Command line used for generation
swagger-codegen-cli-2.2.1.jar generate -l csharp
Steps to reproduce
Generate a swagger definition as C#
Add "Cookie" to the defaultheader
Observe that the request sent does not contain the cookie.
Suggest a fix/enhancement
By updating the ApiClient.cs file I was able to pull out the Cookie header and assign it to the CookieContainer utilized by the RestSharp library.
// set timeout
RestClient.Timeout = Configuration.Timeout;
// set user agent
RestClient.UserAgent = Configuration.UserAgent;
// set cookies
var cookies = new CookieContainer();
foreach (var c in headerParams.Where(x => x.Key.Equals("Cookie", StringComparison.CurrentCultureIgnoreCase)).First().Value.Split(new string[] { "; " }, StringSplitOptions.None))
{
var k = c.Split('=');
if (k.Length < 2) continue;
cookies.Add(new Uri(RestClient.BaseUrl.AbsoluteUri), new Cookie(k[0], k[1]));
}
RestClient.CookieContainer = cookies;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache at the referenced client setup around line 206. Generate a C# client from a Swagger definition with Cookie in the default headers, then verify that the outgoing request contains the cookie; the existing reproduction and suggested CookieContainer approach define the expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100