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
Potential continuation of #1580 and a couple others I can't find now; however, none of the solutions seemed to work.
I'm just trying to start a fresh C# .NET7 web api + static website (with forwarding set for Vite during development, though that shouldn't affect anything here)
I tried recreating the Startup.cs file/class and usage as described by others, but that didn't seem to affect it. So for brevity, I've gone back to a single Program.cs file I share below.
I've tried swapping the ApiExplorer in various ways and removing the options I set, all to no avail.
I'm at my wits end with this, which is why I'm posting here.
If this gets figured out, I'd be happy to submit a PR for a getting started example for NET7+ so no one else has to go through this.
Here's the whole program initialization:
usingMicrosoft.Extensions.Options;usingSwashbuckle.AspNetCore.Swagger;usingSwashbuckle.AspNetCore.SwaggerGen;usingMicrosoft.AspNetCore.Mvc.Versioning;usingSystem.Text.Json.Serialization;varbuilder=WebApplication.CreateBuilder(newWebApplicationOptions{ApplicationName="TheNamespaceIUseForEverything",Args=args});// Add services to the container.varconfig=builder.Configuration;varparsedRequiredConfig=newParsedRequiredConfig(config);varservices=builder.Services;varenv=builder.Environment;services.AddControllers().AddJsonOptions(options =>{options.JsonSerializerOptions.DefaultIgnoreCondition=JsonIgnoreCondition.WhenWritingNull;options.JsonSerializerOptions.Converters.Add(newJsonStringEnumConverter());});services.AddMvc();services.AddEndpointsApiExplorer();services.AddApiVersioning(options =>{options.AssumeDefaultVersionWhenUnspecified=true;options.ApiVersionReader=newUrlSegmentApiVersionReader();options.UseApiBehavior=false;});services.AddVersionedApiExplorer(options =>{options.GroupNameFormat="VVV";options.SubstituteApiVersionInUrl=true;});services.AddSwaggerGen();// services.Configure<SwaggerGenOptions>(Configuration.GetSection("SwaggerGen"));services.Configure<SwaggerOptions>(config.GetSection("Swagger"));services.AddTransient<IConfigureOptions<SwaggerGenOptions>,ConfigureSwaggerOptions>();varapp=builder.Build();if(env.IsDevelopment()){app.UseDeveloperExceptionPage();}else{// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.app.UseHsts();}app.UseStaticFiles().UseApiVersioning().UseRouting().UseEndpoints(endpoints =>{endpoints.MapControllers();}).UseSwagger();app.MapControllerRoute(name:"default",pattern:"{controller}/{action=Index}/{id?}");app.MapFallbackToFile("index.html");app.Run();
The SwaggerGenOptions:
publicclassConfigureSwaggerOptions:IConfigureOptions<SwaggerGenOptions>{readonlyIApiVersionDescriptionProviderprovider;publicConfigureSwaggerOptions(IApiVersionDescriptionProviderprovider)=>this.provider=provider;publicvoidConfigure(SwaggerGenOptionsoptions){foreach(vardescriptioninprovider.ApiVersionDescriptions){options.SwaggerDoc($"OpenAPI_v{description.GroupName}",newOpenApiInfo(){Title=$"Doc for API v{description.ApiVersion}",Description="",Version=$"v{description.ApiVersion.ToString()}",});}varxmlCommentsPath=Path.Combine(System.AppContext.BaseDirectory,"ApiComments.xml");options.IncludeXmlComments(xmlCommentsPath,true);}}
Potential continuation of #1580 and a couple others I can't find now; however, none of the solutions seemed to work.
I'm just trying to start a fresh C# .NET7 web api + static website (with forwarding set for Vite during development, though that shouldn't affect anything here)
I tried recreating the
Startup.cs
file/class and usage as described by others, but that didn't seem to affect it. So for brevity, I've gone back to a singleProgram.cs
file I share below.I've tried swapping the
ApiExplorer
in various ways and removing the options I set, all to no avail.I'm at my wits end with this, which is why I'm posting here.
If this gets figured out, I'd be happy to submit a PR for a getting started example for NET7+ so no one else has to go through this.
Here's the whole program initialization:
The SwaggerGenOptions:
The Swagger section of the settings just sets:
The text was updated successfully, but these errors were encountered: