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

Generated Csharp client doesn't allow to specify http headers #5785

Closed
weyert opened this issue Nov 17, 2024 · 3 comments
Closed

Generated Csharp client doesn't allow to specify http headers #5785

weyert opened this issue Nov 17, 2024 · 3 comments
Labels
Csharp Pull requests that update .net code Needs: Attention 👋 type:bug A broken experience

Comments

@weyert
Copy link

weyert commented Nov 17, 2024

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Mac executable

Client library/SDK language

Csharp

Describe the bug

I am trying to generate a C# client with Kiota were the used OpenAPI specification for some of the operations requires the passing of a http header only it doesn't appear to be possible to set.

Fo example, the operation's parameters is as follows:

"/backchannel/servicediscovery": {
      "get": {
        "description": "Get the list of discovered service\n",
        "operationId": "getServiceDiscoveryItems",
        "parameters": [
          {
            "description": "Specifies the Tenant ID for the request.\n",
            "in": "header",
            "name": "x-tenantId",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          }
        ],
  }
}

Expected behavior

I would expect the client generator to support the setting of the http headers as defined by the operation in the specification

How to reproduce

  1. Save the specification file to disk and name it example.yaml
  2. Run the command to generate the client: ``
  3. Notice no reference to x-tenantid in the code
  4. Review the generated output when running the generate-command
warn: Kiota.Builder.KiotaBuilder[0]
      OpenAPI warning: #/ - A servers entry (v3) or host + basePath + schemes properties (v2) was not present in the OpenAPI description. The root URL will need to be set manually with the request adapter.
Generation completed successfully

Hint: use the info command to get the list of dependencies you need to add to your project.
Example: kiota info -d "/Users/x/Development/Projects/KiotaExperiment/src/tools/client-generator/example.yaml" -l CSharp

Hint: use the --include-path and --exclude-path options with glob patterns to filter the paths generated.
Example: kiota generate --include-path "**/foo" -d "/Users/x/Development/Projects/KiotaExperiment/src/tools/client-generator/example.yaml"

Open API description file

openapi: 3.0.0
info:
  title: Service API
  version: '1.0.0'
  description: API requiring tenant identification

servers:
  - url: /

paths:
  /api/services:
    get:
      summary: Get services
      description: Returns service information with required tenant identification
      parameters:
        - in: header
          name: x-tenantid
          required: true
          schema:
            type: string
          description: Tenant identifier
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: string
                    example: "OK"
                required:
                  - items
        '400':
          description: Bad request - Missing or invalid tenant header
        '401':
          description: Unauthorized

Kiota Version

1.12.4

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

Unknown

Configuration

  • OS: macOS latest version
  • Architecture: ARM64

Debug output

Click to expand log ``` MacBook-Pro # kiota generate -l csharp -d specifications/example.yaml -o ./generated/ApiClient --exclude-backward-compatible --ll debug zsh: correct 'generate' to 'generated' [nyae]? n dbug: Kiota.Builder.KiotaBuilder[0] kiota version 1.20.0 info: Kiota.Builder.KiotaBuilder[0] loaded description from local source dbug: Kiota.Builder.KiotaBuilder[0] step 1 - reading the stream - took 00:00:00.0058051 warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/ - A servers entry (v3) or host + basePath + schemes properties (v2) was not present in the OpenAPI description. The root URL will need to be set manually with the request adapter. dbug: Kiota.Builder.KiotaBuilder[0] step 2 - parsing the document - took 00:00:00.0753558 dbug: Kiota.Builder.KiotaBuilder[0] step 3 - updating generation configuration from kiota extension - took 00:00:00.0001036 dbug: Kiota.Builder.KiotaBuilder[0] step 4 - filtering API paths with patterns - took 00:00:00.0037432 info: Kiota.Builder.KiotaBuilder[0] Client root URL set to dbug: Kiota.Builder.KiotaBuilder[0] step 5 - checking whether the output should be updated - took 00:00:00.0201737 dbug: Kiota.Builder.KiotaBuilder[0] step 6 - create uri space - took 00:00:00.0019637 info: Kiota.Builder.KiotaBuilder[0] No changes detected, skipping generation Generation skipped as no changes were detected

Hint: to force the generation to overwrite an existing client pass the --clean-output switch.
Example: kiota generate --clean-output
dbug: Kiota.Builder.KiotaBuilder[0]
Api manifest path: /Users/x/Development/Projects/KiotaExperiment/src/tools/client-generator/apimanifest.json

Hint: use the info command to get the list of dependencies you need to add to your project.
Example: kiota info -d "/Users/x/Development/Projects/KiotaExperiment/src/tools/client-generator/specifications/example.yaml" -l CSharp

Hint: use the --include-path and --exclude-path options with glob patterns to filter the paths generated.
Example: kiota generate --include-path "**/foo" -d "/Users/x/Development/Projects/KiotaExperiment/src/tools/client-generator/specifications/example.yaml"

</details>


### Other information

_No response_
@weyert weyert added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Nov 17, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Nov 17, 2024
@msgraph-bot msgraph-bot bot added the Csharp Pull requests that update .net code label Nov 17, 2024
@andrueastman
Copy link
Member

Thanks for raising this @weyert

Any chance you come across the documentation on how to specify headers in the link below?
https://learn.microsoft.com/en-us/openapi/kiota/query-parameters-request-headers#request-headers

Projecting a type for request headers would be redundant and inflate the amount of code being generated.

As stated in the link, the code generator does not emit code for headers due to potential inflation of the code generated.

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Nov 18, 2024
@andrueastman andrueastman moved this from Needs Triage 🔍 to Todo 📃 in Kiota Nov 18, 2024
@andrueastman andrueastman moved this from Todo 📃 to Waits for author 🔁 in Kiota Nov 18, 2024
@weyert
Copy link
Author

weyert commented Nov 18, 2024

Yeah, I ended up finding it earlier today. I just think it would be nice to have all the possible headers and/or query parameter values when they are enums generated.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Nov 18, 2024
@baywet
Copy link
Member

baywet commented Nov 19, 2024

Since all questions have been answered, I'll go ahead and close this issue. Don't hesitate to re-open if needed.

@baywet baywet closed this as not planned Won't fix, can't repro, duplicate, stale Nov 19, 2024
@github-project-automation github-project-automation bot moved this from Waits for author 🔁 to Done ✔️ in Kiota Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Csharp Pull requests that update .net code Needs: Attention 👋 type:bug A broken experience
Projects
Archived in project
Development

No branches or pull requests

3 participants