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

C# Methods as alternative to Indexers and QueryParameters #4393

Closed
ghost opened this issue Mar 24, 2024 · 8 comments
Closed

C# Methods as alternative to Indexers and QueryParameters #4393

ghost opened this issue Mar 24, 2024 · 8 comments
Labels
Csharp Pull requests that update .net code Needs: Attention 👋
Milestone

Comments

@ghost
Copy link

ghost commented Mar 24, 2024

Thanks for this project, it worked out of the box with Swashbuckle. It would be awesome if we could generate methods for C# as alternative to indexers just like the Java example in Indexers. The method syntax seems more natural to use.

Same goes for QueryParameters having something like x.QueryParameters.Select("id", title") would be cool.

@baywet
Copy link
Member

baywet commented Mar 25, 2024

Hi @RandomBuffer
Thanks for using kiota and for reaching out.

On indexers: why do you think methods would be better than indexers? Isn't it closer to language semantics after all?

On query parameters: using a method to set the select value is probably to a fluent API design than using the setter with =. This would require generating a getter method as well, and a backing field. It'd probably result in "heavier" binaries. Besides the style consistency, do you see any other benefit to such change?

To be fully transparent, unless we get overwhelming demand for those two, we're probably unlikely to make any of those changes any time soon as they'd represent source breaking changes.

@baywet baywet added question Csharp Pull requests that update .net code labels Mar 25, 2024
@baywet baywet added this to the Backlog milestone Mar 25, 2024
@ghost
Copy link
Author

ghost commented Mar 25, 2024

Hi @baywet for both its mostly readability and help from Intellisense without resorting to looking at the generated code or Swagger to figure out the path and parameter info. For example Intellisense will help me out with var requestBuilder = todoClient.TaskLists("taskListId").ToDos("todoId").AssignedTo;.

Also some interesting feedback in https://devblogs.microsoft.com/microsoft365dev/tailored-sdk-experiences-via-kiota-now-generally-available/#comment-191

Btw I mentioned Kiota here dotnet/aspnetcore#54598 (comment).

@ghost ghost changed the title C# Methods as Alternative to Indexers and QueryParameters C# Methods as alternative to Indexers and QueryParameters Mar 26, 2024
@baywet
Copy link
Member

baywet commented Mar 28, 2024

Thanks for the additional information.
The Java equivalent of that is actually (casing aside)

todoClient.TaskLists.ById("taskListId").ToDos.ById("todoId").AssignedTo

So each fluent API segment maps to a path segment on the API.

The comment you've shared outlines a lack of design documentation on our side. The fluent API pattern still shows some relation to HTTP, and the API segmentation, but that's a feature. This is because it works consistently across any API, large or not, deep (segmentation) or not. The OperationId based approach as too many short comings (starting with the fact they are not required in the OpenAPI spec).

Thanks for bringing kiota up!

@ghost
Copy link
Author

ghost commented Mar 28, 2024

Looks like the docs are not upto date as I copied my example from the Java example there https://learn.microsoft.com/en-us/openapi/kiota/request-builders#indexers

@baywet
Copy link
Member

baywet commented Mar 29, 2024

Thanks for letting us know. Can you please open an issue about this here https://github.com/MicrosoftDocs/openapi-docs

@ghost
Copy link
Author

ghost commented Mar 29, 2024

Have opened issue. Noting happy with the C# Fluent syntax, its just having an alternative to indexers like ById() example above would be sweet.

@baywet
Copy link
Member

baywet commented Mar 29, 2024

Thanks!

Again, noted, but we're unlikely to change this at this point unless we get overwhelming demand for it.

Anything else or is it ok to close this issue?

@ghost
Copy link
Author

ghost commented Mar 29, 2024

Ok to close, thanks

@baywet baywet closed this as not planned Won't fix, can't repro, duplicate, stale Mar 30, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Kiota Mar 30, 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 👋
Projects
Archived in project
Development

No branches or pull requests

1 participant