-
Notifications
You must be signed in to change notification settings - Fork 232
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
Support oneOf path paramaters #6185
Comments
Hi @caleblloyd Purely from a description perspective, what's the value of describing the parameter as a one of string / number? It is functionally equivalent to just a string type since path segments are not "typed" in any way. |
Great point! I think it would mainly be the {
"components": {
"parameters": {
"start": {
"name": "start",
"in": "path",
"description": "The start date/time, can be an exact date/time or duration from the current time, such as -4H",
"required": true,
"schema": {
"oneOf": [
{
"type": "string",
"format": "date-time"
},
{
"type": "string",
"format": "duration"
}
]
}
}
}
}
} Of course this could be described as a If it is too difficult to implement overloaded setters, should Kiota fallback to generating |
Thank you for the additional information. The format argument makes sense, there's no point sending a request to the service if the format doesn't match and the request is going to end up with a 400 response. The challenge is mostly for other languages than dotnet. I believe that dotnet will be happy with multiple indexer overloads as long as the argument type is different. For other languages, these get translated as methods. And some of them won't accept defining methods with the same name, number of parameters, return type, but different parameter type. (Java, Go, TypeScript...) We could give different names to those methods based on the argument type like "byWorkflowIdInt" and "byWorkflowIdString", but this would represent a breaking change and lead to a poor developer experience. Alternatively, when a one of is presented, we could order the types by a deterministic ordering scheme, probably string first, and always present "the largest type available" to avoid blocking scenarios like yours. What do you think? |
Ah yes, that is certainly a restriction.
Another option could be introducing wrapper types, which are essentially a container for a string with a setter for each of the valid types. This could be done in all languages, or only languages that don't support overloads or Discriminated Unions. This is still a more complex Developer Experience but at least keeps the method names the same, and still a breaking change for
If a single type must be chosen, I am not sure how many types would potentially overlap. It'd probably wind up being a I guess |
Thank you for your patience. A - I like the wrapper type approach, since the fluent API surface would essentially need to call ToString (or equivalent) when building the set of parameters, and all the logic can be offloaded there. It can also evolve over time nicely (description changes and additional types are added) and doesn't require complex overloads. B - The alternative being to throw our hands in the air and say "anything more complex than a single scalar type is a string". I want to be transparent about the fact that:
With that in mind, I feel like the B option is probably a more reasonable ask here. Thoughts? Is this something you'd like to submit a pull request for provided some guidance? |
Sure, I could submit a PR given some guidance. Would it need to go to the main Kiota library and support all languages? Or only this repo for .NET? |
I believe this will be a generation only kind of change, and it'll only need to be implemented with the core generation (which will apply to all languages) if we go with option B. Here is where the indexer parameter gets created. kiota/src/Kiota.Builder/KiotaBuilder.cs Line 1058 in 06340d5
And here is an example of a unit test.
Let us know if you have any additional comments or questions. |
Given the schema
A query paramater indexer is only made for the
integer
use case:Could it also add an indexer for the
string
use case?Generated using
dotnet tool install --global Microsoft.OpenApi.Kiota --version 1.22.3
The text was updated successfully, but these errors were encountered: