-
Notifications
You must be signed in to change notification settings - Fork 25.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macOS - no Swagger on Tutorial: Create a web API #21647
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I'm trying this tutorial on my MacBook, and I see the WeatherForecast page, but the swagger page is not loading. |
I'm in the same situation as @drock702 |
@paulzolnierczyk - I got it to work by installing Swagger/Swashbuckle package and "Rebuild All" my project. |
@wadepickett can you test this on macOS? |
Hello. Im currently using Visual Studio on Mac, and in tutorial page the swagger initial configuration for it to work is missing. So in "Test your project" section, the swagger configuration is missing, leaving /Startup.cs as follows:
. This bit of code necessary to configure swagger is shown in the same page in the section "Register the database context" (the lines commented). I hope it helps. |
I am still not able to run the test api provided in the "https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-5.0&tabs=visual-studio-code". localhost:5001(/swagger) shows just "This page isn’t workinglocalhost didn’t send any data. Please help asap. Note: Using VS Code |
I try to paste the swagger config code to the startup.cs file , but getting error :( |
Make sure you have the .NET 5.0 SDK installed and that .NET 5.0 is selected as the target framework in the project properties. For those who are experiencing this problem on Windows, make sure you're using Chrome rather than IE to load the Swagger page. In IE it just shows a blank page, but in Chrome it works. |
Edge works too. Thanks for the tip. |
That's nice, thanks I will try all of your suggestions.
*Thanks*
*Paramita Roy*
*Senior Quality Assurance Analyst II (IT Analysis)*
*Mobile: +1 682-300-6222*
<https://www.linkedin.com/in/paramita-roy-297197104/>
…On Wed, Sep 15, 2021 at 3:04 PM Rick Anderson ***@***.***> wrote:
make sure you're using Chrome rather than IE to load the Swagger page. In
IE it just shows a blank page, but in Chrome it works.
Edge works too. Thanks for the tip.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#21647 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AP56D5AEPSJ2LK3VHVEYRE3UCDU4BANCNFSM4YMU5C3Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
This video is the solution: |
Awesome, thanks!
On Tue, Oct 26, 2021 at 2:03 PM Shad ***@***.***> wrote:
I tried a new project to see what was happening. First go to your project
root folder and run:
dotnet add package Swashbuckle.AspNetCore -v 5.6.3
This will add the Swashbuckle package into your project containing
Swagger. Than you can change your Startup.cs following:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
namespace <your_namespace_here>
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "GpioService", Version = "v1" });
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "GpioService v1"));
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
Just change your namespace to your project namespace. For me it's working
like a charm: [image: Screen Shot 2021-09-01 at 18 51 57]
<https://user-images.githubusercontent.com/12357601/131756038-47edcef4-d9d0-4e71-8d44-58e8cfabf7cb.png>
I hope it helps.
This fixed the problem for me. VS Mac on 2020 MBP.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#21647 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AP56D5DTX4KECKVPK2C2GKLUI3UNRANCNFSM4YMU5C3Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
--
Paramita Roy
Software Quality Assurance Analyst
Contact No: 682-300-6222
|
@rohitsiddha why are you using .NET 5 and not .NET 6? |
@rohitsiddha this happened to me too thank you |
@rohitsiddha Thank you for the the fix. What an odd bug. Deselecting Enable OpenAPI support actually enables it. I am using .Net 5 as well (the current recommendation for M1 Macs). |
Thanks very much to all of you who relayed your experience and identified the issue! This appears to have been fixed and working as expected in the current version 17.6 (build 1575) of Visual Studio for Mac when targeting .NET 5. The Enable OpenAPI support setting results in Swagger working properly. I also verified it continues to work properly in the new Visual Studio 2022 for Mac Preview with .NET 5 and I checked the latest Visual Studio 2022 17.6.4 for windows and .NET 5. Works as expected. The prerequisites for the .NET 5 version of the tutorial point to the latest version of Visual Studio for Mac, which is what should be used. I will add some text to clarify it is the latest version that is required in the prerequisites. When you select .NET 5 in the latest Visual Studio, you will also see the .NET 5 target setting listed as .NET 5.0 (Out of support), which it is, and receive an additional warning once the project is created. .NET 7.0.7 is the latest with Standard Term Support and .NET 6 is Long Term Support. The latest SDK's are available here: https://dotnet.microsoft.com/download/dotnet To verify what version of Visual Studio for Mac you currently have, select the Visual Studio > About Visual Studio menu. |
Fixed with #27363 .NET 7 MacOS: Tutorial: Create a web API |
This issue is still happening. My current SDK version is: 9.0.101 To reproduce the issue follow the VS Code steps from: Tutorial: Create a web API with ASP.NET Core To make it shorter, run:Create a new projectdotnet new webapi --use-controllers -o TodoApi Generate and trust self-signed certificatesdotnet dev-certs https --trust Start the appdotnet run --launch-profile https When you start the application and try to reach the swagger on your browser, you get a blank page.
I hope you can reopen this one. |
I've made a mistake while following the tutorial using the latest version (.NET 9), it is now known that .NET 9 removed swagger support from the templates, so it makes sense getting this 404 when calling it. More info can be found at: https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-8.0&tabs=visual-studio The current is status is that I managed to get it working using the latest release of .NET 8 |
Since this is a "Hello World" kind of situation, more help when things go wrong would be appreciated. I followed the instructions and the /Swagger URL wouldn't load. I'm sure I'm missing some prerequisite, but don't know what yet.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Associated WorkItem - 97033
The text was updated successfully, but these errors were encountered: