NSwag
NSwag copied to clipboard
Invalid Generated C#: Returns void on inside async method
The following nswag file generates invalid c# code. Line 10229 attempts to return void when the method is declared async Task.
Note: The swagger spec in this file came from https://api.testproject.io/docs/v2/swagger.json
I have the same issue:
The scheme looks like this:
"/ApiKey/Update": {
"post": {
"tags": [
"ApiKeyService"
],
"operationId": "Update",
"parameters": [
{
"name": "pKey",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiKeyForm"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": { }
}
}
},
"security": [
{ }
]
}
},
Please note the schema.json above was generated manually, not by swagger.
After I changed to the following the client generated without any errors and compiled:
"/ApiKey/Update": {
"post": {
"tags": [
"ApiKeyService"
],
"operationId": "Update",
"parameters": [
{
"name": "pKey",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiKeyForm"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
}
},
"security": [
{ }
]
}
},
See responses
:200
part.
I have removed the following lines:
"content": {
"application/json": { }
}
I have this issue as well with an Open API spec. I believe nSwag should handle these cases properly.