typedapi-client-helpers 0.2.0 → 0.3.0
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 +68 -0
- package/LICENSE +21 -0
- package/README.md +221 -220
- package/dist/cjs/httpClient.js +258 -0
- package/dist/cjs/httpClient.js.map +1 -0
- package/dist/cjs/index.js +32 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/interfaces/ApiResult.js +3 -0
- package/dist/cjs/interfaces/ApiResult.js.map +1 -0
- package/dist/cjs/interfaces/Filter.js +3 -0
- package/dist/cjs/interfaces/Filter.js.map +1 -0
- package/dist/cjs/interfaces/SortType.js +3 -0
- package/dist/cjs/interfaces/SortType.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/types/ApiCallOptions.js +3 -0
- package/dist/cjs/types/ApiCallOptions.js.map +1 -0
- package/dist/cjs/types/ApiMethodArguments.js +3 -0
- package/dist/cjs/types/ApiMethodArguments.js.map +1 -0
- package/dist/cjs/types/ApiMethodOptions.js +3 -0
- package/dist/cjs/types/ApiMethodOptions.js.map +1 -0
- package/dist/cjs/types/ApiMethodTypes.js +3 -0
- package/dist/cjs/types/ApiMethodTypes.js.map +1 -0
- package/dist/cjs/types/HttpResponse.js +3 -0
- package/dist/cjs/types/HttpResponse.js.map +1 -0
- package/dist/cjs/types/httpClientTypes.js +3 -0
- package/dist/cjs/types/httpClientTypes.js.map +1 -0
- package/dist/cjs/utils/SortTypeFromSortDirection.js +43 -0
- package/dist/cjs/utils/SortTypeFromSortDirection.js.map +1 -0
- package/dist/cjs/utils/buildQuery.js +96 -0
- package/dist/cjs/utils/buildQuery.js.map +1 -0
- package/dist/cjs/utils/extractArgsCallbacksAndParams.js +51 -0
- package/dist/cjs/utils/extractArgsCallbacksAndParams.js.map +1 -0
- package/dist/cjs/utils/extractArgsToastsAndParams.js +49 -0
- package/dist/cjs/utils/extractArgsToastsAndParams.js.map +1 -0
- package/dist/cjs/utils/handleApiResponse.js +124 -0
- package/dist/cjs/utils/handleApiResponse.js.map +1 -0
- package/dist/cjs/utils/toFormData.js +58 -0
- package/dist/cjs/utils/toFormData.js.map +1 -0
- package/dist/cjs/utils/wireMapping.js +123 -0
- package/dist/cjs/utils/wireMapping.js.map +1 -0
- package/dist/esm/httpClient.js +251 -0
- package/dist/esm/httpClient.js.map +1 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/interfaces/ApiResult.js +2 -0
- package/dist/esm/interfaces/ApiResult.js.map +1 -0
- package/dist/esm/interfaces/Filter.js +2 -0
- package/dist/esm/interfaces/Filter.js.map +1 -0
- package/dist/esm/interfaces/SortType.js +2 -0
- package/dist/esm/interfaces/SortType.js.map +1 -0
- package/dist/esm/types/ApiCallOptions.js +2 -0
- package/dist/esm/types/ApiCallOptions.js.map +1 -0
- package/dist/esm/types/ApiMethodArguments.js +2 -0
- package/dist/esm/types/ApiMethodArguments.js.map +1 -0
- package/dist/esm/types/ApiMethodOptions.js +2 -0
- package/dist/esm/types/ApiMethodOptions.js.map +1 -0
- package/dist/esm/types/ApiMethodTypes.js +2 -0
- package/dist/esm/types/ApiMethodTypes.js.map +1 -0
- package/dist/esm/types/HttpResponse.js +2 -0
- package/dist/esm/types/HttpResponse.js.map +1 -0
- package/dist/esm/types/httpClientTypes.js +2 -0
- package/dist/esm/types/httpClientTypes.js.map +1 -0
- package/dist/esm/utils/SortTypeFromSortDirection.js +38 -0
- package/dist/esm/utils/SortTypeFromSortDirection.js.map +1 -0
- package/dist/esm/utils/buildQuery.js +93 -0
- package/dist/esm/utils/buildQuery.js.map +1 -0
- package/dist/esm/utils/extractArgsCallbacksAndParams.js +48 -0
- package/dist/esm/utils/extractArgsCallbacksAndParams.js.map +1 -0
- package/dist/esm/utils/extractArgsToastsAndParams.js +46 -0
- package/dist/esm/utils/extractArgsToastsAndParams.js.map +1 -0
- package/dist/esm/utils/handleApiResponse.js +121 -0
- package/dist/esm/utils/handleApiResponse.js.map +1 -0
- package/dist/esm/utils/toFormData.js +55 -0
- package/dist/esm/utils/toFormData.js.map +1 -0
- package/dist/esm/utils/wireMapping.js +119 -0
- package/dist/esm/utils/wireMapping.js.map +1 -0
- package/dist/types/httpClient.d.ts +63 -0
- package/dist/types/httpClient.d.ts.map +1 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/interfaces/ApiResult.d.ts +32 -0
- package/dist/types/interfaces/ApiResult.d.ts.map +1 -0
- package/dist/types/interfaces/Filter.d.ts +31 -0
- package/dist/types/interfaces/Filter.d.ts.map +1 -0
- package/dist/types/interfaces/SortType.d.ts +7 -0
- package/dist/types/interfaces/SortType.d.ts.map +1 -0
- package/dist/types/types/ApiCallOptions.d.ts +26 -0
- package/dist/types/types/ApiCallOptions.d.ts.map +1 -0
- package/dist/types/types/ApiMethodArguments.d.ts +6 -0
- package/dist/types/types/ApiMethodArguments.d.ts.map +1 -0
- package/dist/types/types/ApiMethodOptions.d.ts +8 -0
- package/dist/types/types/ApiMethodOptions.d.ts.map +1 -0
- package/dist/types/types/ApiMethodTypes.d.ts +47 -0
- package/dist/types/types/ApiMethodTypes.d.ts.map +1 -0
- package/dist/types/types/HttpResponse.d.ts +2 -0
- package/dist/types/types/HttpResponse.d.ts.map +1 -0
- package/dist/types/types/httpClientTypes.d.ts +2 -0
- package/dist/types/types/httpClientTypes.d.ts.map +1 -0
- package/dist/types/utils/SortTypeFromSortDirection.d.ts +13 -0
- package/dist/types/utils/SortTypeFromSortDirection.d.ts.map +1 -0
- package/dist/types/utils/buildQuery.d.ts +16 -0
- package/dist/types/utils/buildQuery.d.ts.map +1 -0
- package/dist/types/utils/extractArgsCallbacksAndParams.d.ts +22 -0
- package/dist/types/utils/extractArgsCallbacksAndParams.d.ts.map +1 -0
- package/dist/types/utils/extractArgsToastsAndParams.d.ts +20 -0
- package/dist/types/utils/extractArgsToastsAndParams.d.ts.map +1 -0
- package/dist/types/utils/handleApiResponse.d.ts +11 -0
- package/dist/types/utils/handleApiResponse.d.ts.map +1 -0
- package/dist/types/utils/toFormData.d.ts +10 -0
- package/dist/types/utils/toFormData.d.ts.map +1 -0
- package/dist/types/utils/wireMapping.d.ts +30 -0
- package/dist/types/utils/wireMapping.d.ts.map +1 -0
- package/package.json +90 -82
- package/scripts/build.mjs +74 -0
- package/scripts/generate-api-minimal.mjs +568 -476
- package/scripts/openapi-generator/controller-template.mjs +1 -1
- package/scripts/openapi-generator/index.mjs +357 -113
- package/scripts/openapi-generator/method-template.mjs +201 -244
- package/scripts/openapi-generator/names.mjs +37 -86
- package/scripts/openapi-generator/openapi-utils.mjs +411 -147
- package/scripts/openapi-generator/schema.mjs +518 -238
- package/dist/index.cjs +0 -536
- package/dist/index.d.cts +0 -285
- package/dist/index.d.ts +0 -285
- package/dist/index.js +0 -495
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `typedapi-client-helpers` are documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.3.0] - 2026-07-10
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
* Added serializer-aware wire mapping through `toWireValue()` and `fromWireValue()`.
|
|
10
|
+
* Added support for exact OpenAPI property names in JSON bodies, multipart forms, query parameters, headers, cookies, path parameters, responses, and documented error bodies.
|
|
11
|
+
* Added support for path, query, header, cookie, and request-body inputs in the same operation.
|
|
12
|
+
* Added typed unions for documented non-success response bodies.
|
|
13
|
+
* Added structured client errors for network failures, aborted requests, and malformed responses.
|
|
14
|
+
* Added support for local OpenAPI `$ref` values in schemas, parameters, path items, request bodies, and responses.
|
|
15
|
+
* Added support for `allOf` schemas with additional local properties.
|
|
16
|
+
* Added configurable frontend method naming through `typedApiMethodNameStyle`.
|
|
17
|
+
* Added `typedApiPrefixMethodNamesWithController` for controller-prefixed action names.
|
|
18
|
+
* Added controller-name fallback detection from TypedApi metadata, OpenAPI tags, and route paths.
|
|
19
|
+
* Added generated root `index.ts` barrel exports.
|
|
20
|
+
* Added `typedapi.manifest.json` containing generator, contract, source, and naming information.
|
|
21
|
+
* Added `--check`, `--strict`, `--offline`, and `--verbose` generator modes.
|
|
22
|
+
* Added configurable Swagger download timeouts.
|
|
23
|
+
* Added global and per-request timeout support.
|
|
24
|
+
* Added support for external `AbortSignal` values and combined cancellation signals.
|
|
25
|
+
* Added header and cookie utilities through `mergeHeaders()`, `toRequestHeaders()`, and `toCookieHeader()`.
|
|
26
|
+
* Added automated generator and runtime tests.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
* Generated TypeScript property names now lowercase only the first character while preserving the remainder of the OpenAPI name.
|
|
31
|
+
* Generated operation IDs and TypeScript identifiers are validated and sanitized before files are written.
|
|
32
|
+
* Missing operation IDs now cause a clear error by default.
|
|
33
|
+
* Missing operation IDs can optionally be generated with `typedApiGenerateMissingOperationIds`.
|
|
34
|
+
* Action-based names can include the controller name by default, preventing collisions between actions with the same name in different controllers.
|
|
35
|
+
* Controller prefixes are not duplicated when an action name already begins with the controller name.
|
|
36
|
+
* Generated method signatures now keep non-body parameters, request bodies, and request options in predictable argument groups.
|
|
37
|
+
* Body-only operations now accept their payload directly without an additional request wrapper.
|
|
38
|
+
* Query-only and paginated operations now use more specific generated query types.
|
|
39
|
+
* Documented backend errors are returned alongside structured TypedApi client errors.
|
|
40
|
+
* Malformed JSON is now returned as a structured parse error instead of being cast to the expected response type.
|
|
41
|
+
* Exceptions thrown by consumer `onSuccess` and `onError` callbacks now propagate normally.
|
|
42
|
+
* Fetch header merging now uses the native `Headers` implementation.
|
|
43
|
+
* File, Blob, FormData, and multipart handling is safer in SSR and Node.js environments.
|
|
44
|
+
* Binary image, PDF, and octet-stream responses are handled as blobs.
|
|
45
|
+
* The package build now uses a deterministic TypeScript-only ESM, CommonJS, and declaration build instead of a bundler-dependent build.
|
|
46
|
+
|
|
47
|
+
### Fixed
|
|
48
|
+
|
|
49
|
+
* Fixed generated-output replacement failures caused by transient Windows filesystem locks.
|
|
50
|
+
* Added retries for filesystem errors encountered while replacing generated output.
|
|
51
|
+
* Added rollback-protected managed-file synchronization when `src/api` cannot be renamed because an editor, TypeScript watcher, antivirus scanner, or development server holds a directory handle.
|
|
52
|
+
* Preserved unmanaged files during fallback synchronization.
|
|
53
|
+
* Removed stale TypedApi-generated files during fallback synchronization.
|
|
54
|
+
* Fixed handling of cancel token `0`.
|
|
55
|
+
* Fixed abort-controller cleanup after completed requests.
|
|
56
|
+
* Fixed URLs that already contain query strings.
|
|
57
|
+
* Fixed absolute URL handling.
|
|
58
|
+
* Fixed duplicate generated method and type names after TypeScript normalization.
|
|
59
|
+
* Fixed property-name collisions caused by first-character normalization.
|
|
60
|
+
|
|
61
|
+
### Migration notes
|
|
62
|
+
|
|
63
|
+
* OpenAPI 3.x is now required. Swagger 2.0 documents are rejected.
|
|
64
|
+
* Regenerated method names, parameter types, property names, and method signatures may differ from version `0.2.1`.
|
|
65
|
+
* Projects using `typedApiMethodNameStyle: "action"` receive controller-prefixed names by default.
|
|
66
|
+
* Set `typedApiPrefixMethodNamesWithController` to `false` to generate action-only names.
|
|
67
|
+
* Set `typedApiGenerateMissingOperationIds` to `true` only when operation IDs cannot be supplied by the backend.
|
|
68
|
+
* Regenerate and review committed API files after upgrading.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Stef Buurman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,220 +1,221 @@
|
|
|
1
|
-
# typedapi-client-helpers
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
1
|
+
# typedapi-client-helpers
|
|
2
|
+
|
|
3
|
+
A small Fetch runtime and OpenAPI 3 TypeScript generator designed to work with `TypedApi.Swagger` on ASP.NET Core.
|
|
4
|
+
|
|
5
|
+
## Version 0.3 highlights
|
|
6
|
+
|
|
7
|
+
- Lowercases only the first character of generated TypeScript members while preserving exact OpenAPI names on the wire.
|
|
8
|
+
- Sanitizes operation IDs and rejects duplicates before writing output.
|
|
9
|
+
- Can name frontend functions from either the unique OpenAPI operation ID or the original ASP.NET controller action name.
|
|
10
|
+
- Supports path, query, header, cookie, and request-body inputs in the same operation.
|
|
11
|
+
- Resolves local OpenAPI references for schemas, parameters, request bodies, and responses.
|
|
12
|
+
- Supports `allOf` composition with local properties.
|
|
13
|
+
- Generates typed unions for documented non-success responses.
|
|
14
|
+
- Produces `index.ts` and `typedapi.manifest.json`.
|
|
15
|
+
- Writes generated output transactionally, with a Windows-safe in-place fallback when directory renames are blocked by editors or file watchers.
|
|
16
|
+
- Adds `--check`, `--strict`, `--offline`, and `--verbose` CLI modes.
|
|
17
|
+
- Improves cancellation, timeouts, header merging, SSR safety, and malformed-response handling.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install typedapi-client-helpers@0.3.0
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The generator expects an OpenAPI 3.x document. Swagger 2.0 documents are rejected with a clear error.
|
|
26
|
+
|
|
27
|
+
## Configure generation
|
|
28
|
+
|
|
29
|
+
Add settings to the consuming application's `package.json`:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"scripts": {
|
|
34
|
+
"generate:api": "typedapi-generate",
|
|
35
|
+
"check:api": "typedapi-generate --check"
|
|
36
|
+
},
|
|
37
|
+
"config": {
|
|
38
|
+
"swaggerUrl": "https://localhost:7000/swagger/v1/swagger.json",
|
|
39
|
+
"apiOutput": "src/api",
|
|
40
|
+
"typedApiSwaggerBackupFile": "swagger/swagger.backup.json",
|
|
41
|
+
"typedApiDownloadTimeoutMs": 15000,
|
|
42
|
+
"typedApiCleanOutput": true,
|
|
43
|
+
"typedApiGenerateMissingOperationIds": false,
|
|
44
|
+
"typedApiMethodNameStyle": "operationId",
|
|
45
|
+
"typedApiPrefixMethodNamesWithController": true
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Run:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm run generate:api
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Generated output contains:
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
src/api/
|
|
60
|
+
├── generated/
|
|
61
|
+
│ ├── data-contracts.ts
|
|
62
|
+
│ └── http-client.ts
|
|
63
|
+
├── methods/
|
|
64
|
+
│ └── Products.api.ts
|
|
65
|
+
├── index.ts
|
|
66
|
+
└── typedapi.manifest.json
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The Swagger backup belongs to the consuming project, not this npm package.
|
|
70
|
+
|
|
71
|
+
## Frontend method names
|
|
72
|
+
|
|
73
|
+
Choose the source of generated function names with `typedApiMethodNameStyle`:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"config": {
|
|
78
|
+
"typedApiMethodNameStyle": "action",
|
|
79
|
+
"typedApiPrefixMethodNamesWithController": true
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- `"operationId"` uses the unique OpenAPI operation ID. The controller-prefix setting does not affect this mode.
|
|
85
|
+
- `"action"` uses the original ASP.NET controller action name.
|
|
86
|
+
- `typedApiPrefixMethodNamesWithController: true` is the default in action mode and prefixes the normalized controller name.
|
|
87
|
+
- `typedApiPrefixMethodNamesWithController: false` removes the controller prefix.
|
|
88
|
+
|
|
89
|
+
For an `OrderController` action named `GetOrderById`:
|
|
90
|
+
|
|
91
|
+
```text
|
|
92
|
+
typedApiPrefixMethodNamesWithController: true -> orderGetOrderById(...)
|
|
93
|
+
typedApiPrefixMethodNamesWithController: false -> getOrderById(...)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Operation-specific types follow the selected name too:
|
|
97
|
+
|
|
98
|
+
```text
|
|
99
|
+
true -> OrderGetOrderByIdParams
|
|
100
|
+
false -> GetOrderByIdParams
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Action-name mode requires the matching `TypedApi.Swagger` package, which emits `x-typedapi-operation.actionName`. When the prefix is enabled, the controller name is read from `x-typedapi-operation.controllerName`, the first OpenAPI tag, or the route. If disabling the prefix creates duplicate names across controllers, generation stops with a clear collision error; enable the prefix, rename an action, or use `"operationId"`.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## CI consistency check
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
typedapi-generate --check
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
This generates in memory and exits with an error when committed generated files are missing, stale, or different.
|
|
113
|
+
|
|
114
|
+
Other modes:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
typedapi-generate --strict # fail instead of using a backup after a download error
|
|
118
|
+
typedapi-generate --offline # intentionally generate from the backup
|
|
119
|
+
typedapi-generate --verbose # print additional diagnostics
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
## Generated property names
|
|
124
|
+
|
|
125
|
+
Generated interface and parameter members lowercase **only the first character**:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
Files -> files
|
|
129
|
+
URLValue -> uRLValue
|
|
130
|
+
ProductID -> productID
|
|
131
|
+
snake_case -> snake_case
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The rest of each name is left unchanged. Generated wire metadata converts these local names back to the exact OpenAPI names for JSON, multipart forms, query parameters, headers, cookies, and path parameters. Responses and documented error bodies are converted in the opposite direction.
|
|
135
|
+
|
|
136
|
+
## Generated method shape
|
|
137
|
+
|
|
138
|
+
Generated methods keep parameters and request bodies as separate positional groups. Non-body parameters come first, the body comes second, and request options remain last:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
await updateWarehouse(
|
|
142
|
+
{ id: requireId(context.warehouseId, "Warehouse ID") },
|
|
143
|
+
warehouse,
|
|
144
|
+
);
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
The generated signature is:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
export async function updateWarehouse(
|
|
151
|
+
pathParams: UpdateWarehouseParams,
|
|
152
|
+
data: WarehouseRequest,
|
|
153
|
+
options: ApiMethodOptions<WarehouseModel, unknown, RequestParams> = {},
|
|
154
|
+
): Promise<ApiResult<WarehouseModel, unknown>>;
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Path operations without a body use only the params object:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
await deleteSupplier({ id: requireId(context.supplierId, "Supplier ID") });
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Body-only operations accept their payload directly:
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
await uploadProductFiles({ files: selectedFiles });
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Query-only operations use a `query` argument. Operations involving headers or cookies without path parameters use `requestParams`. All generated parameter interfaces are named `OperationNameParams`; nested `path`, `query`, `headers`, `cookies`, or `body` wrappers are not generated.
|
|
170
|
+
|
|
171
|
+
Request options are always last:
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
await updateWarehouse(pathParams, data, {
|
|
175
|
+
params: {
|
|
176
|
+
signal: abortController.signal,
|
|
177
|
+
timeoutMs: 10_000,
|
|
178
|
+
headers: new Headers({ Authorization: "Bearer ..." }),
|
|
179
|
+
},
|
|
180
|
+
onSuccess: result => console.log(result.response),
|
|
181
|
+
onError: result => console.error(result.error),
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Typed errors
|
|
186
|
+
|
|
187
|
+
When the OpenAPI document describes error response bodies, generated methods expose their union:
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
const result = await createProduct(body);
|
|
191
|
+
|
|
192
|
+
if (!result.ok) {
|
|
193
|
+
// Documented backend error type or a TypedApi client error:
|
|
194
|
+
// network, aborted, or parse.
|
|
195
|
+
console.error(result.error);
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Malformed JSON is reported as a structured parse error instead of being cast to the expected response type. Consumer callback exceptions are allowed to propagate and are not disguised as API failures.
|
|
200
|
+
|
|
201
|
+
## Runtime configuration
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
import { configureApiClient, setSecurityData } from "typedapi-client-helpers";
|
|
205
|
+
|
|
206
|
+
configureApiClient({
|
|
207
|
+
baseUrl: "https://api.example.com",
|
|
208
|
+
timeoutMs: 15_000,
|
|
209
|
+
securityWorker: token => token
|
|
210
|
+
? { headers: { Authorization: `Bearer ${token}` } }
|
|
211
|
+
: undefined
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
setSecurityData("access-token");
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The runtime also exports `createApiClient`, `request`, `abortRequest`, `mergeHeaders`, `toRequestHeaders`, `toCookieHeader`, `handleApiResponse`, `buildQuery`, `toFormData`, `toWireValue`, and `fromWireValue`.
|
|
218
|
+
|
|
219
|
+
## Backend pairing
|
|
220
|
+
|
|
221
|
+
Use `TypedApi.Swagger` 0.3 or newer on the backend. It emits `x-typedapi.contractVersion = 1`, unique operation IDs, serializer-aware property names, and explicit pagination metadata. The generator validates the contract version before replacing generated files.
|