-
Notifications
You must be signed in to change notification settings - Fork 289
Add support for enum path parameters #7128
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
base: main
Are you sure you want to change the base?
Add support for enum path parameters #7128
Conversation
|
@microsoft-github-policy-service agree |
baywet
left a comment
There was a problem hiding this 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?
Co-authored-by: Vincent Biret <vincentbiret@hotmail.com>
src/Kiota.Builder/KiotaBuilder.cs
Outdated
| enumCandidateSchema = enumCandidateSchema?.AllOf? | ||
| .FlattenSchemaIfRequired(static x => x.AllOf) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
Co-authored-by: Vincent Biret <vincentbiret@hotmail.com>
@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 😟 |
|
@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. |
|
@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. |
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.).