Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream response for HEAD endpoint #4245

Open
bkoelman opened this issue Feb 27, 2024 · 5 comments
Open

Stream response for HEAD endpoint #4245

bkoelman opened this issue Feb 27, 2024 · 5 comments
Labels
generator Issues or improvements relater to generation capabilities. help wanted Issue caused by core project dependency modules or library type:bug A broken experience
Milestone

Comments

@bkoelman
Copy link

bkoelman commented Feb 27, 2024

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

@andrueastman
Copy link
Member

Thanks for raising this @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)))

@andrueastman andrueastman added type:bug A broken experience generator Issues or improvements relater to generation capabilities. help wanted Issue caused by core project dependency modules or library labels Feb 27, 2024
@andrueastman andrueastman added this to the Backlog milestone Feb 27, 2024
@bkoelman
Copy link
Author

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

@andrueastman
Copy link
Member

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

I believe this was resolved via #4367

@github-project-automation github-project-automation bot moved this from Todo 📃 to Done ✔️ in Kiota May 20, 2024
@bkoelman
Copy link
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.

@andrueastman
Copy link
Member

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

@andrueastman andrueastman reopened this May 20, 2024
@github-project-automation github-project-automation bot moved this from Done ✔️ to In Progress 🚧 in Kiota May 20, 2024
@andrueastman andrueastman moved this from In Progress 🚧 to Todo 📃 in Kiota May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator Issues or improvements relater to generation capabilities. help wanted Issue caused by core project dependency modules or library type:bug A broken experience
Projects
Status: Todo 📃
Development

No branches or pull requests

2 participants