RicoSuter/NSwag

How to disable generating parameters for headers using SwaggerToCSharpWebApiControllerGenerator

Open

#642 opened on Mar 1, 2017

View on GitHub
 (4 comments) (3 reactions) (0 assignees)C# (6,291 stars) (1,189 forks)batch import
help wantedproject: NSwag.CodeGeneration.CSharp (Clients)type: bug

Description

Swagger document:

{
  "swagger": "2.0",
  "paths": {
    "/authorization": {
      "put": {
        "operationId": "Test",
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "204": {
            "description": ""
          }
        }
      }
    }
  }
}

Generated code:

namespace MyNamespace
{
    #pragma warning disable // Disable all warnings

    [System.CodeDom.Compiler.GeneratedCode("NSwag", "9.6.6264.38294")]
    public interface IController
    {
        System.Threading.Tasks.Task TestAsync(string authorization);
    
    }
    
    [System.CodeDom.Compiler.GeneratedCode("NSwag", "9.6.6264.38294")]
    public partial class Controller : System.Web.Http.ApiController 
    {
        private IController _implementation; 
    
        public Controller(IController implementation)
        {
            _implementation = implementation; 
        }
    
        [System.Web.Http.HttpPut, System.Web.Http.Route("authorization")]
        public System.Threading.Tasks.Task Test(string authorization)
        {	
            return _implementation.TestAsync(authorization);
            
        }
    
    }

}

Contributor guide