

Task> MarvelMoviesAllAsync() to get all the movies.But it's really important to notice the signatures: you'll find Of course, I'm not going to focus on all the methods generated by Visual Studio. This is a C# file created under the obj folder, called swaggerClient.cs Now you can see the code that has automatically been generated by Visual Studio. To see the code, you must go back to the Service Reference screen, locate the OpenAPI reference, and click on View generated code. What's been generated?Īfter the wizard, Visual Studio adds an OpenAPIs folder in your solution files, but without showing any code. no, still no code for you! Well, apparently. Now move on with the wizard: you'll see Visual Studio installing some NuGet packages for you: You can also define a namespace for the generated code.

Now, click on Add under the OpenAPI section.įinally, you can add a new API reference by specifying the location of the OpenAPI, both on your local machine or online. Here you can add references to OpenAPIs, gRPC, and other external services. Once created, in the Solution Explorer, right-click on the project, then click on Add > Service Reference

For the following tests I used a simple Console Application I called MarvelMoviesClient. You can find the link in the UI, right below the title.ĭownload it or copy the URL, we're going to use it in a while. This time we won't use the UI, but only the JSON definition of the endpoints. Now, restore the NuGet packages and run the project: you'll be able to see the Swagger UI. I'm going to use the MarvelMovies project I used for both the Swagger and the HttpRepl articles: you can download it from GitHub. In this article, I'm going to explain how you can use the OpenAPI file to automatically generate code with Visual Studio 2019 so that you can use the boilerplate code instead of writing your own client. It's interesting for discovering the possible operations, but not really that useful for real integration with a project. We've also seen that you can use the OpenAPI file to navigate the APIs via the CLI with HttpRepl as if they were folders within a file system.
