-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-api-simple.ps1
More file actions
78 lines (72 loc) · 2.36 KB
/
Copy pathgenerate-api-simple.ps1
File metadata and controls
78 lines (72 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Simple PowerShell script to generate TypeScript API client
Write-Host "🚀 Generating TypeScript API client..." -ForegroundColor Green
# Generate TypeScript client using local swagger file
Write-Host "🔧 Generating TypeScript client from local swagger..." -ForegroundColor Yellow
# Create a simple nswag config for local generation
$nswagConfig = @"
{
"`$schema": "http://json.schemastore.org/nswag",
"runtime": "Net80",
"defaultVariables": null,
"documentGenerator": {
"fromDocument": {
"json": "",
"url": "http://localhost:5000/swagger/v1/swagger.json"
}
},
"codeGenerators": {
"openApiToTypeScriptClient": {
"className": "ApiClient",
"moduleName": "",
"namespace": "",
"typeScriptVersion": 4.3,
"template": "Angular",
"promiseType": "Promise",
"httpClass": "HttpClient",
"useSingletonProvider": true,
"injectionTokenType": "InjectionToken",
"rxJsVersion": 7.0,
"dateTimeType": "Date",
"nullValue": "Undefined",
"generateClientClasses": true,
"generateClientInterfaces": true,
"generateOptionalParameters": false,
"exportTypes": true,
"wrapDtoExceptions": true,
"exceptionClass": "ApiException",
"clientClassVisibility": "public",
"typeStyle": "Class",
"classTypes": [],
"extendedClasses": [],
"extensionCode": "",
"generateDefaultValues": true,
"generateTypeCheckFunctions": false,
"enumNameGenerationMode": "Auto",
"enumValueGenerationMode": "Auto",
"serviceHost": "",
"serviceSchemes": [],
"output": "TodoApp.Web/src/api/generated/api-client.ts",
"newLineBehavior": "Auto"
}
}
}
"@
# Write config to temp file
$tempConfig = "nswag-temp.json"
$nswagConfig | Out-File -FilePath $tempConfig -Encoding UTF8
try {
# Generate TypeScript client
nswag run $tempConfig
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ TypeScript API client generated successfully!" -ForegroundColor Green
Write-Host "📁 Output: TodoApp.Web/src/api/generated/api-client.ts" -ForegroundColor Cyan
} else {
Write-Host "❌ Failed to generate TypeScript client" -ForegroundColor Red
}
} finally {
# Clean up temp file
if (Test-Path $tempConfig) {
Remove-Item $tempConfig
}
}
Write-Host "🎉 Generation process completed!" -ForegroundColor Green