Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ fsharp_space_before_member = true
fsharp_space_before_parameter = true
fsharp_space_before_uppercase_invocation = false
max_line_length = 100

2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# the shebang is ignored, but nice for editors
watch_file npins/sources.json
watch_file nix/sources.json

# Load .env file if it exists
dotenv_if_exists
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.ionide
.idea
*.user
.env
.vscode
.direnv
.DS_Store
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
Notable changes are recorded here.

# Giraffe.OpenApi 0.1.0

## Breaking Changes

- Upgrade to .NET 10.0
- Update Microsoft.AspNetCore.OpenApi from 8.0.20 to 10.0.0 (not backwards compatible)

## Updates

- Update Giraffe from 8.0.0-alpha-003 to 8.2.0
- Update FSharp.SystemTextJson from 1.3.13 to 1.4.36

# Giraffe.OpenApi 0.0.3

## Updates
Expand Down
13 changes: 6 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
<ItemGroup>
<!-- Common -->
<PackageVersion Include="Giraffe" Version="8.2.0" />
<PackageVersion Include="Ionide.KeepAChangelog.Tasks" Version="0.2.0" />
<PackageVersion Include="FSharp.Core" Version="9.0.100" />
<PackageVersion Include="Ionide.KeepAChangelog.Tasks" Version="0.3.1" />
<PackageVersion Include="FSharp.Core" Version="10.0.100" />
<!-- Giraffe.OpenApi -->
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerGen" Version="9.0.6" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
<!-- Sample App -->
<PackageVersion Include="Swashbuckle.AspNetCore" Version="9.0.6" />
<PackageVersion Include="Scalar.AspNetCore" Version="2.0.0" />
<PackageVersion Include="FSharp.SystemTextJson" Version="1.4.36" />
<!-- Analyzers -->
<PackageVersion Include="FSharp.Analyzers.Build" Version="0.5.0" />
<PackageVersion Include="G-Research.FSharp.Analyzers" Version="0.18.0" />
<PackageVersion Include="G-Research.FSharp.Analyzers" Version="0.20.0" />
<PackageVersion Include="Ionide.Analyzers" Version="0.14.10" />
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion Directory.Solution.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<ItemGroup>
<ProjectsToAnalyze Include="src/Giraffe.OpenApi/Giraffe.OpenApi.fsproj" Exclude="sample-project/SampleApp.fsproj" />
<ProjectsToAnalyze Include="src/Giraffe.OpenApi/Giraffe.OpenApi.fsproj" Exclude="example/SampleApp.fsproj" />
</ItemGroup>

