-
-
Save dj-nitehawk/c7052f01f3f650e67fb6782c84d3b5f0 to your computer and use it in GitHub Desktop.
using FastEndpoints.Swagger; | |
using Scalar.AspNetCore; //dotnet add package Scalar.AspNetCore | |
var bld = WebApplication.CreateBuilder(args); | |
bld.Services | |
.AddFastEndpoints() | |
.SwaggerDocument(); //define a swagger doc - v1 by default | |
var app = bld.Build(); | |
app.UseFastEndpoints(); //must come before the UseOpenApi() call | |
if (app.Environment.IsDevelopment()) | |
{ | |
//scalar by default looks for the swagger json file here: | |
app.UseOpenApi(c => c.Path = "/openapi/{documentName}.json"); | |
app.MapScalarApiReference(); | |
} | |
app.Run(); | |
//scalar ui can be accessed at: http://localhost:{port}/scalar/v1 |
@mkosucu
that has nothing to do with scalar. pls refer to the following docs:
schema names: https://fast-endpoints.com/docs/swagger-support#short-schema-names
endpoint names: https://fast-endpoints.com/docs/swagger-support#short-endpoint-names
I have been looking somewhere completely irrelevant! Many thanks for your help @dj-nitehawk . Appreciated.
Thanks, @dj-nitehawk! I think it's a good time to upgrade the FastEndpoints documentation and mention Scalar UI.
I create another alternative. Example
don't think that's gonna work: FastEndpoints/FastEndpoints#906 (comment)
So I have discovered that if you want the document name to be different, you must specify the document name in the MapScalarApiReference
options. This is seemingly because Scalar defaults to "v1". Please let me know if there is a smoother way to do this.
Example:
const string openApiDocName = "my-api-v1";
app.UseOpenApi(options =>
{
options.Path = "/openapi/{documentName}.json";
});
app.MapScalarApiReference(
"/api-reference",
options => options
.WithTheme(ScalarTheme.Kepler)
.AddDocument("v1", "My API v1", $"/openapi/{openApiDocName}.json"));
If I use this approach, the Model names include namespaces too, i.e.
ScalartestMyRequest
I tried multiple ways, but could not transform the model names, expected nameMyRequest
, Do you have any idea how to resolve this? @dj-nitehawk