dotnet / dotnet/fsharp

OpenApi Swashbuckle support for Aspnetcore APIs in F#

Open
#14,392 3 comments 2 reactions 0 assignees View on GitHub
Area-Compiler-CodeGen Feature Request Needs-RFC
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

**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**

```
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 =

[]
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!

image

plus also the swagger api is empty
image

image

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.