<Target Name="AnalyzeSolution">
Expand Down
2 changes: 1 addition & 1 deletion Giraffe.OpenApi.slnx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Solution>
<Project Path="sample-project/SampleApp.fsproj" />
<Project Path="example/SampleApp.fsproj" />
<Project Path="src/Giraffe.OpenApi/Giraffe.OpenApi.fsproj" />
</Solution>
39 changes: 29 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ An extension for the [Giraffe](https://github.com/giraffe-fsharp/Giraffe) Web Ap
[![NuGet Info](https://buildstats.info/nuget/Giraffe.OpenApi?includePreReleases=true)](https://www.nuget.org/packages/Giraffe.OpenApi/)


## Table of Contents
## Table of Contents

- [Giraffe.OpenApi](#giraffeopenapi)
- [Table of Contents](#table-of-contents)
Expand Down Expand Up @@ -70,27 +70,46 @@ let endpoints = [

### Integration

Since `Giraffe.OpenApi` works on top of `Microsoft.AspNetCore.OpenApi` and `Swashbuckle.AspNetCore` packages, you need to do [standard steps](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/openapi):
Since `Giraffe.OpenApi` works on top of `Microsoft.AspNetCore.OpenApi` and `Scalar.AspNetCore` packages, you need to do [standard steps](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/openapi):

```fsharp
let configureApp (appBuilder: IApplicationBuilder) =
appBuilder
.UseRouting()
.UseSwagger() // For generating OpenApi spec
.UseSwaggerUI() // For viewing Swagger UI
.UseGiraffe(endpoints)
.UseGiraffe(notFoundHandler)

let configureServices (services: IServiceCollection) =
services
.AddRouting()
.AddGiraffe()
.AddEndpointsApiExplorer() // Use the API Explorer to discover and describe endpoints
.AddSwaggerGen() // Swagger dependencies
.AddOpenApi("v1", fun options ->
// Register F# transformers
options.AddSchemaTransformer<FSharpOptionSchemaTransformer>() |> ignore
options.AddSchemaTransformer<DiscriminatedUnionSchemaTransformer>() |> ignore
)
|> ignore

[<EntryPoint>]
let main args =
let builder = WebApplication.CreateBuilder(args)
configureServices builder.Services

let app = builder.Build()

// Map OpenAPI endpoint
app.MapOpenApi() |> ignore

configureApp app

// Map Scalar API reference
app.MapScalarApiReference() |> ignore

app.Run()
0
```

To make endpoints discoverable by Swagger, you need to call one of the following functions: `addOpenApi` or `addOpenApiSimple` on the endpoint.
To make endpoints discover able by Scalar, 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._

Expand All @@ -101,13 +120,13 @@ This method is used to add OpenApi metadata to the endpoint. It accepts `OpenApi
```fsharp
type OpenApiConfig (?requestBody : RequestBody,
?responseBodies : ResponseBody seq,
?configureOperation : OpenApiOperation -> OpenApiOperation) =
?configureOperation : OpenApiOperation -> OpenApiOperationTransformerContext -> CancellationToken -> Task) =
// ...
```

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.
`configureOperation` parameter is a function that allows you to do very low-level modifications the `OpenApiOperation` object using the new transformer pattern.

### addOpenApiSimple

Expand All @@ -122,7 +141,7 @@ let addOpenApiSimple<'Req, 'Res> = ...
- **Request Type (`'Req`)**:
- If `'Req` is `unit`, the endpoint is treated as not requiring a request body (e.g., for GET endpoints).
- If `'Req` is a tuple or a primitive type (e.g., `int`, `string`), the endpoint is treated as not requiring a request body. These are typically used for path or query parameters, and the parameters are inferred from the route template.
- If `'Req` is a any other complex type (e.g., record or class types), the endpoint is treated as requiring a request body. The schema is inferred from the type's fields.
- If `'Req` is any other complex type (e.g., record, or class types), the endpoint is treated as requiring a request body. The schema is inferred from the type's fields.
- **Response Type (`'Res`)**:
- The response schema is always inferred from the type provided as `'Res`.
- If `'Res` is `unit`, the endpoint is treated as not returning a response body.
Expand Down
4 changes: 2 additions & 2 deletions build.fsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#r "nuget: Fun.Build, 1.0.4"
#r "nuget: Fake.IO.FileSystem, 6.0.0"
#r "nuget: Fun.Build, 1.1.17"
#r "nuget: Fake.IO.FileSystem, 6.1.4"

open System
open System.IO
Expand Down
46 changes: 28 additions & 18 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,45 @@
}:
let
pname = "Giraffe.OpenApi";
dotnet-sdk = pkgs.dotnetCorePackages.sdk_9_0;
dotnet-runtime = pkgs.dotnetCorePackages.aspnetcore_9_0;
version = "0.0.3";
dotnet-sdk = pkgs.dotnetCorePackages.sdk_10_0;
dotnet-runtime = pkgs.dotnetCorePackages.aspnetcore_10_0;
version = "0.1.0";
fsharp-analyzers = pkgs.buildDotnetGlobalTool {
pname = "fsharp-analyzers";
version = "0.34.1 ";
nugetHash = "sha256-Y6PzfVGob2EgX29ZhZIde5EhiZ28Y1+U2pJ6ybIsHV0=";
};
in
{
default = pkgs.callPackage ./nix/package.nix {
inherit
pname
version
dotnet-sdk
dotnet-runtime
;
};
example = pkgs.callPackage ./nix/example.nix {
inherit
version
dotnet-sdk
dotnet-runtime
;
};

shell = pkgs.mkShellNoCC {
buildInputs = [
dotnet-sdk
];

packages = [
pkgs.npins
fsharp-analyzers
pkgs.fantomas
pkgs.fsautocomplete
];

DOTNET_ROOT = "${dotnet-sdk.unwrapped}/share/dotnet";
DOTNET_CLI_TELEMETRY_OPTOUT = "true";
DOTNET_ROOT = "${dotnet-sdk}/share/dotnet";
NPINS_DIRECTORY = "nix";
};
in
{
inherit shell;

default = pkgs.callPackage ./nix/package.nix {
inherit
pname
version
dotnet-sdk
dotnet-runtime
pkgs
;
};
}
12 changes: 6 additions & 6 deletions .config/dotnet-tools.json → dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"version": 1,
"isRoot": true,
"tools": {
"fsharp-analyzers": {
"version": "0.34.1",
"fantomas": {
"version": "7.0.5",
"commands": [
"fsharp-analyzers"
"fantomas"
],
"rollForward": false
},
"fantomas": {
"version": "7.0.5",
"fsharp-analyzers": {
"version": "0.34.1",
"commands": [
"fantomas"
"fsharp-analyzers"
],
"rollForward": false
}
Expand Down
Loading