Skip to content

Stream response for HEAD endpoint #4245

Closed

Description

When a HEAD endpoint contains only responses without a body (which should always be the case), Kiota generates Task<Stream?> as the response type. Is that intentional? I would have expected the return type to be Task.

Repro steps:

{
  "openapi": "3.0.1",
  "info": {
    "title": "OpenApiTests",
    "version": "1.0"
  },
  "paths": {
    "/countries": {
      "head": {
        "tags": [
          "countries"
        ],
        "operationId": "headCountryCollection",
        "responses": {
          "200": {
            "headers": {
              "ETag": {
                "required": true,
                "schema": {
                  "type": "string"
                }
              },
              "Content-Length": {
                "required": true,
                "schema": {
                  "type": "integer",
                  "format": "int64"
                }
              }
            }
          },
          "304": {
            "headers": {
              "ETag": {
                "required": true,
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "The query string is invalid."
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
    }
  }
}

Used command line:

dotnet kiota generate --language CSharp --class-name HeadersClient --namespace-name OpenApiKiotaEndToEndTests.Headers.GeneratedCode --output ./Headers/GeneratedCode --backing-store --exclude-backward-compatible --clean-output --clear-cache --log-level Error --openapi ../OpenApiTests/Headers/GeneratedSwagger/swagger.g.json

Generated client usage:
image

Activity

  1. andrueastman commented on Feb 27, 2024

    @andrueastman
    Contributor

    Thanks for raising this Bart Koelman (@bkoelman)

    Stream is used as a default if the response code is not in noContentStatusCodes. What we would need to do is update the handling code here to have HEAD requests have a void return.

    if (operation.Responses.Any(static x => noContentStatusCodes.Contains(x.Key)))

  2. added
    type:bug
    generator
    help wanted
    on Feb 27, 2024
  3. bkoelman commented on May 18, 2024

    @bkoelman
    Author

    I've just updated to v1.14, which changes the return type to Task. Can you confirm this was fixed as intended?

  4. andrueastman commented on May 20, 2024

    @andrueastman
    Contributor

    Thanks for confirming. We'll close this one for now.

    I believe this was resolved via #4367

  5. moved this from Todo 📃 to Done ✔️ in Kiotaon May 20, 2024
  6. bkoelman commented on May 20, 2024

    @bkoelman
    Author

    I was wrong about this, the bug is still there. But the situation got worse than before.

    My OAS looks like this for the HEAD request:

            "responses": {
              "200": {
                "description": "The operation completed successfully.",
              },
              "304": {
                "description": "The fingerprint of the HTTP response matches one of the ETags from the incoming If-None-Match header.",
              },
              "400": {
                "description": "The query string is invalid."
              }

    Today kiota makes the return type void because one of the statuses is 304 (which is obviously wrong). If I change my OAS to:

            "responses": {
              "200": {
                "description": "The operation completed successfully."
              }
            }

    it generates Stream as return type again. So please reopen.

  7. andrueastman commented on May 20, 2024

    @andrueastman
    Contributor

    Re-opening. The fix here would involve checking the request method(HEAD) rather than the responses.

  8. moved this from Done ✔️ to In Progress 🚧 in Kiotaon May 20, 2024
  9. moved this from In Progress 🚧 to Todo 📃 in Kiotaon May 20, 2024
  10. moved this from New📃 to Done ✔️ in Kiotaon Sep 8, 2026
  11. added a commit that references this issue on Sep 8, 2026
    84a17f0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    generatorhelp wantedtype:bug

    Type

    No type

    Projects

    • Status
      Done ✔️

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions