Created
August 30, 2025 11:31
-
-
Save alexeyfv/4e0fd2da3129b722ced5a8f180d2e76a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # OpenAPI Synchronization Script: ASP.NET Web API + Svelte + TypeScript | |
| # This script shows how to automate sync between C# backend and TypeScript frontend. | |
| # Keywords: openapi, swagger, asp.net, typescript, svelte, api client, codegen, automation | |
| # --- Backend setup (ASP.NET Core Web API) --- | |
| # 1. Create a new ASP.NET Core Web API project for backend. | |
| mkdir -p backend | |
| cd backend | |
| dotnet new webapi | |
| # 2. Add or update Swashbuckle.AspNetCore package for OpenAPI/Swagger support. | |
| # The version must match the CLI tool version for consistency. | |
| dotnet add package Swashbuckle.AspNetCore --version 9.0.4 | |
| # 3. Install Swashbuckle.AspNetCore.Cli as a local dotnet tool for OpenAPI spec generation. | |
| dotnet new tool-manifest | |
| dotnet tool install Swashbuckle.AspNetCore.Cli --version 9.0.4 | |
| # 4. Build the backend project and generate the OpenAPI YAML specification. | |
| dotnet build | |
| dotnet swagger tofile \ | |
| --output openapi.yaml \ | |
| --yaml \ | |
| bin/Debug/net8.0/backend.dll \ | |
| v1 | |
| # --- Frontend setup (Svelte + TypeScript) --- | |
| # 5. Create a new Svelte frontend project with TypeScript template. | |
| cd .. | |
| pnpx sv create \ | |
| --template minimal \ | |
| --types ts \ | |
| --install pnpm \ | |
| --no-add-ons \ | |
| ./frontend | |
| # 6. Generate a TypeScript API client and types from the OpenAPI YAML spec. | |
| pnpx swagger-typescript-api generate \ | |
| --path ./backend/openapi.yaml \ | |
| -o ./frontend/src/generated \ | |
| -n WebApi.ts | |
| # End of script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment