Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #6191
Closed
Open
Issue created May 06, 2020 by Administrator@rootContributor3 of 6 checklist items completed3/6 checklist items

[BUG][csharp-netcore] No provision to pass cookies to the ApiClient

Created by: vvb

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Their is a provision to pass headers in the configuration using DefaultHeaders. But passing cookie here does not seem to work.

For the below code, a wire capture shows the origin header, but cookie param is not found in the message. It gets saved into DefaultParameters but not consumed.

Org.OpenAPITools.Client.Configuration config = new Org.OpenAPITools.Client.Configuration();
var api = new Org.OpenAPITools.Api.NtpApi(config);
var url = endpoint + "ntp/Policies";
var intersightHeaders = new Dictionary<string, string>()
{
    { "cookie", "Param="+Value },
    { "origin", url }
};
foreach (var h in intersightHeaders)
{
    api.Configuration.DefaultHeaders.Add(h.Key, h.Value);
}
openapi-generator version

latest master

OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix

We could make a change in the ApiClient, if it comes across a header with Name "Cookie", then it could do the below instead.


diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/ApiClient.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/ApiClient.mustache
index 49b81c72e0..8592f55720 100644
--- a/modules/openapi-generator/src/main/resources/csharp-netcore/ApiClient.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp-netcore/ApiClient.mustache
@@ -271,6 +271,21 @@ namespace {{packageName}}.Client
             {
                 foreach (var headerParam in configuration.DefaultHeaders)
                 {
+                   if (String.Equals(headerParam.Key, "cookie", StringComparison.OrdinalIgnoreCase))
+                    {
+                        string[] cookieSeparators = new string[] {";"};
+                        string[] EqualSeparator = new string[] {"="};
+                        string[] rawCookieParams = headerParam.Value.Split(cookieSeparators, StringSplitOptions.None);
+                        foreach (string paramset in rawCookieParams)
+                        {
+                            String[] param = paramset.Split(EqualSeparator, StringSplitOptions.None);
+                            if (param.Length == 2)
+                            {
+                                request.AddCookie(param[0], param[1]);
+                            }
+                        }
+                        continue;
+                    }
                     request.AddHeader(headerParam.Key, headerParam.Value);
                 }
             }
Assignee
Assign to
Time tracking