Skip to content

Commit 3462bfa

Browse files
author
Moritz Jörg
committed
feat: Updates for .NET 10 changes
1 parent 7e32b52 commit 3462bfa

26 files changed

+758
-349
lines changed

.editorconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,3 @@ fsharp_space_before_member = true
3838
fsharp_space_before_parameter = true
3939
fsharp_space_before_uppercase_invocation = false
4040
max_line_length = 100
41-

.envrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
# the shebang is ignored, but nice for editors
3-
watch_file npins/sources.json
3+
watch_file nix/sources.json
44

55
# Load .env file if it exists
66
dotenv_if_exists

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
.ionide
66
.idea
77
*.user
8+
.env
89
.vscode
910
.direnv
1011
.DS_Store

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
Notable changes are recorded here.
22

3+
# Giraffe.OpenApi 0.1.0
4+
5+
## Breaking Changes
6+
7+
- Upgrade to .NET 10.0
8+
- Update Microsoft.AspNetCore.OpenApi from 8.0.20 to 10.0.0 (not backwards compatible)
9+
10+
## Updates
11+
12+
- Update Giraffe from 8.0.0-alpha-003 to 8.2.0
13+
- Update FSharp.SystemTextJson from 1.3.13 to 1.4.36
14+
- Update Swashbuckle.AspNetCore from 9.0.4 to 9.0.6
15+
- Update GitHub Actions workflow to use actions/checkout v6
16+
317
# Giraffe.OpenApi 0.0.3
418

519
## Updates

Directory.Packages.props

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
<ItemGroup>
66
<!-- Common -->
77
<PackageVersion Include="Giraffe" Version="8.2.0" />
8-
<PackageVersion Include="Ionide.KeepAChangelog.Tasks" Version="0.2.0" />
9-
<PackageVersion Include="FSharp.Core" Version="9.0.100" />
8+
<PackageVersion Include="Ionide.KeepAChangelog.Tasks" Version="0.3.1" />
9+
<PackageVersion Include="FSharp.Core" Version="10.0.100" />
1010
<!-- Giraffe.OpenApi -->
1111
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
12-
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
13-
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerGen" Version="9.0.6" />
12+
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
1413
<!-- Sample App -->
15-
<PackageVersion Include="Swashbuckle.AspNetCore" Version="9.0.6" />
14+
<PackageVersion Include="Scalar.AspNetCore" Version="2.0.0" />
1615
<PackageVersion Include="FSharp.SystemTextJson" Version="1.4.36" />
1716
<!-- Analyzers -->
1817
<PackageVersion Include="FSharp.Analyzers.Build" Version="0.5.0" />
19-
<PackageVersion Include="G-Research.FSharp.Analyzers" Version="0.18.0" />
18+
<PackageVersion Include="G-Research.FSharp.Analyzers" Version="0.20.0" />
2019
<PackageVersion Include="Ionide.Analyzers" Version="0.14.10" />
2120
</ItemGroup>
22-
</Project>
21+
</Project>

Directory.Solution.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<ItemGroup>
3-
<ProjectsToAnalyze Include="src/Giraffe.OpenApi/Giraffe.OpenApi.fsproj" Exclude="sample-project/SampleApp.fsproj" />
3+
<ProjectsToAnalyze Include="src/Giraffe.OpenApi/Giraffe.OpenApi.fsproj" Exclude="example/SampleApp.fsproj" />
44
</ItemGroup>
55

66
<Target Name="AnalyzeSolution">

Giraffe.OpenApi.slnx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<Solution>
2-
<Project Path="sample-project/SampleApp.fsproj" />
2+
<Project Path="example/SampleApp.fsproj" />
33
<Project Path="src/Giraffe.OpenApi/Giraffe.OpenApi.fsproj" />
44
</Solution>

README.md

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,67 @@ let endpoints = [
7070

7171
### Integration
7272

73-
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):
73+
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):
7474

