Last active
October 23, 2024 09:49
-
-
Save jkone27/5dd13bc071ead66e62239431155216da to your computer and use it in GitHub Desktop.
Falco openapi swagger fsharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#nowarn "20" | |
// invoke this script locally to load aspnet dependencies | |
// https://github.com/TheAngryByrd/IcedTasks/blob/master/generate-sdk-references.fsx | |
#load "runtime-scripts/Microsoft.AspNetCore.App-latest-8.fsx" | |
#r "nuget: Falco, 5.0.0-alpha3" | |
#r "nuget: Falco.OpenApi, 1.0.0-alpha1" | |
#r "nuget: Swashbuckle.AspNetCore" | |
open Falco | |
open Falco.OpenApi | |
open Microsoft.AspNetCore.Builder | |
open Microsoft.Extensions.DependencyInjection | |
open Microsoft.Extensions.Hosting | |
open Falco.Routing | |
open Swashbuckle | |
open System | |
let endpoints = | |
[ | |
get "/" ($"falco app on FSX! v.1.0 - live since: {DateTime.UtcNow}" |> Response.ofPlainText) | |
get "/hello" | |
("Hello World" |> Response.ofPlainText) | |
|> OpenApi.name "HelloWorld" | |
|> OpenApi.description "returns hello world" | |
|> OpenApi.returnType typeof<string> | |
get "/hello-json" | |
("""{ "Hello" : "World" }""" |> Response.ofJson) | |
|> OpenApi.name "HelloWorldJson" | |
|> OpenApi.description "returns hello world in json" | |
|> OpenApi.returnType typeof<{| Hello: string |}> | |
] | |
let configure (builder: WebApplicationBuilder) = | |
builder.Services | |
.AddFalcoOpenApi() | |
.AddSwaggerGen() | |
builder.Build() | |
let configureApp (app: WebApplication) = | |
app.UseRouting() | |
.UseSwagger() // for generating OpenApi spec | |
.UseSwaggerUI() // for viewing Swagger UI | |
.UseFalco(endpoints) | |
app | |
let webApp = | |
WebApplication.CreateBuilder() | |
|> configure | |
|> configureApp | |
webApp.Run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment