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

Map exceptions in .Net #3817

Closed
galvesribeiro opened this issue Nov 27, 2023 · 2 comments
Closed

Map exceptions in .Net #3817

galvesribeiro opened this issue Nov 27, 2023 · 2 comments
Assignees
Labels
Csharp Pull requests that update .net code
Milestone

Comments

@galvesribeiro
Copy link

galvesribeiro commented Nov 27, 2023

Hello guys!

The code generated by Kiota for a given API generated several classes that inherit from the ApiException.

image

I've tried to simulate a situation on which one of those, as a result of a response of the server, would be thrown. However, it doesn't throw the specific one but instead, the generic ApiException:

image

Note that the ResponseStatusCode is not 400 as the generated class suggest but instead 422.

image

I've looked at the error type map docs, and it appear to me that the exception is not being properly mapped correctly because of this.

The Swagger file doesn't explicitly say about the 422 response code, but their docs say it can be returned.

I know I could ask the API provider to fix their API spec. However, there are some cases where this is just not that feasible as they, in my case, are huge banks, it would take a while to get a reply.

So my question is: Is there a way for us, Kiota consumers, to somehow customize the API being generated using the CLI or something else?

Again, I know this is the API provider fault, but I'm pretty sure a lot of people will find out crappy API specs out there which they would like to "tweak" the generator in order to get the desired result.

Side note: When generating this API client, we've got this:

kiota generate -l CSharp -n "TP.Payments.Acquirers.Rede" \
-c RedeApiClient -d https://developer.userede.com.br/dev-portal-swaggers/erede/swagger.json -o $PWD/ApiClient 
warn: Kiota.Builder.KiotaBuilder[0]
      OpenAPI warning: #/ - Multiple servers entries were found in the OpenAPI description. Only the first one will be used. The root URL can be set manually with the request adapter.
warn: Kiota.Builder.KiotaBuilder[0]
      OpenAPI warning: #/ - The schema /v1/transactions is a polymorphic type but does not define a discriminator. This will result in a serialization errors.
Generation completed successfully

I'm not 100% sure where the problem lies tbh...

Thanks! Keep the great work!

@baywet
Copy link
Member

baywet commented Nov 28, 2023

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

However, there are some cases where this is just not that feasible as they, in my case, are huge banks, it would take a while to get a reply.

Being a bank and/or slow is not an excuse for the description being inaccurate. Contact them anyway, when they eventually fix it, it'll benefit every other developer out there, improving their integration story and leading to more business for them. (lead with that aspect, banks generally care about making money)

Is there a way for us, Kiota consumers, to somehow customize the API being generated

Besides the arguments offered by the CLI, no. There are two main reasons for that:

  • We want to keep kiota as simple as possible, too many options lead to confusion and maintenance hell.
  • We want people to report description issues so they get addressed, leading to a better state of the ecosystem.

In the interim, make a local copy of their description, and make a couple of modifications to address the short comings. This can be used as a test bed for any feedback you provide them as well.

Let us know if you have further questions.

@galvesribeiro
Copy link
Author

Yeah, I agree that is not an excuse. Just saying that they will take months to report back with an update and meanwhile we wouldn't be able to use Kiota and have to write the client ourselves.

I tried modifying their swagger.json and add the 422 response with the same exception type and it essentially worked.

Will report to them and for now keep this hack.

Thanks!

@github-project-automation github-project-automation bot moved this from Todo to Done in Kiota Nov 28, 2023
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
Projects
Archived in project
Development

No branches or pull requests

2 participants