7575
```fsharp
7676
let configureApp (appBuilder: IApplicationBuilder) =
7777
appBuilder
7878
.UseRouting()
79-
.UseSwagger() // For generating OpenApi spec
80-
.UseSwaggerUI() // For viewing Swagger UI
8179
.UseGiraffe(endpoints)
8280
.UseGiraffe(notFoundHandler)
8381
8482
let configureServices (services: IServiceCollection) =
8583
services
8684
.AddRouting()
8785
.AddGiraffe()
88-
.AddEndpointsApiExplorer() // Use the API Explorer to discover and describe endpoints
89-
.AddSwaggerGen() // Swagger dependencies
86+
.AddOpenApi("v1", fun options ->
87+
// Configure OpenAPI document metadata
88+
options.AddDocumentTransformer(fun document context ct ->
89+
document.Info <- Microsoft.OpenApi.Models.OpenApiInfo(
90+
Title = "My API",
91+
Version = "v1.0.0",
92+
Description = "API documentation",
93+
Contact = Microsoft.OpenApi.Models.OpenApiContact(
94+
Name = "API Support",
95+
96+
)
97+
)
98+
Task.CompletedTask
99+
)
100+
101+
// Register F# transformers
102+
options.AddSchemaTransformer<FSharpOptionSchemaTransformer>() |> ignore
103+
options.AddSchemaTransformer<DiscriminatedUnionSchemaTransformer>() |> ignore
104+
)
90105
|> ignore
106+
107+
[<EntryPoint>]
108+
let main args =
109+
let builder = WebApplication.CreateBuilder(args)
110+
configureServices builder.Services
111+
112+
let app = builder.Build()
113+
114+
// Map OpenAPI endpoint
115+
app.MapOpenApi() |> ignore
116+
117+
configureApp app
118+
119+
// Map Scalar API Reference UI with configuration
120+
app.MapScalarApiReference(fun options ->
121+
options
122+
.WithTitle("My API Documentation")
123+
.WithTheme(Scalar.AspNetCore.ScalarTheme.Purple)
124+
.WithDefaultHttpClient(Scalar.AspNetCore.ScalarTarget.CSharp, Scalar.AspNetCore.ScalarClient.HttpClient)
125+
.WithDarkMode(true)
126+
.WithSidebar(true)
127+
) |> ignore
128+
129+
app.Run()
130+
0
91131
```
92132

93-
To make endpoints discoverable by Swagger, you need to call one of the following functions: `addOpenApi` or `addOpenApiSimple` on the endpoint.
133+
To make endpoints discoverable by Scalar, you need to call one of the following functions: `addOpenApi` or `addOpenApiSimple` on the endpoint.
94134

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

@@ -101,13 +141,13 @@ This method is used to add OpenApi metadata to the endpoint. It accepts `OpenApi
101141
```fsharp
102142
type OpenApiConfig (?requestBody : RequestBody,
103143
?responseBodies : ResponseBody seq,
104-
?configureOperation : OpenApiOperation -> OpenApiOperation) =
144+
?configureOperation : OpenApiOperation -> OpenApiOperationTransformerContext -> CancellationToken -> Task) =
105145
// ...
106146
```
107147

108148
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.
109149

110-
`configureOperation` parameter is a function that allows you to do very low-level modifications the `OpenApiOperation` object.
150+
`configureOperation` parameter is a function that allows you to do very low-level modifications the `OpenApiOperation` object using the new transformer pattern.
111151

112152
### addOpenApiSimple
113153

build.fsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#r "nuget: Fun.Build, 1.0.4"
2-
#r "nuget: Fake.IO.FileSystem, 6.0.0"
1+
#r "nuget: Fun.Build, 1.1.17"
2+
#r "nuget: Fake.IO.FileSystem, 6.1.4"
33

44
open System
55
open System.IO

default.nix

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,45 @@
44
}:
55
let
66
pname = "Giraffe.OpenApi";
7-
dotnet-sdk = pkgs.dotnetCorePackages.sdk_9_0;
8-
dotnet-runtime = pkgs.dotnetCorePackages.aspnetcore_9_0;
9-
version = "0.0.3";
7+
dotnet-sdk = pkgs.dotnetCorePackages.sdk_10_0;
8+
dotnet-runtime = pkgs.dotnetCorePackages.aspnetcore_10_0;
9+
version = "0.1.0";
10+
fsharp-analyzers = pkgs.buildDotnetGlobalTool {
11+
pname = "fsharp-analyzers";
12+
version = "0.34.1 ";
13+
nugetHash = "sha256-Y6PzfVGob2EgX29ZhZIde5EhiZ28Y1+U2pJ6ybIsHV0=";
14+
};
15+
in
16+
{
17+
default = pkgs.callPackage ./nix/package.nix {
18+
inherit
19+
pname
20+
version
21+
dotnet-sdk
22+
dotnet-runtime
23+
;
24+
};
25+
example = pkgs.callPackage ./nix/example.nix {
26+
inherit
27+
version
28+
dotnet-sdk
29+
dotnet-runtime
30+
;
31+
};
32+
1033
shell = pkgs.mkShellNoCC {
1134
buildInputs = [
1235
dotnet-sdk
1336
];
1437

1538
packages = [
1639
pkgs.npins
40+
fsharp-analyzers
1741
pkgs.fantomas
1842
pkgs.fsautocomplete
1943
];
2044

21-
DOTNET_ROOT = "${dotnet-sdk.unwrapped}/share/dotnet";
22-
DOTNET_CLI_TELEMETRY_OPTOUT = "true";
45+
DOTNET_ROOT = "${dotnet-sdk}/share/dotnet";
2346
NPINS_DIRECTORY = "nix";
2447
};
25-
in
26-
{
27-
inherit shell;
28-
29-
default = pkgs.callPackage ./nix/package.nix {
30-
inherit
31-
pname
32-
version
33-
dotnet-sdk
34-
dotnet-runtime
35-
pkgs
36-
;
37-
};
3848
}

0 commit comments

Comments
 (0)