Skip to content

Commit 8a08794

Browse files
committed
Add initial implementation of TypeScript client generator from OpenAPI specification
- Create project structure with necessary files and configurations - Implement TypeScriptGenerator class for generating TypeScript clients - Add OpenAPI model classes for parsing OpenAPI specifications - Set up CI/CD workflow for building, testing, and publishing the tool - Include sample OpenAPI specification for testing
0 parents  commit 8a08794

16 files changed

Lines changed: 755 additions & 0 deletions

.config/dotnet-tools.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"gitversion.tool": {
6+
"version": "6.5.1",
7+
"commands": [
8+
"dotnet-gitversion"
9+
],
10+
"rollForward": false
11+
}
12+
}
13+
}

.github/workflows/ci-cd.yml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
release:
9+
types: [ published ]
10+
11+
env:
12+
DOTNET_VERSION: '10.0.x'
13+
PROJECT_PATH: 'TypescriptClientGenerator/TypescriptClientGenerator.csproj'
14+
15+
jobs:
16+
build-and-test:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Setup .NET
24+
uses: actions/setup-dotnet@v4
25+
with:
26+
dotnet-version: ${{ env.DOTNET_VERSION }}
27+
28+
- name: Restore dependencies
29+
run: dotnet restore ${{ env.PROJECT_PATH }}
30+
31+
- name: Build
32+
run: dotnet build ${{ env.PROJECT_PATH }} --no-restore --configuration Release
33+
34+
- name: Test tool with sample OpenAPI spec
35+
run: |
36+
dotnet run --project ${{ env.PROJECT_PATH }} -- --input tests/sample-openapi.json --output TestClient.ts
37+
38+
- name: Verify generated client
39+
run: |
40+
if [ ! -f "TestClient.ts" ]; then
41+
echo "Generated client file not found!"
42+
exit 1
43+
fi
44+
echo "Generated client file found and verified"
45+
46+
- name: Pack
47+
run: dotnet pack ${{ env.PROJECT_PATH }} --no-build --configuration Release
48+
49+
- name: Upload build artifacts
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: nuget-package
53+
path: TypescriptClientGenerator/bin/Release/*.nupkg
54+
55+
publish:
56+
needs: build-and-test
57+
runs-on: ubuntu-latest
58+
# Only publish on pushes to main branch, not on PRs or other branches
59+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
60+
61+
steps:
62+
- name: Checkout code
63+
uses: actions/checkout@v4
64+
with:
65+
fetch-depth: 0
66+
67+
- name: Install GitVersion
68+
uses: gittools/actions/gitversion/setup@v0.10.2
69+
with:
70+
versionSpec: '6.x'
71+
72+
- name: Determine Version
73+
id: gitversion
74+
uses: gittools/actions/gitversion/execute@v0.10.2
75+
76+
- name: Setup .NET
77+
uses: actions/setup-dotnet@v4
78+
with:
79+
dotnet-version: ${{ env.DOTNET_VERSION }}
80+
81+
- name: Restore dependencies
82+
run: dotnet restore ${{ env.PROJECT_PATH }}
83+
84+
- name: Build
85+
run: dotnet build ${{ env.PROJECT_PATH }} --no-restore --configuration Release -p:Version=${{ steps.gitversion.outputs.semVer }}
86+
87+
- name: Pack
88+
run: dotnet pack ${{ env.PROJECT_PATH }} --no-build --configuration Release -p:PackageVersion=${{ steps.gitversion.outputs.semVer }}
89+
90+
- name: Publish to NuGet
91+
run: dotnet nuget push TypescriptClientGenerator/bin/Release/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
92+
93+
- name: Upload release artifacts
94+
uses: actions/upload-artifact@v4
95+
with:
96+
name: release-package
97+
path: TypescriptClientGenerator/bin/Release/*.nupkg
98+
99+
verify-package:
100+
needs: build-and-test
101+
runs-on: ubuntu-latest
102+
if: github.event_name != 'release'
103+
104+
steps:
105+
- name: Checkout code
106+
uses: actions/checkout@v4
107+
108+
- name: Setup .NET
109+
uses: actions/setup-dotnet@v4
110+
with:
111+
dotnet-version: ${{ env.DOTNET_VERSION }}
112+
113+
- name: Download build artifacts
114+
uses: actions/download-artifact@v4
115+
with:
116+
name: nuget-package
117+
path: ./artifacts
118+
119+
- name: Install tool from local package
120+
run: |
121+
PACKAGE_PATH=$(find ./artifacts -name "*.nupkg" | head -1)
122+
dotnet tool install --global --add-source ./artifacts TypescriptClientGenerator
123+
124+
- name: Test installed tool
125+
run: |
126+
typescript-client-generator --input tests/sample-openapi.json --output VerifyClient.ts
127+
128+
- name: Verify tool output
129+
run: |
130+
if [ ! -f "VerifyClient.ts" ]; then
131+
echo "Tool verification failed - no output generated!"
132+
exit 1
133+
fi
134+
echo "Tool verification successful!"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bin
2+
obj
3+
.idea

TypescriptClientGenerator.sln

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypescriptClientGenerator", "TypescriptClientGenerator\TypescriptClientGenerator.csproj", "{E573024D-850E-4B27-85A3-D5973986362D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Debug|x64 = Debug|x64
12+
Debug|x86 = Debug|x86
13+
Release|Any CPU = Release|Any CPU
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{E573024D-850E-4B27-85A3-D5973986362D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{E573024D-850E-4B27-85A3-D5973986362D}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{E573024D-850E-4B27-85A3-D5973986362D}.Debug|x64.ActiveCfg = Debug|Any CPU
21+
{E573024D-850E-4B27-85A3-D5973986362D}.Debug|x64.Build.0 = Debug|Any CPU
22+
{E573024D-850E-4B27-85A3-D5973986362D}.Debug|x86.ActiveCfg = Debug|Any CPU
23+
{E573024D-850E-4B27-85A3-D5973986362D}.Debug|x86.Build.0 = Debug|Any CPU
24+
{E573024D-850E-4B27-85A3-D5973986362D}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{E573024D-850E-4B27-85A3-D5973986362D}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{E573024D-850E-4B27-85A3-D5973986362D}.Release|x64.ActiveCfg = Release|Any CPU
27+
{E573024D-850E-4B27-85A3-D5973986362D}.Release|x64.Build.0 = Release|Any CPU
28+
{E573024D-850E-4B27-85A3-D5973986362D}.Release|x86.ActiveCfg = Release|Any CPU
29+
{E573024D-850E-4B27-85A3-D5973986362D}.Release|x86.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
EndGlobal

0 commit comments

Comments
 (0)