DEV Community

Supraja Tangella
Supraja Tangella

Posted on

𝗨𝗻𝗹𝗼𝗰𝗸 𝘁𝗵𝗲 𝗣𝗼𝘄𝗲𝗿 𝗼𝗳 𝗢𝗽𝗲𝗻𝗔𝗣𝗜 𝗶𝗻 𝗔𝗦𝗣.𝗡𝗘𝗧 𝗖𝗼𝗿𝗲: 𝗨𝘀𝗶𝗻𝗴 𝗦𝘄𝗮𝗴𝗴𝗲𝗿 𝗨𝗜, 𝗦𝗰𝗮𝗹𝗮𝗿, 𝗮𝗻𝗱 𝗦𝗽𝗲𝗰𝘁𝗿𝗮𝗹 𝗳𝗼𝗿 𝗕𝗲𝘁𝘁𝗲𝗿 𝗔𝗣𝗜 𝗗𝗼𝗰𝘂𝗺𝗲𝗻𝘁𝗮𝘁𝗶𝗼𝗻 𝗮𝗻𝗱 𝗧𝗲𝘀𝘁𝗶𝗻𝗴

𝟭. 𝗦𝘄𝗮𝗴𝗴𝗲𝗿 𝗨𝗜 – 𝗟𝗼𝗰𝗮𝗹 𝗔𝗱-𝗛𝗼𝗰 𝗔𝗣𝗜 𝗧𝗲𝘀𝘁𝗶𝗻𝗴

Swagger UI provides an interactive web interface to visualize and test your OpenAPI documents locally. It is widely used to explore and verify API endpoints during development.

𝗣𝘂𝗿𝗽𝗼𝘀𝗲: Quickly test your API endpoints with an intuitive UI directly in your ASP.NET Core app.

𝗖𝗼𝗱𝗲 𝘀𝗻𝗶𝗽𝗽𝗲𝘁:

builder.Services.AddOpenApi();

app.MapOpenApi();

app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/openapi/v1.json", "v1");
});

Access it at: https://localhost:<port>/swagger

Enable "launchBrowser": true and set "launchUrl": "swagger" in launchSettings.json to auto-open the app at the Swagger UI URL using the HTTPS profile.

𝟮. 𝗦𝗰𝗮𝗹𝗮𝗿 – 𝗜𝗻𝘁𝗲𝗿𝗮𝗰𝘁𝗶𝘃𝗲 𝗔𝗣𝗜 𝗗𝗼𝗰𝘂𝗺𝗲𝗻𝘁𝗮𝘁𝗶𝗼𝗻

Scalar is an open-source UI alternative for OpenAPI documentation, designed to provide an interactive experience similar to Swagger UI.

𝗣𝘂𝗿𝗽𝗼𝘀𝗲: Offer a clean and customizable interactive API doc experience integrated with your OpenAPI endpoint.

𝗖𝗼𝗱𝗲 𝘀𝗻𝗶𝗽𝗽𝗲𝘁:

builder.Services.AddOpenApi();
app.MapOpenApi();
app.MapScalarApiReference();

Access it at: https://localhost:<port>/scalar/v1

Set "launchBrowser": true and "launchUrl": "scalar/v1" in launchSettings.json to auto-launch the app at the Scalar UI URL with the HTTPS profile.

𝟯. 𝗦𝗽𝗲𝗰𝘁𝗿𝗮𝗹 – 𝗟𝗶𝗻𝘁𝗶𝗻𝗴 𝗢𝗽𝗲𝗻𝗔𝗣𝗜 𝗗𝗼𝗰𝘂𝗺𝗲𝗻𝘁𝘀

Spectral is a powerful linter that checks your OpenAPI document for errors and best practice violations during build time, helping ensure high-quality API definitions.

𝗣𝘂𝗿𝗽𝗼𝘀𝗲: Automatically validate and maintain consistency in your OpenAPI documents.

𝗦𝗲𝘁𝘂𝗽 𝘀𝗻𝗶𝗽𝗽𝗲𝘁 (𝗶𝗻 .𝗰𝘀𝗽𝗿𝗼𝗷):

true

$(MSBuildProjectDirectory)

Run lint:

spectral lint WebMinOpenApi.json

𝗪𝗵𝗶𝗰𝗵 𝘁𝗼𝗼𝗹 𝗱𝗼 𝘆𝗼𝘂 𝗿𝗲𝗹𝘆 𝗼𝗻 𝗺𝗼𝘀𝘁 𝗳𝗼𝗿 𝗔𝗣𝗜 𝗱𝗼𝗰𝘂𝗺𝗲𝗻𝘁𝗮𝘁𝗶𝗼𝗻 𝗮𝗻𝗱 𝘁𝗲𝘀𝘁𝗶𝗻𝗴 𝗶𝗻 𝘆𝗼𝘂𝗿 𝗽𝗿𝗼𝗷𝗲𝗰𝘁𝘀? 𝗛𝗮𝘃𝗲 𝘆𝗼𝘂 𝘁𝗿𝗶𝗲𝗱 𝗰𝗼𝗺𝗯𝗶𝗻𝗶𝗻𝗴 𝘁𝗵𝗲𝘀𝗲 𝘁𝗼𝗼𝗹𝘀 𝗳𝗼𝗿 𝗮 𝗺𝗼𝗿𝗲 𝗿𝗼𝗯𝘂𝘀𝘁 𝗢𝗽𝗲𝗻𝗔𝗣𝗜 𝘄𝗼𝗿𝗸𝗳𝗹𝗼𝘄?

Top comments (0)