Skip to content

Conversation

@MatthiasNistl
Copy link

See #4340.
This PR intends to add support for Enums as path parameters. The created Enums can be used as indexers in the request builders.

As far as I understand existing Kiota clients can still use primitive types (strings) as indexers, but they might be marked as deprecated (This indexer is deprecated and will be removed in the next major version. Use the one with the typed parameter instead.).

@MatthiasNistl MatthiasNistl requested a review from a team as a code owner November 14, 2025 23:06
@MatthiasNistl
Copy link
Author

@microsoft-github-policy-service agree

Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

Have you tested the generated code can handle serialization of the values properly? Especially when the symbol is different from the value?

Comment on lines 1133 to 1134
enumCandidateSchema = enumCandidateSchema?.AllOf?
.FlattenSchemaIfRequired(static x => x.AllOf)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we consider any or one of at well? this seems like it's special casing for one of the scenarios you ran into

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are probably right. We generate our API spec from code, and all Enums references have been generated with "AllOf", but it makes sense to check AnyOf and OneOf, too.
I have now added an extension that uses the already existing Func to flatten the subsequent schemas. Not sure if this is the correct way to achieve this?

@MatthiasNistl
Copy link
Author

Thanks for the contribution!

Have you tested the generated code can handle serialization of the values properly? Especially when the symbol is different from the value?

@baywet I have only tested generated code for C# so far. The Enums are serialized according to their EnumMember Value, which is identical to the API specification (just like when an enum is generated for a request model). The Enum symbols might be different since they always start with an uppercase letter, but this seems to be irrelevant during serialization. Both as path parameter and in the request body the enums are serialized according to their Enum value, so at least in my use cases this seems to work.

Unfortunately I don't know how other languages handle enums or what else needs to be considered for other target languages 😟
Maybe someone else can check this?

@baywet
Copy link
Member

baywet commented Nov 18, 2025

@MatthiasNistl Thank you for the additional information.

I think the first step here would be to demonstrate that we have sufficient unit test coverage for enums in the kiota libs.

For example:

The repositories structure is similar, so you should get around even without the knowledge of the language. And you can ignore ruby and swift since they were never completed.

@MatthiasNistl
Copy link
Author

@baywet Unfortunately I'm not quite sure what you mean. I see that the same tests for Enums exist in their own language-specific variant in most of the repositories, for example:

It seems to me like enums are pretty well covered accross the libs.
However, I fail to understand how exactly the tests relate to the changes in this PR or how they might be affected. Without really knowing kiota I understand that there is an additional abstraction layer between the core and the language-specific libs. How can I ensure with confidence that the changes here do not introduce any issues down the road?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants