elsa-workflows / elsa-workflows/elsa-core
[BUG] Unable to Run Swagger from FastEndPoint
- Dominant language
- C#
- Stars
- 7.9k
- Forks
- 1.5k
- Avg merge
- 15h 22m
- Merged PRs (30d)
- 114
Description
## Description
When trying to configure Swagger a `Internal Server Eror` appar
## Steps to Reproduce
In `Program.cs` add the following
- inside `builder.Services.AddElsa` add the following `elsa.AddSwagger();`
- After `builder.Services.AddElsa` add the following `builder.Services.AddFastEndpoints().AddSwaggerDocument();`
- in the `app` section add the following `app.UseFastEndpoints().UseSwaggerGen();` and `app.MapFastEndpoints();`
```C#
using Elsa.Studio.Core.BlazorServer.Extensions;
using Elsa.Studio.Dashboard.Extensions;
using Elsa.Studio.Extensions;
using Elsa.Studio.Login.BlazorServer.Extensions;
using Elsa.Studio.Login.HttpMessageHandlers;
using Elsa.Studio.Shell.Extensions;
using Elsa.Studio.Workflows.Extensions;
using Elsa.Studio.Workflows.Designer.Extensions;
using Elsa.Extensions;
using FastEndpoints;
using FastEndpoints.Swagger;
using Elsa.Studio.Models;
using Elsa.EntityFrameworkCore.Modules.Management;
using Elsa.EntityFrameworkCore.Extensions;
using Elsa.EntityFrameworkCore.Modules.Runtime;
using Elsa.Alterations.Extensions;
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
builder.Services.AddElsa(elsa =>
{
elsa.UseWorkflowManagement(managment =>
{
managment.UseEntityFrameworkCore(ef =>
{
ef.UseSqlServer(configuration.GetConnectionString("Elsa"));
});
});
elsa.UseWorkflowRuntime(runtime =>
{
runtime.UseEntityFrameworkCore(ef =>
{
ef.UseSqlServer(configuration.GetConnectionString("Elsa"));
});
});
elsa.UseIdentity(identity =>
{
identity.TokenOptions = options => options.SigningKey = "sufficiently-large-secret-signing-key";
identity.UseAdminUserProvider();
});
elsa.AddSwagger();
elsa.UseDefaultAuthentication(auth => auth.UseAdminApiKey());
elsa.UseWorkflowsApi();
elsa.UseRealTimeWorkflows();
elsa.UseCSharp();
elsa.UseJavaScript();
elsa.UseHttp();
elsa.AddSwagger();
elsa.UseExpressions();
elsa.UseLabels();
elsa.UseAlterations();
elsa.AddActivitiesFrom();
elsa.AddWorkflowsFrom();
});
builder.Services.AddFastEndpoints().AddSwaggerDocument();
builder.Services.AddCors(cors =>
{
cors.AddDefaultPolicy(policy =>
{
policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().WithExposedHeaders("x-elsa-workflow-instance-id");
});
});
builder.Services.AddHealthChecks();
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor(options =>
{
options.DetailedErrors = true;
options.RootComponents.RegisterCustomElsaStudioElements();
});
builder.Services.AddCore();
builder.Services.AddShell(options => configuration.GetSection("Shell").Bind(options));
var backendApiConfig = new BackendApiConfig
{
ConfigureBackendOptions = options => configuration.GetSection("Backend").Bind(options),
ConfigureHttpClientBuilder = options => options.AuthenticationHandler = typeof(AuthenticatingApiHttpMessageHandler),
};
builder.Services.AddRemoteBackend(backendApiConfig);
builder.Services.AddLoginModule();
builder.Services.AddDashboardModule();
builder.Services.AddWorkflowsModule();
builder.Services.AddSignalR(options =>
{
options.MaximumReceiveMessageSize = 5 * 1024 * 1000;
});
var app = builder.Build();
app.UseCors();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseFastEndpoints().UseSwaggerGen();
app.UseWorkflowsApi();
app.UseWorkflows();
app.UseWorkflowsSignalRHubs();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.MapFastEndpoints();
app.Run();
```
## Expected Behavior
I must be able to navigate to `/swagger`
## Actual Behavior
I get a `Internal Server Error`
## Screenshots
## Environment
- **Elsa Package Version**: 3.3.0-rc6 also in 3.2.3
- **Operating System**: Windows
- **Browser and Version**: MS Edge
- **Net Core**:9.0
## Log Output
```pwsh
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.InvalidOperationException: Duplicate endpoint name 'ElsaWorkflowsApiEndpointsWorkflowInstancesVariablesPostList' found on 'HTTP: POST /elsa/api/workflow-instances/{id}/variables' and 'HTTP: POST /workflow-instances/{id}/variables'. Endpoint names must be globally unique.
at Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher.CreateMatcher(IReadOnlyList`1 endpoints)
at Microsoft.AspNetCore.Routing.DataSourceDependentCache`1.Initialize()
at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
at Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher..ctor(EndpointDataSource dataSource, Lifetime lifetime, Func`1 matcherBuilderFactory)
at Microsoft.AspNetCore.Routing.Matching.DfaMatcherFactory.CreateMatcher(EndpointDataSource dataSource)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.InitializeCoreAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.g__AwaitMatcher|10_0(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task`1 matcherTask)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.InvalidOperationException: Duplicate endpoint name 'ElsaWorkflowsApiEndpointsWorkflowInstancesVariablesPostList' found on 'HTTP: POST /elsa/api/workflow-instances/{id}/variables' and 'HTTP: POST /workflow-instances/{id}/variables'. Endpoint names must be globally unique.
at Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher.CreateMatcher(IReadOnlyList`1 endpoints)
at Microsoft.AspNetCore.Routing.DataSourceDependentCache`1.Initialize()
at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
at Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher..ctor(EndpointDataSource dataSource, Lifetime lifetime, Func`1 matcherBuilderFactory)
at Microsoft.AspNetCore.Routing.Matching.DfaMatcherFactory.CreateMatcher(EndpointDataSource dataSource)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.InitializeCoreAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.g__AwaitMatcher|10_0(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task`1 matcherTask)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
```
Contributor guide
Assessment
This issue has not been assessed yet.