DEV Community

Cover image for .Net Aspire - Add Swagger, OpenApi, Scalar to the AppHost
Arash zandi
Arash zandi

Posted on

.Net Aspire - Add Swagger, OpenApi, Scalar to the AppHost

Before you begin, If you are not familar with OpenApi, Swagger or Scalar please read this article :
net-9-revolutionizing-documentation-of-apis-from-swashbuckle-to-scalar

You can have ApiDocs and also your custom links in your .Net Aspire Dashboard like this :
.Net Aspire - Swagger

Simply install this nuget package Arshid.Aspire.ApiDocs.Extensions to your AppHost.csproj

dotnet add package Arshid.Aspire.ApiDocs.Extensions
Enter fullscreen mode Exit fullscreen mode

Then add these lines for the project that has Swagger, Scalar or etc.

📦 Example

using Arshid.Aspire.ApiDocs.Extensions;

var apiService = builder.AddProject<Projects.AspireApp1_ApiService>("apiservice")
    .WithScalar()
    .WithSwagger()
    .WithOpenApi()
    .WithCustomUrl("https://127.0.0.1:5000/CustomRoute/CustomPage1")
    .WithRoute("/CustomRoute/CustomPage2"); //The URL become something like this {protocol}://{url}:{port}/CustomRoute/CustomPage2

Enter fullscreen mode Exit fullscreen mode

Source Codes are available here in GitHub:
https://github.com/zandiarash/Arshid-Aspire-ApiDocs-Extensions

Nuget Package:
Arshid.Aspire.ApiDocs.Extensions

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay