You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been playing around with the ASP.NET Core runtime capabilities added to NetPad. It's been a very pleasant update and I'm happy to be using it. :-D
Personally, I thought it would be great to be able to render ASP.NET Web APIs using NetPad, so I wrote the following code using Swashbuckle and Swagger.
However, the XMLDOC wasn't being processed as I expected, so I couldn't complete the scenario configuration because I didn't have the XMLDOC file needed to configure Swashbuckle. I couldn't find any options related to XMLDOC generation, so I'm wondering if there is a workaround or if you could add an option in the next version.
Since I am currently using Monaco and Roslyn, which are grammatically capable of recognizing and autocompleting XMLDOCs, I feel this suggestion is appropriate and I am opening an additional issue.
usingMicrosoft.OpenApi.Models;varbuilder=WebApplication.CreateBuilder();builder.Services.AddDbContext<TodoDb>(opt =>opt.UseInMemoryDatabase("TodoList"));builder.Services.AddDatabaseDeveloperPageExceptionFilter();builder.Services.AddEndpointsApiExplorer();builder.Services.AddSwaggerGen(options =>{options.SwaggerDoc("v1",newOpenApiInfo{Version="v1",Title="ToDo API",Description="An ASP.NET Core Web API for managing ToDo items",TermsOfService=newUri("https://example.com/terms"),Contact=newOpenApiContact{Name="Example Contact",Url=newUri("https://example.com/contact")},License=newOpenApiLicense{Name="Example License",Url=newUri("https://example.com/license")}});// using System.Reflection;varxmlFilename=$"{Assembly.GetExecutingAssembly().GetName().Name}.xml";options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory,xmlFilename));});varapp=builder.Build();app.UseSwagger();app.UseSwaggerUI(options =>{options.SwaggerEndpoint("/swagger/v1/swagger.json","v1");options.RoutePrefix=string.Empty;});app.MapGet("/todoitems",async(TodoDbdb)=>awaitdb.Todos.ToListAsync());app.MapGet("/todoitems/complete",async(TodoDbdb)=>awaitdb.Todos.Where(t =>t.Done).ToListAsync());app.MapGet("/todoitems/{id}",async(intid,TodoDbdb)=>awaitdb.Todos.FindAsync(id)isTodotodo?Results.Ok(todo):Results.NotFound());app.MapPost("/todoitems",async(Todotodo,TodoDbdb)=>{db.Todos.Add(todo);awaitdb.SaveChangesAsync();returnResults.Created($"/todoitems/{todo.Id}",todo);});app.MapPut("/todoitems/{id}",async(intid,TodoinputTodo,TodoDbdb)=>{vartodo=awaitdb.Todos.FindAsync(id);if(todoisnull)returnResults.NotFound();todo.Name=inputTodo.Name;todo.Done=inputTodo.Done;awaitdb.SaveChangesAsync();returnResults.NoContent();});app.MapDelete("/todoitems/{id}",async(intid,TodoDbdb)=>{if(awaitdb.Todos.FindAsync(id)isTodotodo){db.Todos.Remove(todo);awaitdb.SaveChangesAsync();returnResults.NoContent();}returnResults.NotFound();});awaitapp.RunAsync("http://localhost:5678");/* Database Model *//// <summary>/// To Do Item/// </summary>publicclassTodo{/// <summary>/// Unique ID/// </summary>publicintId{get;set;}/// <summary>/// Item Title/// </summary>publicstring?Name{get;set;}/// <summary>/// Done?/// </summary>publicboolDone{get;set;}}publicclassTodoDb:DbContext{publicTodoDb(DbContextOptions<TodoDb>options):base(options){}publicDbSet<Todo>Todos=>Set<Todo>();}
The text was updated successfully, but these errors were encountered:
I've been playing around with the ASP.NET Core runtime capabilities added to NetPad. It's been a very pleasant update and I'm happy to be using it. :-D
Personally, I thought it would be great to be able to render ASP.NET Web APIs using NetPad, so I wrote the following code using Swashbuckle and Swagger.
However, the XMLDOC wasn't being processed as I expected, so I couldn't complete the scenario configuration because I didn't have the XMLDOC file needed to configure Swashbuckle. I couldn't find any options related to XMLDOC generation, so I'm wondering if there is a workaround or if you could add an option in the next version.
Since I am currently using Monaco and Roslyn, which are grammatically capable of recognizing and autocompleting XMLDOCs, I feel this suggestion is appropriate and I am opening an additional issue.
The text was updated successfully, but these errors were encountered: