code4it-dev / blog-comments

https://www.code4it.dev/
1 stars 0 forks source link

blog/openapi-code-generation-vs2019 #45

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

How to generate code from OpenAPI definition with Visual Studio 2019 - Code4IT

Wouldn't it be nice if Visual Studio could autogenerate clients for external API? It is actually possible, if they expose an OpenAPI file. Let's see how!

https://www.code4it.dev/blog/openapi-code-generation-vs2019

KutanaDev commented 1 year ago

Hi Davide,

Thank you for this article! We've been using swaggerhub to generate C# code from a third-party yaml file, but the swaggerhub code targets Newtonsoft.Json 105 - not the more recent version. So it was great to discover that VS itself can read yaml and generate C# but using the more up-to-date Newtonsoft.Json. We don't have to rely on swaggerhub for our C# code any more.

b5white commented 11 months ago

We were able to generate the code, but the nine method names are all {controllername}1Async through {controllername}9Async. Our JSON looks like yours as far as I can tell. Did you do anything special, like decorate the methods, to get it to generate sensible method names?