NSwag icon indicating copy to clipboard operation
NSwag copied to clipboard

Invalid Generated C#: Returns void on inside async method

Open groogiam opened this issue 2 years ago • 4 comments

The following nswag file generates invalid c# code. Line 10229 attempts to return void when the method is declared async Task.

TestProject.nswag.txt

Note: The swagger spec in this file came from https://api.testproject.io/docs/v2/swagger.json

groogiam avatar Jun 24 '22 23:06 groogiam

I have the same issue: image

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.

fairking avatar Aug 08 '22 16:08 fairking

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": { }
            }

fairking avatar Aug 08 '22 16:08 fairking

I have this issue as well with an Open API spec. I believe nSwag should handle these cases properly.

LeonarddeR avatar Sep 27 '22 06:09 LeonarddeR