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

[java] [question] Query parameters and enums #2306

Closed
andreaTP opened this issue Feb 14, 2023 · 6 comments
Closed

[java] [question] Query parameters and enums #2306

andreaTP opened this issue Feb 14, 2023 · 6 comments
Assignees
Labels
enhancement New feature or request generator Issues or improvements relater to generation capabilities.
Milestone

Comments

@andreaTP
Copy link
Contributor

I haven't narrowed down this issue completely, but it seems that enum fields are exposed as strings in queryParameters.
I don't see a huge problem with this decision but I would like to understand if it's deliberate, accidental, or something we want to improve in the longer run.

E.g. here

@baywet
Copy link
Member

baywet commented Feb 14, 2023

Thanks for bringing this up. In theory we already have all the bricks we need for this one.
We already know how to project enum types to the code dom, we also have a serialization method for query parameters that are non-trivial (name was changed, etc...)
I think this should be feasible as long as the property is projected to be nullable and as long as the code that handles serialization is updated to call the enum serialization method.
This is something that should be implemented consistently across languages however, and I believe we haven't prioritized that at this point because we don't have enums on the Microsoft Graph API surface being used as query parameters.

@andreaTP
Copy link
Contributor Author

@baywet thanks for reverting back!

Would you like to dump a few links to significant lines where you expect the code to be touched?
This is going to be helpful to anyone that finds time to jump on it 🙂

@baywet
Copy link
Member

baywet commented Feb 14, 2023

Sure,
This is where properties are added to the DOM for query parameters

Type = GetPrimitiveType(parameter.Schema),

right now it only supports primitive types but calling a simplified version of create model declaration would do the trick (to avoid generating classes)

private CodeTypeBase CreateModelDeclarations(OpenApiUrlTreeNode currentNode, OpenApiSchema schema, OpenApiOperation? operation, CodeElement parentElement, string suffixForInlineSchema, OpenApiResponse? response = default, string typeNameForInlineSchema = "", bool isRequestBody = false)

Then in the request information the serialization expects annotations for anything that's not trivial, so we'd need to update the annotation to point to the serialization method for the enum
https://github.com/microsoft/kiota-java/blob/812a5a2636d52afc259a792fdf6bdfce9a451118/components/abstractions/src/main/java/com/microsoft/kiota/RequestInformation.java#L102

and update the property generation.

writer.WriteLine($"@QueryParameter(name = \"{codeElement.SerializationName}\")");

@andreaTP
Copy link
Contributor Author

Nice writeup @baywet , appreciated!

@baywet baywet added this to the Kiota post-GA milestone Feb 24, 2023
@baywet baywet self-assigned this Apr 5, 2023
@baywet baywet added enhancement New feature or request generator Issues or improvements relater to generation capabilities. and removed question Needs: Attention 👋 labels Apr 5, 2023
@baywet baywet added this to Kiota Apr 5, 2023
@github-project-automation github-project-automation bot moved this to Todo in Kiota Apr 5, 2023
@baywet baywet modified the milestones: Backlog, Kiota v1.3, Kiota v1.4 Apr 5, 2023
@baywet baywet modified the milestones: Kiota v1.4, Kiota v2.0 Jun 22, 2023
@baywet
Copy link
Member

baywet commented Jun 22, 2023

Unfortunately this would potentially mean a breaking change for existing users off go and c# and we missed it when we went GA. This will have to wait for v2 at this point.

@baywet
Copy link
Member

baywet commented Jul 19, 2023

This is actually a duplicate of #2490 closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request generator Issues or improvements relater to generation capabilities.
Projects
Archived in project
Development

No branches or pull requests

2 participants