Skip to content

Commit 8b8ef1c

Browse files
committed
feat: Migrate API client generation from NSwag to Refitter, introducing granular endpoint interfaces, new DTOs, and updated client registration with Polly policies.
1 parent 396a414 commit 8b8ef1c

61 files changed

Lines changed: 2043 additions & 201 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.refitter

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"openApiPath": "openapi.json",
3+
"namespace": "BookStore.Client",
4+
"naming": {
5+
"useOpenApiTitle": false,
6+
"interfaceName": "I{controller}Endpoint"
7+
},
8+
"multipleInterfaces": "ByEndpoint",
9+
"generateContracts": true,
10+
"generateXmlDocCodeComments": false,
11+
"generateStatusCodeComments": true,
12+
"typeAccessibility": "public",
13+
"useCancellationTokens": true,
14+
"useIsoDateFormat": false,
15+
"outputFolder": "src/Client/BookStore.Client",
16+
"outputFilename": "IBookStoreApiClient.g.cs",
17+
"contractsOutputFolder": "src/Client/BookStore.Client",
18+
"contractsOutputFilename": "Contracts.g.cs",
19+
"additionalNamespaces": [
20+
"BookStore.Shared.Models"
21+
],
22+
"returnIApiResponse": false,
23+
"generateOperationHeaders": true,
24+
"typeAccessibilityForContracts": "public",
25+
"codeGeneratorSettings": {
26+
"excludedTypeNames": [
27+
"PartialDate"
28+
]
29+
}
30+
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ BookStore/
173173
- **TUnit** - Modern testing framework with built-in code coverage
174174
- **Roslyn Analyzers** - Custom analyzers for Event Sourcing/CQRS patterns
175175
- **Roslynator.Analyzers 4.15.0** - Enhanced code analysis
176+
- **Refit** - Type-safe REST library for .NET
177+
- **Refitter** - Tool to generate Refit interfaces from OpenAPI specifications
176178
- **NSwag** - OpenAPI client generation (optional development tool)
177179

178180
## 📊 API Endpoints

_tools/generate-client-nswag.sh

Lines changed: 0 additions & 44 deletions
This file was deleted.

_tools/generate-client.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# Generate API client using Refitter (Refit interfaces + DTOs)
3+
# Generates clean Refit interfaces from OpenAPI spec
4+
5+
set -e
6+
7+
echo "🔄 Generating API client with Refitter..."
8+
echo ""
9+
10+
# Check if openapi.json exists
11+
if [ ! -f "openapi.json" ]; then
12+
echo "❌ openapi.json not found"
13+
echo ""
14+
echo "Run ./_tools/update-openapi.sh first to download the spec"
15+
exit 1
16+
fi
17+
18+
# Generate Refit client with DTOs
19+
echo "📝 Generating Refit interfaces + DTOs..."
20+
refitter --settings-file .refitter --skip-validation
21+
22+
if [ $? -eq 0 ]; then
23+
echo ""
24+
echo "✅ Client generated successfully!"
25+
echo ""
26+
echo "📝 Generated files:"
27+
echo " - 28 Refit interface files (I*Endpoint.cs)"
28+
echo " - 1 Contracts file (Contracts.cs with all DTOs)"
29+
echo ""
30+
echo "📝 Next steps:"
31+
echo " 1. Review generated files: src/Client/BookStore.Client/"
32+
echo " 2. Build project: dotnet build"
33+
echo " 3. Commit changes: git add openapi.json src/Client/BookStore.Client/"
34+
echo " 4. Commit message: git commit -m 'Update API client from OpenAPI spec'"
35+
echo ""
36+
else
37+
echo ""
38+
echo "❌ Client generation failed"
39+
exit 1
40+
fi

0 commit comments

Comments
 (0)