Skip to content

Generated client throws exceptions when the body is an enumerable #537

@SiVGiV

Description

@SiVGiV

When attempting to send a request that has an enum as body through a generated client, an exception is thrown from SetContentFromScalar in RequestInfo (Microsoft.Kiota.Abstractions - 1.17.2).

The function contains a big switch function that is missing an option that allows an enum through.

Important to note that the enum was also generated by Kiota.

Function used to generate:

kiota generate --exclude-backward-compatible --class-name KiotaClient --output "./KiotaClient" --language CSharp --openapi "./KiotaClient.OpenAPI.yaml" --namespace-name "KiotaClient" --disable-ssl-validation --clean-output --clear-cache

OpenAPI schema example:

openapi: 3.0.3
info:
  version: v1.0
  title: KiotaClient Bug Example
  description: 
    Example
servers:
  - url: https://localhost:5000/
paths:
  "/api/":
    put:
      requestBody:
        required: true
        content:
          application/json; charset=utf-8:
            schema:
              $ref: "#/components/schemas/state"
            examples:
              started:
                summary: OptionA
                value: "OptionA"
              stopped:
                summary: OptionB
                value: "OptionB"
      responses:
        "204":
          description: State was changed

components:
  schemas:
    state:
      description: Device state
      type: string
      enum:
        - OptionA
        - OptionB

Edit:

Upon further investigation, this problem may be linked to the client generation and not Microsoft.Kiota.Abstractions, as a similar problem presents when the body of the request is of an UntypedNode type instead of an Enum.

There seems to be a problem with fitting the client request function body with the function body's type - no matter what type is sent, they're all sent to the SetContentAsScalar function, which lacks support for those types (Enum and UntypedNode are the ones I came across).

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedStandard GitHub labelpriority:p3Nice to have. Customer impact is very minimaltype: bugA broken experience

    Type

    Projects

    Status

    Done ✔️

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions