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.
using Microsoft.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",new OpenApiInfo{Version="v1",Title="ToDo API",Description="An ASP.NET Core Web API for managing ToDo items",TermsOfService=new Uri("https://example.com/terms"),Contact=new OpenApiContact{Name="Example Contact",Url=new Uri("https://example.com/contact")},License=new OpenApiLicense{Name="Example License",Url=new Uri("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)=>await db.Todos.ToListAsync());
app.MapGet("/todoitems/complete",async(TodoDbdb)=>await db.Todos.Where(t => t.Done).ToListAsync());
app.MapGet("/todoitems/{id}",async(intid,TodoDbdb)=>await db.Todos.FindAsync(id)is Todo todo? Results.Ok(todo): Results.NotFound());
app.MapPost("/todoitems",async(Todotodo,TodoDbdb)=>{ db.Todos.Add(todo);await db.SaveChangesAsync();return Results.Created($"/todoitems/{todo.Id}", todo);});
app.MapPut("/todoitems/{id}",async(intid,TodoinputTodo,TodoDbdb)=>{vartodo=await db.Todos.FindAsync(id);if(todo isnull)return Results.NotFound(); todo.Name = inputTodo.Name; todo.Done = inputTodo.Done;await db.SaveChangesAsync();return Results.NoContent();});
app.MapDelete("/todoitems/{id}",async(intid,TodoDbdb)=>{if(await db.Todos.FindAsync(id)is Todo todo){ db.Todos.Remove(todo);await db.SaveChangesAsync();return Results.NoContent();}return Results.NotFound();});await app.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: