Skip to content

Add SetContentFromEnumCollection method to RequestInformation class#579

Merged
baywet merged 6 commits into
mainfrom
copilot/fix-enum-array-compile-error
Oct 24, 2025
Merged

Add SetContentFromEnumCollection method to RequestInformation class#579
baywet merged 6 commits into
mainfrom
copilot/fix-enum-array-compile-error

Conversation

Copilot AI commented Oct 23, 2025

Copy link
Copy Markdown
Contributor
  • Explore repository structure and understand the issue
  • Review existing code in RequestInformation.cs
  • Build and test the project to verify current state
  • Add SetContentFromEnumCollection method to RequestInformation class
  • Add tests for the new method
  • Build and test to verify changes (all 171 tests pass)
  • Verify method exists in compiled assembly
  • Refactor to use foreach loop instead of enumerator pattern per code review feedback

Summary

Added the missing SetContentFromEnumCollection method to the RequestInformation class and refactored to use a foreach loop for finding the first non-null item. This resolves the compile error that occurred when Kiota generates C# clients for OpenAPI specs with enum array request bodies.

All tests pass successfully.

Original prompt

This section details on the original issue you should resolve

<issue_title>Array of enums in a request generates code (C#) that produces a compile error</issue_title>
<issue_description>### What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

Csharp

Describe the bug

With an OpenAPI description that has a route with request body of enum array. Kiota will generate a C# client that has a compile error:

Error CS1061 : 'RequestInformation' does not contain a definition for 'SetContentFromEnumCollection' and no accessible extension method 'SetContentFromEnumCollection' accepting a first argument of type 'RequestInformation' could be found (are you missing a using directive or an assembly reference?)

RequestInformation type has a method SetContentFromEnum but not the needed SetContentFromEnumCollection

Expected behavior

Kiota should generate code that compiles.

How to reproduce

Problem can be reproduced by generating a C# client with the provided Open API description. Command used to generate the client was:

dotnet kiota generate -l CSharp -c Client -n ConsoleApp1 --openapi example.yaml -o ./Client

Open API description file

openapi: 3.0.4
info:
  title: WebApplication1 | v1
  version: 1.0.0
paths:
  /:
    put:
      tags:
        - WebApplication1
      requestBody:
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/Status'
        required: true
      responses:
        '200':
          description: OK
components:
  schemas:
    Status:
      enum:
        - Active
        - Inactive
        - Pending

Kiota Version

1.28.0+57130b1b1db3bc5c060498682f41e20c8ae089f2

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

1.27.0

Known Workarounds

None

Configuration

  • Ubuntu 24.04.3 LTS
  • x64

Debug output

Click to expand log

dbug: Kiota.Builder.KiotaBuilder[0]
kiota version 1.28.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.0083332
dbug: Kiota.Builder.KiotaBuilder[0]
step 2 - parsing the document - took 00:00:00.0841337
dbug: Kiota.Builder.KiotaBuilder[0]
step 3 - updating generation configuration from kiota extension - took 00:00:00.0001318
dbug: Kiota.Builder.KiotaBuilder[0]
step 4 - filtering API paths with patterns - took 00:00:00.0065592
warn: Kiota.Builder.KiotaBuilder[0]
No server url found in the OpenAPI document. The base url will need to be set when using the client.
dbug: Kiota.Builder.KiotaBuilder[0]
step 5 - checking whether the output should be updated - took 00:00:00.0346000
dbug: Kiota.Builder.KiotaBuilder[0]
step 6 - create uri space - took 00:00:00.0027734
dbug: Kiota.Builder.KiotaBuilder[0]
InitializeInheritanceIndex 00:00:00.0108185
dbug: Kiota.Builder.KiotaBuilder[0]
CreateRequestBuilderClass 00:00:00
dbug: Kiota.Builder.KiotaBuilder[0]
MapTypeDefinitions 00:00:00.0033737
dbug: Kiota.Builder.KiotaBuilder[0]
TrimInheritedModels 00:00:00
dbug: Kiota.Builder.KiotaBuilder[0]
CleanUpInternalState 00:00:00
dbug: Kiota.Builder.KiotaBuilder[0]
step 7 - create source model - took 00:00:00.0653511
dbug: Kiota.Builder.KiotaBuilder[0]
20ms: Language refinement applied
dbug: Kiota.Builder.KiotaBuilder[0]
step 8 - refine by language - took 00:00:00.0206971
dbug: Kiota.Builder.KiotaBuilder[0]
step 9 - writing files - took 00:00:00.0207780
info: Kiota.Builder.KiotaBuilder[0]
loaded description from local source
dbug: Kiota.Builder.KiotaBuilder[0]
step 10 - writing lock file - took 00:00:00.0069393
Generation completed successfully

Other information

The problem might have been introduced here: microsoft/kiota@51d995b</issue_description>

<agent_instructions>Please add the SetContentFromEnumCollection method to the RequestInformation class</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #578


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: gavinbarron <7122716+gavinbarron@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix compile error with enum array in generated C# client Add SetContentFromEnumCollection method to RequestInformation class Oct 23, 2025
Copilot AI requested a review from gavinbarron October 23, 2025 22:23
@gavinbarron gavinbarron marked this pull request as ready for review October 23, 2025 22:25
@gavinbarron gavinbarron requested a review from a team as a code owner October 23, 2025 22:25
@gavinbarron gavinbarron enabled auto-merge (squash) October 23, 2025 22:27
Comment thread src/abstractions/RequestInformation.cs Outdated
@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Oct 24, 2025
…rator

Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Copilot AI requested a review from baywet October 24, 2025 12:03
Comment thread src/abstractions/RequestInformation.cs Outdated
baywet
baywet previously approved these changes Oct 24, 2025
@baywet

baywet commented Oct 24, 2025

Copy link
Copy Markdown
Member

@adrian05-ms you'll need to give it an approval since Gavin queued the PR and I submitted the last commit.

@baywet baywet disabled auto-merge October 24, 2025 13:56
@baywet baywet enabled auto-merge October 24, 2025 13:56
@baywet baywet disabled auto-merge October 24, 2025 13:56
@baywet baywet enabled auto-merge (squash) October 24, 2025 13:57
@sonarqubecloud

Copy link
Copy Markdown

@baywet baywet merged commit d970e8e into main Oct 24, 2025
10 of 12 checks passed
@baywet baywet deleted the copilot/fix-enum-array-compile-error branch October 24, 2025 22:27
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Array of enums in a request generates code (C#) that produces a compile error

4 participants