dotnet / HttpRepl

The HTTP Read-Eval-Print Loop (REPL) is a lightweight, cross-platform command-line tool that's supported everywhere .NET Core is supported and is used for making HTTP requests to test ASP.NET Core web APIs and view their results.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to find an OpenAPI description

paddywide opened this issue · comments

Hi,
I follow the tutorial https://docs.microsoft.com/en-au/learn/modules/build-web-api-aspnet-core/3-exercise-create-web-api, then I get stuck to run connect http://localhost:5000, it said Unable to find an OpenAPI description

I run connect http://localhost:5000 --verbose it returns:
Checking http://localhost:5000/swagger.json... 404 NotFound
Checking http://localhost:5000/swagger/v1/swagger.json... 404 NotFound
Checking http://localhost:5000/openapi.json... 404 NotFound

I run dotnet dev-certs https --trust, when I run dotnet run it returns:
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\Project\3

How can I solve the problem?

Hard to say what's going on here. I just went through the instructions and it worked fine for me. The second link checked in your httprepl output above - http://localhost:5000/swagger/v1/swagger.json - is the one that should be available after running those instructions. Can you access it via a web browser?

I note that in your output for dotnet run, you show an https address as well as the http one. Which means at least something is different than the directions in the exercise (the directions specify --no-https) so perhaps something else was different/slipped along the way?

I tried both dotnet new webapi --no-https and dotnet new webapi. To create a webapi without https, the output of dotnet run will be:
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\Project\2

I can't access http://localhost:5000/swagger/v1/swagger.json via web browser.

The first time I go through the tutorial, it works. But the next day I run the same project without modifying any code and fail(shows Unable to find an OpenAPI description). This happens the same in 2 different PC.

Since you can't access the swagger definition via a web browser either, then the problem isn't with HttpRepl. It must be something to do with the config of your app, though I can't be sure what.

For starters, I'd try checking to make sure that the app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "ContosoPizza v1")); line in Startup.cs of the tutorial is being executed. It looks like you're running in development mode, so it should be but clearly something is going wrong there.

Beyond that, I'd suggest filing feedback with the learn tutorial and see if you can get help from them - maybe someone else has run into something similar.

I found the solution. My laptop contains other Nuget sources which is the company internal source and used by visual studio as well. I remove those sources and reinstall httprepl and re-create the tutorial project. then it works.

If I understand correctly you have deleted all files and directory from c:\User\xxx.nuget
can you confirm it to us?

commented

很难说这里发生了什么。我只是按照说明进行了操作,对我来说效果很好。在上面的 httprepl 输出中检查的第二个链接 - http://localhost:5000/swagger/v1/swagger.json - 是在运行这些指令后应该可用的链接。您可以通过网络浏览器访问它吗?

我注意到,在dotnet run的输出中,您显示了一个https地址以及http地址。这意味着至少有些东西与练习中的方向不同(方向指定 --no-https),所以也许还有其他东西不同/在此过程中滑倒了?

在.net8.0中这是对的,要注意http和https的区别,https会找不到 OpenAPI 描述