openAPISwaggerUI–part 2 – add ui for all
This is how I made
https://nuget.org/packages/OpenAPISwaggerUI in order to see the UI for an ASP.NET 9 project.
And hey, if you have any feedback, don’t be shy! Drop by https://github.com/ignatandrei/openAPISwaggerUI/ and let me know.
Step one in this epic quest: add all the mystical references (a.k.a. NuGet packages) to the project file.
<ItemGroup> <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" /> <PackageReference Include="NetCore2Blockly" Version="9.2024.1206.813" /> <PackageReference Include="NSwag.AspNetCore" Version="14.2.0" /> <PackageReference Include="RSCG_NameGenerator" Version="2024.26.8.2002" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" /> <PackageReference Include="Scalar.AspNetCore" Version="1.2.56" /> <PackageReference Include="Swashbuckle.AspNetCore.ReDoc" Version="7.2.0" /> <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="7.2.0" /> </ItemGroup>
Next, I had to figure out how to register these mystical packages to reveal the UI
public static WebApplication UseOpenAPISwaggerUI(this WebApplication app) { //goto /swagger-Swashbuckle app.UseSwaggerUI(options => { options.SwaggerEndpoint("/openapi/v1.json", "v1"); options.RoutePrefix = "swagger-Swashbuckle"; }); //scalar //goto swagger-scalar/v1 app.MapScalarApiReference(opt => { opt.EndpointPathPrefix = "/swagger-scalar/{documentName}"; }); //redoc //goto /api-docs app.UseReDoc(options => { options.SpecUrl("/openapi/v1.json"); options.RoutePrefix = "swagger-redoc"; }); //goto /nswag-swagger app.UseSwaggerUi(options => { options.DocumentPath = "/openapi/v1.json"; options.Path = "/swagger-nswag"; }); //goto /blocklyautomation app.UseBlocklyUI(app.Environment); app.UseBlocklyAutomation(); }
After this it was simple to use the extension in program.cs
app.MapOpenApi(); app.UseOpenAPISwaggerUI();