dto2ts 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +36 -2
- package/dist/cli.js +10 -1
- package/package.json +19 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here.
|
|
4
|
+
This project follows [Semantic Versioning](https://semver.org/).
|
|
5
|
+
|
|
6
|
+
## [0.1.1] - 2026-07-02
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- Package metadata: `author`, `repository`, `bugs`, `homepage` (shown on the npm page).
|
|
11
|
+
- npm badges and package link in the README.
|
|
12
|
+
- CI workflow that builds the project on every push and pull request.
|
|
13
|
+
|
|
14
|
+
## [0.1.0] - 2026-07-02
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- Initial release.
|
|
19
|
+
- Generate TypeScript models (interfaces & enums) from **OpenAPI/Swagger** (file or URL) or
|
|
20
|
+
**C# source files** (`.cs`).
|
|
21
|
+
- Generate fetch-based CRUD services (`list` / `getById` / `create` / `update` / `patch` / `remove`)
|
|
22
|
+
per resource.
|
|
23
|
+
- Zero-dependency generated `HttpClient` with `ApiError` and injectable headers/fetch.
|
|
24
|
+
- One file per type following the Angular style guide (`.model.ts` / `.enum.ts` / `.service.ts`)
|
|
25
|
+
with barrel `index.ts` files.
|
|
26
|
+
- CLI and programmatic API, configurable via `dto2ts.config.json` or flags.
|
package/README.md
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
# dto2ts
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/dto2ts)
|
|
4
|
+
[](https://www.npmjs.com/package/dto2ts)
|
|
5
|
+
[](https://github.com/serkancakmakk/dto2ts/actions/workflows/ci.yml)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
|
|
3
8
|
Generate **TypeScript models** and **fetch-based CRUD services** from your C# API.
|
|
4
9
|
|
|
10
|
+
📦 **[npmjs.com/package/dto2ts](https://www.npmjs.com/package/dto2ts)**
|
|
11
|
+
|
|
5
12
|
Point it at your ASP.NET Core backend and get a fully typed, ready-to-use client for your
|
|
6
13
|
frontend — no manual DTO copying, no drift between backend and frontend.
|
|
7
14
|
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
## Why dto2ts?
|
|
18
|
+
|
|
19
|
+
There are excellent OpenAPI→TS generators already (NSwag, `openapi-typescript`,
|
|
20
|
+
`swagger-typescript-api`). dto2ts is worth a look when you want two things they don't give you
|
|
21
|
+
out of the box:
|
|
22
|
+
|
|
23
|
+
- **No running API required.** dto2ts can read your `.cs` DTO/record/enum files **directly** —
|
|
24
|
+
so you can generate types before the backend is even started, and enums keep their real member
|
|
25
|
+
names (a common pain point with .NET's default OpenAPI output). Most tools force you through a
|
|
26
|
+
live spec.
|
|
27
|
+
- **Ready-to-use CRUD services, zero runtime deps.** You don't just get `interface`s — you get a
|
|
28
|
+
typed `ProductService` with `list / getById / create / update / patch / remove`, built on the
|
|
29
|
+
built-in `fetch`. Nothing to install, runs in the browser, Node 18+, Angular, React, or Vue.
|
|
30
|
+
|
|
8
31
|
Two input sources are supported:
|
|
9
32
|
|
|
10
33
|
- **OpenAPI / Swagger** — a `swagger.json` file or a live URL (e.g. the spec ASP.NET Core
|
|
@@ -12,8 +35,16 @@ Two input sources are supported:
|
|
|
12
35
|
- **C# source files** (`.cs`) — parses your DTO/record/enum definitions directly, no need to
|
|
13
36
|
run the API first.
|
|
14
37
|
|
|
15
|
-
|
|
16
|
-
|
|
38
|
+
### Finding your Swagger/OpenAPI URL
|
|
39
|
+
|
|
40
|
+
If you use the `openapi` source against a live API, the spec URL depends on your ASP.NET Core
|
|
41
|
+
setup:
|
|
42
|
+
|
|
43
|
+
- **.NET 9+ (built-in OpenAPI)**: `https://localhost:<port>/openapi/v1.json`
|
|
44
|
+
- **Swashbuckle / Swagger UI**: `https://localhost:<port>/swagger/v1/swagger.json`
|
|
45
|
+
|
|
46
|
+
Open the Swagger UI page in your browser and the JSON link is usually at the top. Not sure it's
|
|
47
|
+
reachable? Use the `csharp` source instead and skip the running API entirely.
|
|
17
48
|
|
|
18
49
|
---
|
|
19
50
|
|
|
@@ -48,6 +79,9 @@ npx dto2ts -s openapi -i ./swagger.json -o ./src/api
|
|
|
48
79
|
npx dto2ts -s csharp -i ../Backend/Dtos -o ./src/api
|
|
49
80
|
```
|
|
50
81
|
|
|
82
|
+
> 💡 Want to try it right now? This repo ships sample DTOs under [`examples/csharp`](examples/csharp) —
|
|
83
|
+
> run `npx dto2ts -s csharp -i ./examples/csharp -o ./out` to see exactly what the demo above produces.
|
|
84
|
+
|
|
51
85
|
## What gets generated
|
|
52
86
|
|
|
53
87
|
One file per type, following the Angular style guide (`.model.ts` / `.enum.ts` / `.service.ts`),
|
package/dist/cli.js
CHANGED
|
@@ -8,7 +8,7 @@ const program = new commander_1.Command();
|
|
|
8
8
|
program
|
|
9
9
|
.name("dto2ts")
|
|
10
10
|
.description("C# API (OpenAPI/Swagger veya .cs DTO) kaynaklarından TS model + fetch CRUD service üretir.")
|
|
11
|
-
.version("0.1.
|
|
11
|
+
.version("0.1.1");
|
|
12
12
|
program
|
|
13
13
|
.command("generate", { isDefault: true })
|
|
14
14
|
.description("Model ve service dosyalarını üret")
|
|
@@ -50,6 +50,15 @@ program
|
|
|
50
50
|
console.log(` ${modelCount} model, ${serviceCount} service üretildi:`);
|
|
51
51
|
for (const f of files)
|
|
52
52
|
console.log(` → ${f}`);
|
|
53
|
+
// OpenAPI + .NET'in default enum serileştirmesinde enum'lar üye adı olmadan
|
|
54
|
+
// gelir; bu durumda boş enum üretilir. Kullanıcıyı sessizce bırakmayalım.
|
|
55
|
+
const emptyEnums = api.models.filter((m) => m.kind === "enum" && m.members.length === 0);
|
|
56
|
+
if (emptyEnums.length > 0 && merged.source === "openapi") {
|
|
57
|
+
console.warn("");
|
|
58
|
+
console.warn(`⚠ ${emptyEnums.length} enum üye adı olmadan geldi (${emptyEnums.map((e) => e.name).join(", ")}).`);
|
|
59
|
+
console.warn(" .NET'in default OpenAPI çıktısı enum'ları düz integer olarak yazar.");
|
|
60
|
+
console.warn(" Çözüm: '--source csharp' kullan ya da API'nde JsonStringEnumConverter kaydet.");
|
|
61
|
+
}
|
|
53
62
|
}
|
|
54
63
|
catch (err) {
|
|
55
64
|
console.error(`✖ Hata: ${err instanceof Error ? err.message : String(err)}`);
|
package/package.json
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dto2ts",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "C# API (OpenAPI/Swagger
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Generate TypeScript models & fetch-based CRUD services from your C# API (OpenAPI/Swagger or .cs source).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"csharp",
|
|
7
7
|
"dotnet",
|
|
8
|
+
"aspnetcore",
|
|
8
9
|
"openapi",
|
|
9
10
|
"swagger",
|
|
10
11
|
"codegen",
|
|
12
|
+
"code-generation",
|
|
11
13
|
"typescript",
|
|
12
14
|
"dto",
|
|
13
15
|
"crud",
|
|
14
|
-
"fetch"
|
|
16
|
+
"fetch",
|
|
17
|
+
"angular",
|
|
18
|
+
"api-client"
|
|
15
19
|
],
|
|
20
|
+
"author": "Serkan Çakmak",
|
|
16
21
|
"license": "MIT",
|
|
22
|
+
"homepage": "https://github.com/serkancakmakk/dto2ts#readme",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/serkancakmakk/dto2ts.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/serkancakmakk/dto2ts/issues"
|
|
29
|
+
},
|
|
17
30
|
"type": "commonjs",
|
|
18
31
|
"main": "./dist/index.js",
|
|
19
32
|
"types": "./dist/index.d.ts",
|
|
@@ -22,7 +35,9 @@
|
|
|
22
35
|
},
|
|
23
36
|
"files": [
|
|
24
37
|
"dist",
|
|
25
|
-
"README.md"
|
|
38
|
+
"README.md",
|
|
39
|
+
"CHANGELOG.md",
|
|
40
|
+
"LICENSE"
|
|
26
41
|
],
|
|
27
42
|
"scripts": {
|
|
28
43
|
"build": "tsc -p tsconfig.json",
|