-
Notifications
You must be signed in to change notification settings - Fork 25.2k
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
Updated first-web-api tutorial #34676
Conversation
@dotnet-policy-service agree |
@likekaese, thanks so much for your contribution, and I am sorry to hear of your colleague's experience. This work for this was scheduled for this month's "sprint" and tracked in an issue here: I wasn't going to hit this one until other work was completed this coming week, but I'll move it up since you are already starting, and I want you to be successful with the work you already put into it. Thanks very much for your start! We usually try to keep code samples in a self-contained project directory for each version rather than putting the code inline to the .md doc itself. I already had a directory set up for that some time ago before I had to move over to higher priority work a while back here, but it wasn't updated yet: So next you will see the app samples replaced in code that included from the project samples. I will keep what I can of your work here so you get credit, but you will see some changes coming in soon (Today is Sunday and I might not be able to get a lot done until Monday). Nothing for you to do at the moment as I am making those changes. Thanks again for the contribution, greatly appreciated! |
@wadepickett Thanks, I'm always happy to contribute! Good to know this was already planned, and I really appreciate you prioritizing it. Keeping code samples in separate project directories makes sense—I’ll keep that in mind for future contributions (and maybe some hobby projects). Looking forward to seeing how everything comes together. Let me know if there's anything else I can do. Thanks again! |
@@ -67,6 +67,9 @@ A NuGet package must be added to support the database used in this tutorial. | |||
* From the **Tools** menu, select **NuGet Package Manager > Manage NuGet Packages for Solution**. | |||
* Select the **Browse** tab. | |||
* Enter **Microsoft.EntityFrameworkCore.InMemory** in the search box, and then select `Microsoft.EntityFrameworkCore.InMemory`. | |||
* Select the **Project** checkbox in the right pane and then select **Install**. | |||
* Enter **Swashbuckle.AspNetCore.SwaggerUI** in the search box, and then select `Swashbuckle.AspNetCore.SwaggerUI`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're no longer using swagger. The .NET 9 controller API template generates the following code using the Swagger replacement, OpenAPI.
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're no longer using swagger. The .NET 9 controller API template generates the following code using the Swagger replacement, OpenAPI.
Why was Swagger left in the tutorial, and this comment marked as resolved? I'm unresolving it so you can see my question.
Note that there are other instances of "Swashbuckle" "and "Swagger" that need to be addressed as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I resolved offline with Rick at the time, before setting as resolved here. The statement "We're no longer using swagger." was not correct as a broad statement. The Swashbuckle package tools are no longer used to generate the OpenAPI doc. Microsoft's OpenAPI package is now used for generating the OpenAPI doc. SwaggerUI is still used and recommended for generating UI for interactivity and uses that Microsoft created OpenAPI doc. See Safia's https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/using-openapi-documents?view=aspnetcore-9.0#use-swagger-ui-for-local-ad-hoc-testing
@lukekaese, please don't make any changes or close. I'm in the middle of updating this PR with work I finished last night. I think there is some miscommunication around using SwaggerUI for visualization and interaction while OpenAPI generates the doc that SwaggerUI uses to provide visualization (What I am updating the PR for) vs using the Swashbuckle tools to generate the doc which, we would not do and the point I think Rick is raising. Sorting it out with Rick. Thanks. |
@wadepickett I wasn't going to, but I was about to say something along those lines ^^. Perhaps my wording was a bit unclear, but yes, exactly as you said: OpenAPI is for generating, while SwaggerUI is for visualizing. |
No worries, I understood. |
Moving as approved to new branch, then adding my changes in a moment... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving work so far so I can move this into a new branch and add changes from there.
Tab issue in doc, fixing it... |
Close and reopening pr to flush cache. |
@lukekaese please do not make any changes. Will let you know when it is in a state ready for review of my changes. |
A corrected code snippet is now pulled in above this from a full app sample.
@tdykstra, I added a lot to this original PR for the update. It would be good to get a review from you since I added so much. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed and executed the instructions to validate them up to scaffolding the controller and skimmed the changes after that.
I thought we were going to use .http files for testing with VS in .NET 9 (?)
* `Microsoft.EntityFrameworkCore.InMemory`: Enables Entity Framework Core to work with an in-memory database rather than an external one, simplifying this tutorial. | ||
* `Swashbuckle.AspNetCore.SwaggerUI`: Provides a user interface for exploring and testing API endpoints interactively through Swagger. | ||
|
||
Add the following NuGet packages used in this tutorial. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not rendering as a bulleted list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this. Trying to figure out what is wrong with it. It looks right in markdown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tdykstra, I cannot figure out why a blank line is showing up between the list items.
This for example, renders fine as a list:
The preceding highlighted code:
- Adds the Swagger UI as a service to the app with
app.UseSwaggerUI()
. - Sets the
SwaggerEndpoint()
option to the location of the OpenAPI documentation for this project. - Ensures the Swagger UI is only available in the app development environment to limit information disclosure and security vulnerability.
This, which is set up the same way, throws in line spaces in the build, but does fine when displayed here:
This tutorial uses the following additional NuGet packages:
Microsoft.EntityFrameworkCore.InMemory
: Enables Entity Framework Core to work with an in-memory database rather than an external one, simplifying this tutorial.Swashbuckle.AspNetCore.SwaggerUI
: Provides a user interface for exploring and testing API endpoints interactively through Swagger.
I can't spot what is tripping it up. I also checked against the style guide examples and other topics we have here doing the same thing. I tried removing the code ticks ` just in case there was some issue with that. That wasn't it either.
@@ -67,6 +67,9 @@ A NuGet package must be added to support the database used in this tutorial. | |||
* From the **Tools** menu, select **NuGet Package Manager > Manage NuGet Packages for Solution**. | |||
* Select the **Browse** tab. | |||
* Enter **Microsoft.EntityFrameworkCore.InMemory** in the search box, and then select `Microsoft.EntityFrameworkCore.InMemory`. | |||
* Select the **Project** checkbox in the right pane and then select **Install**. | |||
* Enter **Swashbuckle.AspNetCore.SwaggerUI** in the search box, and then select `Swashbuckle.AspNetCore.SwaggerUI`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're no longer using swagger. The .NET 9 controller API template generates the following code using the Swagger replacement, OpenAPI.
Why was Swagger left in the tutorial, and this comment marked as resolved? I'm unresolving it so you can see my question.
Note that there are other instances of "Swashbuckle" "and "Swagger" that need to be addressed as well.
@tdykstra, thanks.
SwaggerUI is currently a heavily poplular tool out there for visualization/interactivity. We have examples in tutorials now using VS .http and Scalar, but I decided to maintain this one as the remaining SwaggerUI example. ( SwaggerUI using Microsofts OpenAPI package that creates the doc, which SwaggerUI uses to add the visualization. ) That seem good? Also see my explanation on Swagger UI in the other comment above and that I had resolved with Rick offline before marking that item as resolved. |
Add tdykstra review commits Co-authored-by: Tom Dykstra <tdykstra@microsoft.com>
Sorry @lukekaese and @tdykstra, closing per #34746 (comment) |
Reopening to get a build and will close back up. |
Closing per note above. |
@wadepickett don't worry. I'm sorry for wasting your time for a bit. At least the Documentation is getting better, That's all that counts. Maybe my next PR is more successful. Thanks you for everything ^^ |
* Update .NET version references in first-web-api.md to 9.0 * update sample to target .NET 9.0 * rename example to _SwaggerExample * add OpenAPI example (no swagger) * update WebApi to .NET 9 (without swagger) * remove unused example * review fixes * apply changes from #34676 * include IsDevelopment codeblock to match the text description * VS new project settings moved to order they appear in dialog * Right-click or Command-click on project in VSC Control-click on a project in VSC on windows does not work, must be Right-click for Windows and Control-click on macOS for VSC. * Specifying the DTO file and location in the instruction * Apply suggestions from code review * Update author names in web API tutorial * Add comment block in first-web-api tutorial * Apply suggestions from code review revert * Update aspnetcore/tutorials/first-web-api.md * remove unused file 'create-new-project' --------- Co-authored-by: Wade Pickett <wpickett@microsoft.com> Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com>
Hi,
A colleague of mine recently took his first steps with C# and ASP.NET Core, specifically in .NET 9. Unfortunately, he became quite frustrated while following this tutorial:
Create a web API with ASP.NET Core
The tutorial did not work as expected. Since I work full-time with C# in our company, I stepped in to assist, but I noticed that the tutorial does not function correctly in its current state. Either the mention of Swagger needs to be removed, or the tutorial should be updated to reflect the necessary adjustments.
I found that only a few lines of code need modification to restore the expected functionality. I also came across issue #34558, which might be related, so I wanted to contribute a fix.
I hope this helps! Let me know if any further adjustments are needed.
Best regards,
Luke
[Added below by Wade Pickett]
Fixes #33001
Internal previews