RicoSuter/NSwag
View on GitHubInvalid C# code produced in latest version (11.15.4.0) if path definition has an underscore
Open
#1,222 opened on Mar 14, 2018
help wantedproject: NSwag.CodeGeneration.CSharp (Clients)type: bug
Repository metrics
- Stars
- (6,291 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
Hi, I have created a test specification from Restlet as below to illustrate the issue.
{
"swagger": "2.0",
"info": {
"description": "No description",
"version": "1.0.0",
"title": "Test"
},
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/test/{test_id}": {
"get": {
"summary": "Gets the specific test object",
"parameters": [],
"responses": {
"200": {
"description": "Status 200",
"schema": {
"$ref": "#/definitions/_test_object"
}
}
}
},
"parameters": [
{
"name": "test_id",
"in": "path",
"required": true,
"type": "string"
}
]
}
},
"definitions": {
"_test_object": {
"type": "object",
"required": [
"price",
"test_description",
"test_id"
],
"properties": {
"test_id": {
"type": "string"
},
"test_description": {
"type": "string"
},
"price": {
"type": "number"
}
}
}
}
}
the snippet of the output below shows the issue. It is adding a "}" in the middle of the function names (e.g. TestId}Async) .It looks like it is due to the underscore in the path definition e.g. /test/{test_id}. If I take the underscore out (/test/{testid}), then the code generates OK.
/// <summary>Gets the specific test object</summary>
/// <returns>Status 200</returns>
/// <exception cref="SwaggerException">A server side error occurred.</exception>
public System.Threading.Tasks.Task<_test_object>TestId}Async(string test_id)
{
return TestId}Async(test_id, System.Threading.CancellationToken.None);
}
/// <summary>Gets the specific test object</summary>
/// <returns>Status 200</returns>
/// <exception cref="SwaggerException">A server side error occurred.</exception>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
public async System.Threading.Tasks.Task<_test_object> TestId}Async(string test_id, System.Threading.CancellationToken cancellationToken)
{
if (test_id == null)
throw new System.ArgumentNullException("test_id");