typedapi-client-helpers 0.2.1 → 0.3.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 +72 -0
- package/README.md +231 -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 +132 -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 +128 -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 +41 -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 +12 -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 -84
- 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 +348 -113
- package/scripts/openapi-generator/method-template.mjs +405 -440
- package/scripts/openapi-generator/names.mjs +37 -86
- package/scripts/openapi-generator/openapi-utils.mjs +411 -147
- package/scripts/openapi-generator/schema.mjs +737 -455
- 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,72 @@
|
|
|
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 `ApiHttpError` for operations without a documented OpenAPI error schema.
|
|
15
|
+
* Added support for local OpenAPI `$ref` values in schemas, parameters, path items, request bodies, and responses.
|
|
16
|
+
* Added support for `allOf` schemas with additional local properties.
|
|
17
|
+
* Added configurable frontend method naming through `typedApiMethodNameStyle`.
|
|
18
|
+
* Added `typedApiPrefixMethodNamesWithController` for controller-prefixed action names.
|
|
19
|
+
* Added controller-name fallback detection from TypedApi metadata, OpenAPI tags, and route paths.
|
|
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
|
+
* Generated methods now use `ApiHttpError` instead of `unknown` when no backend error schema is documented.
|
|
38
|
+
* Generated API output no longer contains a root `index.ts`; methods and contracts are imported directly from their generated files.
|
|
39
|
+
* Body-only operations now accept their payload directly without an additional request wrapper.
|
|
40
|
+
* Query-only and paginated operations now use more specific generated query types.
|
|
41
|
+
* Documented backend errors are returned alongside structured TypedApi client errors.
|
|
42
|
+
* Malformed JSON is now returned as a structured parse error instead of being cast to the expected response type.
|
|
43
|
+
* Exceptions thrown by consumer `onSuccess` and `onError` callbacks now propagate normally.
|
|
44
|
+
* Fetch header merging now uses the native `Headers` implementation.
|
|
45
|
+
* File, Blob, FormData, and multipart handling is safer in SSR and Node.js environments.
|
|
46
|
+
* Binary image, PDF, and octet-stream responses are handled as blobs.
|
|
47
|
+
* The package build now uses a deterministic TypeScript-only ESM, CommonJS, and declaration build instead of a bundler-dependent build.
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
|
|
51
|
+
* Fixed generated-output replacement failures caused by transient Windows filesystem locks.
|
|
52
|
+
* Added retries for filesystem errors encountered while replacing generated output.
|
|
53
|
+
* 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.
|
|
54
|
+
* Preserved unmanaged files during fallback synchronization.
|
|
55
|
+
* Removed stale TypedApi-generated files during fallback synchronization.
|
|
56
|
+
* Removed previously generated root `index.ts` files during regeneration.
|
|
57
|
+
* Fixed handling of cancel token `0`.
|
|
58
|
+
* Fixed abort-controller cleanup after completed requests.
|
|
59
|
+
* Fixed URLs that already contain query strings.
|
|
60
|
+
* Fixed absolute URL handling.
|
|
61
|
+
* Fixed duplicate generated method and type names after TypeScript normalization.
|
|
62
|
+
* Fixed property-name collisions caused by first-character normalization.
|
|
63
|
+
|
|
64
|
+
### Migration notes
|
|
65
|
+
|
|
66
|
+
* OpenAPI 3.x is now required. Swagger 2.0 documents are rejected.
|
|
67
|
+
* Regenerated method names, parameter types, property names, and method signatures may differ from version `0.2.1`.
|
|
68
|
+
* Projects using `typedApiMethodNameStyle: "action"` receive controller-prefixed names by default.
|
|
69
|
+
* Set `typedApiPrefixMethodNamesWithController` to `false` to generate action-only names.
|
|
70
|
+
* Set `typedApiGenerateMissingOperationIds` to `true` only when operation IDs cannot be supplied by the backend.
|
|
71
|
+
* Import methods from `src/api/methods/*.api.ts` and contracts from `src/api/generated/data-contracts.ts` instead of using `src/api/index.ts`.
|
|
72
|
+
* Regenerate and review committed API files after upgrading; regeneration removes the old generated root `index.ts`.
|
package/README.md
CHANGED
|
@@ -1,220 +1,231 @@
|
|
|
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
|
+
- Uses a structured `ApiHttpError` when an operation has no documented error schema.
|
|
15
|
+
- Produces `typedapi.manifest.json` without creating a root API barrel file.
|
|
16
|
+
- Writes generated output transactionally, with a Windows-safe in-place fallback when directory renames are blocked by editors or file watchers.
|
|
17
|
+
- Adds `--check`, `--strict`, `--offline`, and `--verbose` CLI modes.
|
|
18
|
+
- Improves cancellation, timeouts, header merging, SSR safety, and malformed-response handling.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install typedapi-client-helpers@0.3.0
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The generator expects an OpenAPI 3.x document. Swagger 2.0 documents are rejected with a clear error.
|
|
27
|
+
|
|
28
|
+
## Configure generation
|
|
29
|
+
|
|
30
|
+
Add settings to the consuming application's `package.json`:
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"scripts": {
|
|
35
|
+
"generate:api": "typedapi-generate",
|
|
36
|
+
"check:api": "typedapi-generate --check"
|
|
37
|
+
},
|
|
38
|
+
"config": {
|
|
39
|
+
"swaggerUrl": "https://localhost:7000/swagger/v1/swagger.json",
|
|
40
|
+
"apiOutput": "src/api",
|
|
41
|
+
"typedApiSwaggerBackupFile": "swagger/swagger.backup.json",
|
|
42
|
+
"typedApiDownloadTimeoutMs": 15000,
|
|
43
|
+
"typedApiCleanOutput": true,
|
|
44
|
+
"typedApiGenerateMissingOperationIds": false,
|
|
45
|
+
"typedApiMethodNameStyle": "operationId",
|
|
46
|
+
"typedApiPrefixMethodNamesWithController": true
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Run:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm run generate:api
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Generated output contains:
|
|
58
|
+
|
|
59
|
+
```text
|
|
60
|
+
src/api/
|
|
61
|
+
├── generated/
|
|
62
|
+
│ ├── data-contracts.ts
|
|
63
|
+
│ └── http-client.ts
|
|
64
|
+
├── methods/
|
|
65
|
+
│ └── Products.api.ts
|
|
66
|
+
└── typedapi.manifest.json
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The generator intentionally does not create `src/api/index.ts`. Import generated methods and contracts directly from their files:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { getProducts } from "./api/methods/Product.api";
|
|
73
|
+
import type { ProductModel } from "./api/generated/data-contracts";
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
When upgrading from an earlier 0.3.0 build, the next generation removes the old generated `src/api/index.ts`. The Swagger backup belongs to the consuming project, not this npm package.
|
|
77
|
+
|
|
78
|
+
## Frontend method names
|
|
79
|
+
|
|
80
|
+
Choose the source of generated function names with `typedApiMethodNameStyle`:
|
|
81
|
+
|
|
82
|
+
```json
|
|
83
|
+
{
|
|
84
|
+
"config": {
|
|
85
|
+
"typedApiMethodNameStyle": "action",
|
|
86
|
+
"typedApiPrefixMethodNamesWithController": true
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
- `"operationId"` uses the unique OpenAPI operation ID. The controller-prefix setting does not affect this mode.
|
|
92
|
+
- `"action"` uses the original ASP.NET controller action name.
|
|
93
|
+
- `typedApiPrefixMethodNamesWithController: true` is the default in action mode and prefixes the normalized controller name.
|
|
94
|
+
- `typedApiPrefixMethodNamesWithController: false` removes the controller prefix.
|
|
95
|
+
|
|
96
|
+
For an `OrderController` action named `GetOrderById`:
|
|
97
|
+
|
|
98
|
+
```text
|
|
99
|
+
typedApiPrefixMethodNamesWithController: true -> orderGetOrderById(...)
|
|
100
|
+
typedApiPrefixMethodNamesWithController: false -> getOrderById(...)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Operation-specific types follow the selected name too:
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
true -> OrderGetOrderByIdParams
|
|
107
|
+
false -> GetOrderByIdParams
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
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"`.
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
## CI consistency check
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
typedapi-generate --check
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
This generates in memory and exits with an error when committed generated files are missing, stale, or different.
|
|
120
|
+
|
|
121
|
+
Other modes:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
typedapi-generate --strict # fail instead of using a backup after a download error
|
|
125
|
+
typedapi-generate --offline # intentionally generate from the backup
|
|
126
|
+
typedapi-generate --verbose # print additional diagnostics
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
## Generated property names
|
|
131
|
+
|
|
132
|
+
Generated interface and parameter members lowercase **only the first character**:
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
Files -> files
|
|
136
|
+
URLValue -> uRLValue
|
|
137
|
+
ProductID -> productID
|
|
138
|
+
snake_case -> snake_case
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
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.
|
|
142
|
+
|
|
143
|
+
## Generated method shape
|
|
144
|
+
|
|
145
|
+
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:
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
await updateWarehouse(
|
|
149
|
+
{ id: requireId(context.warehouseId, "Warehouse ID") },
|
|
150
|
+
warehouse,
|
|
151
|
+
);
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The generated signature is:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
export async function updateWarehouse(
|
|
158
|
+
pathParams: UpdateWarehouseParams,
|
|
159
|
+
data: WarehouseRequest,
|
|
160
|
+
options: ApiMethodOptions<WarehouseModel, ApiHttpError, RequestParams> = {},
|
|
161
|
+
): Promise<ApiResult<WarehouseModel, ApiHttpError>>;
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Path operations without a body use only the params object:
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
await deleteSupplier({ id: requireId(context.supplierId, "Supplier ID") });
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Body-only operations accept their payload directly:
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
await uploadProductFiles({ files: selectedFiles });
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
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.
|
|
177
|
+
|
|
178
|
+
Request options are always last:
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
await updateWarehouse(pathParams, data, {
|
|
182
|
+
params: {
|
|
183
|
+
signal: abortController.signal,
|
|
184
|
+
timeoutMs: 10_000,
|
|
185
|
+
headers: new Headers({ Authorization: "Bearer ..." }),
|
|
186
|
+
},
|
|
187
|
+
onSuccess: result => console.log(result.response),
|
|
188
|
+
onError: result => console.error(result.error),
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Typed errors
|
|
193
|
+
|
|
194
|
+
When the OpenAPI document describes error response bodies, generated methods expose their generated type or union. When no error schema is documented, the method uses `ApiHttpError` instead of `unknown`:
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
const result = await cancelOrder({ id, reason });
|
|
198
|
+
|
|
199
|
+
if (!result.ok) {
|
|
200
|
+
if (result.error.kind === "http") {
|
|
201
|
+
console.error(result.error.status, result.error.body);
|
|
202
|
+
} else {
|
|
203
|
+
// Structured TypedApi client error: network, aborted, or parse.
|
|
204
|
+
console.error(result.error);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
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.
|
|
210
|
+
|
|
211
|
+
## Runtime configuration
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
import { configureApiClient, setSecurityData } from "typedapi-client-helpers";
|
|
215
|
+
|
|
216
|
+
configureApiClient({
|
|
217
|
+
baseUrl: "https://api.example.com",
|
|
218
|
+
timeoutMs: 15_000,
|
|
219
|
+
securityWorker: token => token
|
|
220
|
+
? { headers: { Authorization: `Bearer ${token}` } }
|
|
221
|
+
: undefined
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
setSecurityData("access-token");
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
The runtime also exports `createApiClient`, `request`, `abortRequest`, `mergeHeaders`, `toRequestHeaders`, `toCookieHeader`, `handleApiResponse`, `buildQuery`, `toFormData`, `toWireValue`, and `fromWireValue`.
|
|
228
|
+
|
|
229
|
+
## Backend pairing
|
|
230
|
+
|
|
231
|
+
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.
|