113
CHAPTER 5 | Designing and Developing Multi-Container and Microservice-Based .NET Applications
such as Azure API App, Azure Mobile App, Azure Service Fabric microservices based on ASP.NET. It
also supports plain Web API deployed on containers, as in for the reference application.
Swashbuckle combines API Explorer and Swagger or
swagger-ui
to provide a rich discovery and
documentation experience for your API consumers. In addition to its Swagger metadata generator
engine, Swashbuckle also contains an embedded version of swagger-ui, which it will automatically
serve up once Swashbuckle is installed.
This means you can complement your API with a nice discovery UI to help developers to use your API.
It requires a small amount of code and maintenance because it is automatically generated, allowing
you to focus on building your API. The result for the API Explorer looks like Figure 6-8.
Figure 6-8. Swashbuckle API Explorer based on Swagger metadata
—
eShopOnContainers catalog microservice
The Swashbuckle generated Swagger UI API documentation includes all published actions. The API
explorer is not the most important thing here. Once you have a Web API that can describe itself in
Swagger metadata, your API can be used seamlessly from Swagger-based tools, including client
proxy-class code generators that can target many platforms. For example, as mentioned,
AutoRest
automatically generates .NET client classes. But additional tools like
swagger-codegen
are also
available, which allow code generation of API client libraries, server stubs, and documentation
automatically.
Currently, Swashbuckle consists of five internal NuGet packages under the high-level metapackage
Swashbuckle.AspNetCore
for ASP.NET Core applications.
After you have installed these NuGet packages in your Web API project, you need to configure
Swagger in the
Program.cs
class, as in the following
Dostları ilə paylaş: