Oxpecker.OpenApi 0.1.1

dotnet add package Oxpecker.OpenApi --version 0.1.1                
NuGet\Install-Package Oxpecker.OpenApi -Version 0.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Oxpecker.OpenApi" Version="0.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Oxpecker.OpenApi --version 0.1.1                
#r "nuget: Oxpecker.OpenApi, 0.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Oxpecker.OpenApi as a Cake Addin
#addin nuget:?package=Oxpecker.OpenApi&version=0.1.1

// Install Oxpecker.OpenApi as a Cake Tool
#tool nuget:?package=Oxpecker.OpenApi&version=0.1.1                

Oxpecker.OpenApi

Oxpecker.OpenApi extends Oxpecker framework with functionality to automatically generate OpenApi spec from code.

Nuget package

Two usages:

open Oxpecker
open Oxpecker.OpenApi

let endpoints = [
    // addOpenApi supports passing detailed configuration
    POST [
        route "/product" (text "Product posted!")
            |> addOpenApi (OpenApiConfig(
                requestBody = RequestBody(typeof<Product>),
                responseBodies = [| ResponseBody(typeof<string>) |],
                configureOperation = (fun o -> o.OperationId <- "PostProduct"; o)
            ))
    ]
    // addOpenApiSimple is a shortcut for simple cases
    GET [
        routef "/product/{%i}" (
            fun id ->
                forecases
                |> Array.find (fun f -> f.Id = num)
                |> json
        )
            |> configureEndpoint _.WithName("GetProduct")
            |> addOpenApiSimple<int, Product>
    ]
]

Documentation:

Integration

Since Oxpecker.OpenApi works on top of Microsoft.AspNetCore.OpenApi and Swashbuckle.AspNetCore packages, you need to do standard steps:


let configureApp (appBuilder: IApplicationBuilder) =
    appBuilder
        .UseRouting()
        .Use(errorHandler)
        .UseOxpecker(endpoints)
        .UseSwagger() // for generating OpenApi spec
        .UseSwaggerUI() // for viewing Swagger UI
        .Run(notFoundHandler)

let configureServices (services: IServiceCollection) =
    services
        .AddRouting()
        .AddOxpecker()
        .AddEndpointsApiExplorer() // use the API Explorer to discover and describe endpoints
        .AddSwaggerGen() // swagger dependencies
    |> ignore

To make endpoints discoverable by Swagger, you need to call one of the following functions: addOpenApi or addOpenApiSimple on the endpoint.

NOTE: you don't have to describe routing parameters when using those functions, they will be inferred from the route template automatically.

addOpenApi

This method is used to add OpenApi metadata to the endpoint. It accepts OpenApiConfig object with the following optional parameters:

type OpenApiConfig (?requestBody : RequestBody,
                    ?responseBodies : ResponseBody seq,
                    ?configureOperation : OpenApiOperation -> OpenApiOperation) =
    // ...

Response body schema will be inferred from the types passed to requestBody and responseBodies parameters. Each ResponseBody object in sequence must have different status code. configureOperation parameter is a function that allows you to do very low-level modifications the OpenApiOperation object.

addOpenApiSimple

This method is a shortcut for simple cases. It accepts two generic type parameters - request and response, so the schema can be inferred from them.

let addOpenApiSimple<'Req, 'Res> = ...

If your handler doesn't accept any input, you can pass unit as a request type (works for response as well).

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.1 1,655 4/29/2024
0.1.0 292 3/23/2024

Added logo