{"action":"closed","issue":{"url":"https://api.github.com/repos/NSwag/NSwag/issues/26","labels_url":"https://api.github.com/repos/NSwag/NSwag/issues/26/labels{/name}","comments_url":"https://api.github.com/repos/NSwag/NSwag/issues/26/comments","events_url":"https://api.github.com/repos/NSwag/NSwag/issues/26/events","html_url":"https://github.com/NSwag/NSwag/issues/26","id":125178666,"number":26,"title":"Optional parameters are required - TypeScript","user":{"login":"wapolinar","id":3637190,"avatar_url":"https://avatars.githubusercontent.com/u/3637190?v=3","gravatar_id":"","url":"https://api.github.com/users/wapolinar","html_url":"https://github.com/wapolinar","followers_url":"https://api.github.com/users/wapolinar/followers","following_url":"https://api.github.com/users/wapolinar/following{/other_user}","gists_url":"https://api.github.com/users/wapolinar/gists{/gist_id}","starred_url":"https://api.github.com/users/wapolinar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wapolinar/subscriptions","organizations_url":"https://api.github.com/users/wapolinar/orgs","repos_url":"https://api.github.com/users/wapolinar/repos","events_url":"https://api.github.com/users/wapolinar/events{/privacy}","received_events_url":"https://api.github.com/users/wapolinar/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-06T13:44:35Z","updated_at":"2016-01-06T19:09:13Z","closed_at":"2016-01-06T19:09:13Z","body":"If a parameter is not required, the TypeScript client still requires it as a parameter. This might be unavoidable, since in TS and JS, it is only possible to leave out the last parameters (which makes sense).\r\n\r\nNevertheless, the generated TypeScript client should check if these optional parameters are undef, null, etc. and leave them out, such that the client can be called when these parameters are set to **null**.\r\n\r\nThis shows the currently generated code:\r\n````javascript\r\n    removeElement(x_User: string, elementId: number, onSuccess?: (result: any) => void, onFail?: (exception: string, reason: string) => void) {\r\n        var url = this.baseUrl + \"/removeElement?\"; \r\n\r\n        url += \"elementId=\" + encodeURIComponent(\"\" + elementId) + \"&\"; \r\n\r\n        var content = \"\";\r\n\r\n        $.ajax({\r\n            url: url,\r\n            beforeSend: this.beforeSend,\r\n            type: \"delete\",\r\n            data: content,\r\n            dataType: \"text\",\r\n            headers: {\r\n                \"X-User\": x_User, \r\n                \"Content-Type\": \"application/json; charset=UTF-8\"\r\n            }\r\n        }).done((data, textStatus, xhr) => {\r\n            this.processRemoveElement(xhr, onSuccess, onFail);\r\n        }).fail((xhr) => {\r\n            this.processRemoveElement(xhr, onSuccess, onFail);\r\n        });\r\n    }\r\n````\r\nThis is the modified code:\r\n````javascript\r\n    removeElement(x_User: string, elementId: number, onSuccess?: (result: any) => void, onFail?: (exception: string, reason: string) => void) {\r\n        var url = this.baseUrl + \"/removeElement?\"; \r\n\r\n\t\tif(elementId)\r\n\t\t{\r\n\t\t\turl += \"elementId=\" + encodeURIComponent(\"\" + elementId) + \"&\";\r\n\t\t}\r\n\r\n        var content = \"\";\r\n\r\n        $.ajax({\r\n            url: url,\r\n            beforeSend: this.beforeSend,\r\n            type: \"delete\",\r\n            data: content,\r\n            dataType: \"text\",\r\n            headers: {\r\n                \"X-User\": x_User, \r\n                \"Content-Type\": \"application/json; charset=UTF-8\"\r\n            }\r\n        }).done((data, textStatus, xhr) => {\r\n            this.processRemoveElement(xhr, onSuccess, onFail);\r\n        }).fail((xhr) => {\r\n            this.processRemoveElement(xhr, onSuccess, onFail);\r\n        });\r\n    }\r\n````\r\n\r\nThis is an example JSON file:\r\n````\r\n{\r\n  \"swagger\" : \"2.0\",\r\n  \"info\" : {\r\n    \"version\" : \"1.0.2\",\r\n\t\"title\" : \"Test API\"\r\n  },\r\n  \"host\" : \"localhost:8080\",\r\n  \"basePath\" : \"/\",\r\n  \"tags\" : [ {\r\n    \"name\" : \"api\"\r\n  } ],\r\n  \"schemes\" : [ \"http\" ],\r\n  \"paths\" : {\r\n     \"/removeElement\" : {\r\n      \"delete\" : {\r\n        \"tags\" : [ \"api\" ],\r\n        \"summary\" : \"Removes an element\",\r\n        \"description\" : \"Removes an element\",\r\n        \"operationId\" : \"removeElement\",\r\n        \"consumes\" : [ \"application/json\" ],\r\n        \"produces\" : [ \"application/json\" ],\r\n        \"parameters\" : [ {\r\n          \"name\" : \"X-User\",\r\n          \"in\" : \"header\",\r\n          \"description\" : \"User identifier\",\r\n          \"required\" : true,\r\n          \"type\" : \"string\"\r\n        }, {\r\n          \"name\" : \"elementId\",\r\n          \"in\" : \"query\",\r\n          \"description\" : \"The id of an existing element that should be removed\",\r\n          \"required\" : false,\r\n          \"type\" : \"integer\",\r\n          \"format\" : \"int64\"\r\n        } ],\r\n        \"responses\" : {\r\n          \"default\" : {\r\n            \"description\" : \"successful operation\"\r\n          }\r\n        }\r\n      }\r\n    }\r\n  },\r\n    \"definitions\" : { }\r\n}\r\n````\r\n\r\nNote: In this example the non-required parameter is also the last parameter, but - in general - this is not the case.\r\n\r\nEdit: Added **\"definitions\": { }** to the example JSON file. This is necessary for NSwag."}}