You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would love to be able to just use openapi in F# aspnetcore projects and in any F# web framework wrapping around aspnetcore..
Describe alternatives you've considered
At the moment there is no alternative or no working alternative, openapi spec needs to be written by hand, making development and integration with other teams slower and possibly more error prone... and making F# sound like a "less professional choice" as it cannot easilly interact with common API tooling for .NET (swashbuckle nuget package).
Example of code that should work based on Aspnetcore docs
open System
open System.Collections.Generic
open System.IO
open System.Linq
open System.Threading.Tasks
open Microsoft.AspNetCore
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.HttpsPolicy
open Microsoft.Extensions.Configuration
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.Logging
open Microsoft.AspNetCore.Http
open Microsoft.AspNetCore.OpenApi
open Swashbuckle.AspNetCore
open Microsoft.OpenApi
module Program =
[<EntryPoint>]
let main args =
let builder = WebApplication.CreateBuilder(args)
builder.Services.AddEndpointsApiExplorer() |> ignore
builder.Services.AddSwaggerGen() |> ignore
let app = builder.Build()
if (app.Environment.IsDevelopment()) then
app.UseSwagger() |> ignore
app.UseSwaggerUI(fun c -> ()) |> ignore
app.MapGet("/hello",
requestDelegate = fun x -> task { return "hello" } )
.WithName("HelloF#")
.WithOpenApi() |> ignore
app.Run()
0
but this gives me wrong api (hello returns an empty body, not "hello" text string..) , 200 OK but no content!
plus also the swagger api is empty
The text was updated successfully, but these errors were encountered:
There is nothing really wrong with F# and minimal apis, the main problem here is that the RequestDelegate overload does not add openapi info (which is by design atm, see dotnet/aspnetcore#44970).
You have to use the Delegate overload to get the 'true' minimal api experience. Additionally to make this easy in F# you probably want to add Func<T1,T2,T3,TEtc> extension methods for MapGet, MapPost etc (which do nothing but cast to Delegate and pass it into the main overload). fsharp/fslang-suggestions#1131 was opened to track that usability issue.
Unable to use swashbuckle with F# minimal APIs (or Giraffe, or Saturn, or Falco or any other web framework)
https://www.youtube.com/watch?v=HXHwtEjQoyM&ab_channel=dotnet
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/openapi?view=aspnetcore-7.0
I tried this in F# and doesnt work.
Describe the solution you'd like
I would love to be able to just use openapi in F# aspnetcore projects and in any F# web framework wrapping around aspnetcore..
Describe alternatives you've considered
At the moment there is no alternative or no working alternative, openapi spec needs to be written by hand, making development and integration with other teams slower and possibly more error prone... and making F# sound like a "less professional choice" as it cannot easilly interact with common API tooling for .NET (swashbuckle nuget package).
Example of code that should work based on Aspnetcore docs
but this gives me wrong api (hello returns an empty body, not "hello" text string..) , 200 OK but no content!
plus also the swagger api is empty
The text was updated successfully, but these errors were encountered: