Created
October 21, 2024 21:50
-
-
Save jkone27/dee950808063cbd27eff35caa8a2740e to your computer and use it in GitHub Desktop.
oxpecker openapi F# swagger
This file contains hidden or 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" // for OOP/ignore values | |
// 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: Oxpecker" | |
#r "nuget: Oxpecker.OpenApi" | |
#r "nuget: Swashbuckle.AspNetCore " | |
open Microsoft.AspNetCore.Builder | |
open Microsoft.Extensions.DependencyInjection | |
open Oxpecker | |
open Oxpecker.OpenApi | |
open Microsoft.Extensions.DependencyInjection | |
open Microsoft.Extensions.Configuration | |
open Swashbuckle.AspNetCore.SwaggerGen | |
open Microsoft.OpenApi.Models | |
open Microsoft.AspNetCore.Http | |
open Microsoft.Extensions.Logging | |
let endpoints = [ | |
GET [ | |
route "/hello" | |
("Hello World!" |> text) | |
|> configureEndpoint _.WithName("Hello") | |
|> addOpenApiSimple<unit, string> | |
route "/hello-json" | |
("""{ "Hello": "World!" }""" |> json) | |
|> configureEndpoint _.WithName("HelloJson") | |
|> addOpenApiSimple<unit, {| Hello: string |}> | |
] | |
] | |
let configure (builder: WebApplicationBuilder) = | |
builder.Services | |
.AddRouting() | |
.AddOxpecker() | |
.AddEndpointsApiExplorer() | |
.AddSwaggerGen() | |
builder.Build() | |
let configureApp (app: WebApplication) = | |
app.UseRouting() | |
.UseOxpecker(endpoints) | |
.UseSwagger() // for generating OpenApi spec | |
.UseSwaggerUI() // for viewing Swagger UI | |
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