typedapi-client-helpers 0.3.3 → 0.3.4

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 CHANGED
@@ -2,6 +2,37 @@
2
2
 
3
3
  All notable changes to `typedapi-client-helpers` are documented in this file.
4
4
 
5
+ ## [0.3.4] - 2026-07-22
6
+
7
+ ### Added
8
+
9
+ * Added support for `x-typedapi-generic` metadata and reusable TypeScript generic declarations.
10
+ * Added exact generic substitutions for direct properties, array/collection items, dictionary values, and inherited generic wrappers.
11
+ * Added discriminator mapping support with literal discriminator properties and frontend union types.
12
+ * Added readable closed-generic reference handling such as `ApiPaginationResponseOfProjectModel` to `ApiPaginationResponse<ProjectModel>`.
13
+ * Added generator coverage for custom generic envelopes, pagination, nullability combinations, polymorphism, schema IDs, typed errors, and TypeScript compilation.
14
+
15
+ ### Changed
16
+
17
+ * Requiredness and nullability now remain independent in generated property declarations.
18
+ * Polymorphic base schemas now generate a separate `Base` contract plus a union of concrete variants.
19
+ * Derived polymorphic schemas inherit from the base contract rather than from the union, preventing cyclic TypeScript types.
20
+ * Inline `allOf` object fragments are emitted directly in intersections instead of creating unnecessary numbered helper interfaces.
21
+ * Typed OpenAPI error responses are deduplicated into method-specific error unions.
22
+ * TypedApi contract version 2 is now supported.
23
+
24
+ ### Fixed
25
+
26
+ * Fixed flattened inherited generic wrappers accidentally capturing the first concrete schema, such as generating `data: OrderModel[]` inside `ApiPaginationSortResponse<T>`.
27
+ * Fixed flattened generic inheritance being emitted as a duplicated standalone interface; annotated derived wrappers now preserve their reusable generic base intersection.
28
+ * Invalid generic metadata with unused type parameters now fails with a clear error instead of emitting a misleading generic declaration.
29
+
30
+ ### Compatibility notes
31
+
32
+ * Pair this package with `TypedApi.Swagger` 0.3.1 or newer for all new features.
33
+ * Regenerate committed API files after upgrading.
34
+ * Generic reconstruction only occurs for schemas carrying `x-typedapi-generic`; ordinary closed generic schemas remain ordinary component types.
35
+
5
36
  ## [0.3.0] - 2026-07-10
6
37
 
7
38
  ### Added
package/README.md CHANGED
@@ -2,25 +2,74 @@
2
2
 
3
3
  A small Fetch runtime and OpenAPI 3 TypeScript generator designed to work with `TypedApi.Swagger` on ASP.NET Core.
4
4
 
5
- ## Version 0.3 highlights
6
-
7
- - Lowercases only the first character of generated TypeScript members.
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
- - Generates API contracts and controller method files 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.
5
+ ## Version 0.3.4 highlights
6
+
7
+ - Reconstructs opted-in closed .NET generic schemas as reusable TypeScript generics.
8
+ - Supports exact generic bindings for direct properties, arrays/collections, and dictionary values.
9
+ - Preserves required-but-nullable properties as required `T | null` instead of optional values.
10
+ - Generates non-cyclic discriminated unions with literal discriminator fields.
11
+ - Consumes readable generic schema IDs such as `ApiPaginationResponseOfProjectModel`.
12
+ - Generates method-specific unions from typed `ProblemDetails` error responses.
13
+ - Validates TypedApi OpenAPI contract version 2.
14
+
15
+ ### Generic contracts
16
+
17
+ With `[TypedApiGeneric]` on a backend wrapper, a closed schema such as `ApiEnvelope<ProjectModel>` becomes one reusable declaration:
18
+
19
+ ```ts
20
+ export interface ApiEnvelope<T> {
21
+ data: T;
22
+ relatedItems: T[];
23
+ itemsByKey: Record<string, T>;
24
+ }
25
+ ```
26
+
27
+ Endpoints then use `ApiEnvelope<ProjectModel>` rather than a repeated `ApiEnvelopeOfProjectModel` interface. Inherited generic wrappers are reconstructed whether Swagger uses `allOf` or emits a flattened schema:
28
+
29
+ ```ts
30
+ export type ApiPaginationSortResponse<T> = ApiPaginationResponse<T> & {
31
+ sortBy?: string | null;
32
+ sortDirection: SortDirection;
33
+ };
34
+ ```
35
+
36
+ ### Required and nullable properties
37
+
38
+ OpenAPI presence and nullability remain separate:
39
+
40
+ ```ts
41
+ export interface NullabilityContract {
42
+ requiredText: string;
43
+ requiredNullableText: string | null;
44
+ optionalNullableText?: string | null;
45
+ }
46
+ ```
47
+
48
+ ### Discriminated unions
49
+
50
+ Serializer discriminator mappings produce narrowing unions without cyclic inheritance:
51
+
52
+ ```ts
53
+ export type NotificationModel = EmailNotificationModel | SmsNotificationModel;
54
+
55
+ export type EmailNotificationModel = NotificationModelBase & {
56
+ emailAddress: string;
57
+ kind: "email";
58
+ };
59
+ ```
60
+
61
+ ### Typed errors
62
+
63
+ When the OpenAPI operation contains typed error response bodies, generated methods expose the union directly:
64
+
65
+ ```ts
66
+ ApiResult<ProjectModel, HttpValidationProblemDetails | ProblemDetails>
67
+ ```
19
68
 
20
69
  ## Install
21
70
 
22
71
  ```bash
23
- npm install typedapi-client-helpers@0.3.3
72
+ npm install typedapi-client-helpers@0.3.4
24
73
  ```
25
74
 
26
75
  The generator expects an OpenAPI 3.x document. Swagger 2.0 documents are rejected with a clear error.
@@ -227,4 +276,4 @@ The runtime also exports `createApiClient`, `request`, `abortRequest`, `mergeHea
227
276
 
228
277
  ## Backend pairing
229
278
 
230
- 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.
279
+ Use `TypedApi.Swagger` 0.3.1 or newer on the backend for generic reconstruction, corrected nullability, discriminators, readable schema IDs, and typed default errors. It emits `x-typedapi.contractVersion = 2`. The generator validates the contract version before replacing generated files.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typedapi-client-helpers",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Reusable typed OpenAPI client helpers.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -19,7 +19,7 @@ export async function generateApi(options) {
19
19
  const source = fs.readFileSync(inputPath, "utf8");
20
20
  const openApi = JSON.parse(source);
21
21
 
22
- validateOpenApiDocument(openApi, { supportedContractVersion: 1 });
22
+ validateOpenApiDocument(openApi, { supportedContractVersion: 2 });
23
23
  const operations = collectOperations(openApi, {
24
24
  generateMissingOperationIds: Boolean(options.generateMissingOperationIds),
25
25
  methodNameStyle: options.methodNameStyle ?? "operationId",