Working through Create a web API with ASP.NET Core Controllers i also did run into the error
Unable to find an OpenAPI description
The tutorial uses dotnet 6, i was using dotnet core 3.1.
I did the changes from sasha answers here and had to add these packages
dotnet add package Microsoft.OpenApi --version 1.2.3
dotnet add package Swashbuckle.AspNetCore.Swagger --version 6.2.3
dotnet add package Swashbuckle.AspNetCore.SwaggerUI --version 6.2.3
dotnet add package Swashbuckle.AspNetCore.SwaggerGen --version 6.2.3
After all that i still got error messages. In step 4 of Exercise - Create a web API project the following is written
Connect to our web API by running the following command:
httprepl https://localhost:{PORT}
Alternatively, run the following command at any time while the HttpRepl is running:
(Disconnected)> connect https://localhost:{PORT}
I was not aware that running httprepl
like this
httprepl https://localhost:{PORT}
still requires that your web app is running. So you have to open a second terminal (cmd.exe) to run your webapi project dotnet run
. After that you can connect to the swagger docs using httprepl like this
connect http://localhost:5000 --verbose --openapi /swagger/v1/swagger.json
http://localhost:5000/> ls
. []
WeatherForecast [GET]
http://localhost:5000/> cd WeatherForecast
/WeatherForecast [GET]
http://localhost:5000/WeatherForecast> get
HTTP/1.1 200 OK
This did the trick for me.
Adding the swagger ui
Swashbuckle.AspNetCore - Getting Started contains
Optionally, insert the swagger-ui middleware if you want to expose
interactive documentation, specifying the Swagger JSON endpoint(s) to
power it from.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("v1/swagger.json", "My API V1");
});
If you change startup.cs
to include this
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c =>
c.SwaggerEndpoint("/swagger/v1/swagger.json", "ContosoPizza v1"));
}
....
You get a nice gui under http://localhost:5000/swagger/
which looks like this
