Feature Request: option to generate method per content type #6455
Replies: 1 comment
|
Hi MiyaGrace (@JeroMiya) This is something we discussed a while ago in #2317 Effectively, there'd be a need to vary per request media type, response media type AND status code to fully implement that. It'd severely impact the user's experience, maintenance costs, and size of any given client.
For all those reasons, we've decided to leave it, about 2 years ago, to test if any customer demand would manifest, and you're the first to request it in that time. We're unlikely to implement that feature request unless we get overwhelming additional demand for it. Let us know if you have any additional comments or questions. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I've split this discussion off from a bug report here:
#6451
The bug report is still valid, but I'd like to request a new feature related to the bug. I have an external API with an OpenAPI spec I'm attempting to create a Kiota client for in C#. While I would not design my own APIs like this, this API has a POST endpoint that supports multiple content types, and the behavior of the endpoint is different depending on the content type submitted. Here is an example OpenApi spec that demonstrates the situation:
Note the
templateIdfield in thecreate-user-info-requestmodel. Imagine that this endpoint supports templates for the user profile picture when a photo isn't available - maybe with a logo or icons based on the role of the user. Anyway, thePOST /usersendpoint in this example behaves differently depending on if you usemultipart/form-dataas the content type or theapplication/jsontype. In both cases, you submit acreate-user-info-requestobject as part of the request. However, if you submit with content typeapplication/json, and you provide a validtemplateIdin the body of the request, the second content type creates a profile picture based on the template. However, if you use themultipart/form-datacontent type, and include a picture in thepicturepart of the request, the endpoint will use the submitted picture as the profile picture.Unfortunately, Kiota can't currently support this kind of API. Although currently bugged (see: #6451), even if Kiota worked as designed, we would not be able to use the
multipart/form-datacontent type, which in our case is the one we use for our own workflow. As I said, this wouldn't have been my design choice, but it's an external API we have no control over. We need to be able to use both content types to support all the workflows of this endpoint.Therefor, I propose a new generator option, for now I'll name it
--method-per-content-type, which should be off by default to avoid breaking changes. When enabled, this option will change the way the generator handles multiple content types in a given request. Instead of choosing the most "structured" content type (in the above example, that would beapplication/json), the generator would instead generate a method for each content type. So as to support languages that don't have support for type based method overloads, and to avoid collisions in method signature for content types that would generate the same signature, the methods should include the content type in the name of the method, translated to an identifier using the conventions of the target language.For example, in the above sample OpenApi spec, when the
--method-per-content-typeis enabled, instead of a singlePostAsyncmethod being generated (again, note this is bugged currently - see linked issue above), there would be two methods:PostApplicationJsonAsyncandPostMultipartFormDataAsync. In this case, the signatures would be different withPostMultipartFormDataAsynctaking aMultipartBodyas an argument, andPostApplicationJsonAsynctaking aCreateUserInfoRequest(in the C# generated output, at least).So that, when enabled, the proposed new
--method-per-content-typeoption would allow us to use Kiota to generate a client that enables us to explicitly choose which content type to use when an endpoint in the source spec supports multiple content types and which differs in behavior depending on which content type is submitted.All reactions