@origins-digital/ts-rest-zod-openapi 1.0.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.
Files changed (50) hide show
  1. package/README.md +295 -0
  2. package/dist/index.d.ts +5 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +21 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/contract-traversal.d.ts +15 -0
  7. package/dist/lib/contract-traversal.d.ts.map +1 -0
  8. package/dist/lib/contract-traversal.js +147 -0
  9. package/dist/lib/contract-traversal.js.map +1 -0
  10. package/dist/lib/parsers/body.d.ts +15 -0
  11. package/dist/lib/parsers/body.d.ts.map +1 -0
  12. package/dist/lib/parsers/body.js +33 -0
  13. package/dist/lib/parsers/body.js.map +1 -0
  14. package/dist/lib/parsers/headers.d.ts +15 -0
  15. package/dist/lib/parsers/headers.d.ts.map +1 -0
  16. package/dist/lib/parsers/headers.js +103 -0
  17. package/dist/lib/parsers/headers.js.map +1 -0
  18. package/dist/lib/parsers/index.d.ts +6 -0
  19. package/dist/lib/parsers/index.d.ts.map +1 -0
  20. package/dist/lib/parsers/index.js +27 -0
  21. package/dist/lib/parsers/index.js.map +1 -0
  22. package/dist/lib/parsers/path-params.d.ts +21 -0
  23. package/dist/lib/parsers/path-params.d.ts.map +1 -0
  24. package/dist/lib/parsers/path-params.js +79 -0
  25. package/dist/lib/parsers/path-params.js.map +1 -0
  26. package/dist/lib/parsers/query-params.d.ts +16 -0
  27. package/dist/lib/parsers/query-params.d.ts.map +1 -0
  28. package/dist/lib/parsers/query-params.js +47 -0
  29. package/dist/lib/parsers/query-params.js.map +1 -0
  30. package/dist/lib/parsers/utils.d.ts +12 -0
  31. package/dist/lib/parsers/utils.d.ts.map +1 -0
  32. package/dist/lib/parsers/utils.js +50 -0
  33. package/dist/lib/parsers/utils.js.map +1 -0
  34. package/dist/lib/transformers.d.ts +9 -0
  35. package/dist/lib/transformers.d.ts.map +1 -0
  36. package/dist/lib/transformers.js +22 -0
  37. package/dist/lib/transformers.js.map +1 -0
  38. package/dist/lib/ts-rest-open-api.d.ts +47 -0
  39. package/dist/lib/ts-rest-open-api.d.ts.map +1 -0
  40. package/dist/lib/ts-rest-open-api.js +141 -0
  41. package/dist/lib/ts-rest-open-api.js.map +1 -0
  42. package/dist/lib/types.d.ts +88 -0
  43. package/dist/lib/types.d.ts.map +1 -0
  44. package/dist/lib/types.js +25 -0
  45. package/dist/lib/types.js.map +1 -0
  46. package/dist/lib/utils.d.ts +6 -0
  47. package/dist/lib/utils.d.ts.map +1 -0
  48. package/dist/lib/utils.js +85 -0
  49. package/dist/lib/utils.js.map +1 -0
  50. package/package.json +103 -0
package/README.md ADDED
@@ -0,0 +1,295 @@
1
+ # @origins-digital/ts-rest-zod-openapi
2
+
3
+ A custom transformer for `@ts-rest/openapi` that uses `@origins-digital/zod-openapi-utils` instead of `@anatine/zod-openapi` and is able to deal with lazy schemes.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @origins-digital/ts-rest-zod-openapi
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Basic Setup
14
+
15
+ Replace the default `@anatine/zod-openapi` transformer with our custom one:
16
+
17
+ ```typescript
18
+ import { generateOpenApi } from '@origins-digital/ts-rest-zod-openapi';
19
+ import { initServer } from '@ts-rest/core';
20
+ import { z } from 'zod';
21
+
22
+ // Create your server
23
+ const server = initServer();
24
+
25
+ // Define your contracts
26
+ const userContract = server.contract({
27
+ method: 'GET',
28
+ path: '/users',
29
+ responses: {
30
+ 200: z.object({
31
+ users: z.array(
32
+ z.object({
33
+ id: z.string().describe('User ID'),
34
+ name: z.string().describe('User name'),
35
+ email: z.string().email().describe('User email'),
36
+ }),
37
+ ),
38
+ }),
39
+ },
40
+ });
41
+
42
+ // Generate OpenAPI with custom transformer
43
+ const openApiDoc = generateOpenApi([userContract], {
44
+ info: {
45
+ title: 'My API',
46
+ version: '1.0.0',
47
+ description: 'API documentation',
48
+ },
49
+ });
50
+ ```
51
+
52
+ ### With NestJS
53
+
54
+ ```typescript
55
+ import { NestExpressApplication } from '@nestjs/platform-express';
56
+ import { SwaggerModule } from '@nestjs/swagger';
57
+ import { generateOpenApi } from '@origins-digital/ts-rest-zod-openapi';
58
+ import { specContract } from './contracts';
59
+
60
+ export function setupSwagger(app: NestExpressApplication, env: string) {
61
+ if (env === 'development' || env === 'local') {
62
+ try {
63
+ const openApiDocument = generateOpenApiW(
64
+ specContract.orchestratorOutput,
65
+ {
66
+ info: {
67
+ title: 'ACM Adapter API',
68
+ version: '1.0.0',
69
+ description:
70
+ 'This is the ACM Orchestrator API OpenAPI specification.',
71
+ },
72
+ components: {
73
+ securitySchemes: {
74
+ bearer: {
75
+ scheme: 'bearer',
76
+ bearerFormat: 'JWT',
77
+ type: 'http',
78
+ },
79
+ },
80
+ },
81
+ },
82
+ );
83
+
84
+ SwaggerModule.setup('docs', app, openApiDocument);
85
+ } catch (error) {
86
+ console.warn('Failed to generate OpenAPI documentation:', error);
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ ### With Express
93
+
94
+ ```typescript
95
+ import express from 'express';
96
+ import { generateOpenApi } from '@origins-digital/ts-rest-zod-openapi';
97
+
98
+ const app = express();
99
+
100
+ // Generate OpenAPI documentation
101
+ const openApiDoc = generateOpenApi(contracts, {
102
+ info: {
103
+ title: 'Express API',
104
+ version: '1.0.0',
105
+ },
106
+ });
107
+
108
+ // Serve OpenAPI documentation
109
+ app.get('/api-docs', (req, res) => {
110
+ res.json(openApiDoc);
111
+ });
112
+ ```
113
+
114
+ ## API Reference
115
+
116
+ ### `generateOpenApiWithCustomTransformer(contracts, options)`
117
+
118
+ Generates OpenAPI documentation using the custom transformer.
119
+
120
+ #### Parameters
121
+
122
+ - `contracts`: Array of ts-rest contracts
123
+ - `options`: OpenAPI configuration options
124
+ - `info`: API information (title, version, description)
125
+ - `servers`: Array of server configurations
126
+ - `components`: OpenAPI components
127
+ - `security`: Security schemes
128
+ - `tags`: API tags
129
+
130
+ #### Returns
131
+
132
+ OpenAPI specification object compatible with Swagger UI.
133
+
134
+ ## Benefits
135
+
136
+ - **Custom Transformation**: Uses `@origins-digital/zod-openapi-utils` instead of `@anatine/zod-openapi`
137
+ - **Consistent Schema**: Same transformation logic across your entire application
138
+ - **Better Control**: Full control over how Zod schemas are converted to OpenAPI
139
+ - **No External Dependencies**: Removes dependency on `@anatine/zod-openapi`
140
+
141
+ ## Migration from @anatine/zod-openapi
142
+
143
+ Replace:
144
+
145
+ ```typescript
146
+ import { generateOpenApi } from '@ts-rest/openapi';
147
+
148
+ const openApiDoc = generateOpenApi(contracts, options);
149
+ ```
150
+
151
+ With:
152
+
153
+ ```typescript
154
+ import { generateOpenApi } from '@origins-digital/ts-rest-zod-openapi';
155
+
156
+ const openApiDoc = generateOpenApi(contracts, options);
157
+ ```
158
+
159
+ ## Examples
160
+
161
+ ### Complex Schema Example with Lazy Schemas
162
+
163
+ ```typescript
164
+ import { z } from 'zod';
165
+
166
+ // Base schemas
167
+ const externalLinkSchema = z
168
+ .object({
169
+ type: z.literal('external_link'),
170
+ linkName: z.string().optional(),
171
+ linkURL: z.string().optional(),
172
+ isVisible: z.boolean(),
173
+ })
174
+ .openapi({
175
+ title: 'ExternalLink',
176
+ description: 'External link configuration',
177
+ });
178
+
179
+ const menuItemSchema = z
180
+ .object({
181
+ type: z.literal('menu_item_web'),
182
+ label: z.string(),
183
+ geoTarget: z
184
+ .object({
185
+ enable: z.boolean(),
186
+ type: z.enum(['allow', 'deny']),
187
+ countries: z.array(z.string()),
188
+ })
189
+ .optional(),
190
+ webPagesCodenamesAndSlugs: z.array(
191
+ z.object({
192
+ codename: z.string(),
193
+ slug: z.string(),
194
+ }),
195
+ ),
196
+ isVisible: z.boolean(),
197
+ })
198
+ .openapi({
199
+ title: 'MenuItem',
200
+ description: 'Menu item configuration',
201
+ });
202
+
203
+ // Recursive schema with lazy loading
204
+ const menuItemWithSubItemsSchema = menuItemSchema
205
+ .extend({
206
+ subItems: z
207
+ .array(
208
+ z.union([z.lazy(() => menuItemWithSubItemsSchema), externalLinkSchema]),
209
+ )
210
+ .optional(),
211
+ })
212
+ .openapi({
213
+ title: 'MenuItemWithSubItems',
214
+ description: 'Menu item with nested sub-items',
215
+ });
216
+
217
+ // Main contract
218
+ const complexContract = server.contract({
219
+ method: 'GET',
220
+ path: '/api/web-config',
221
+ headers: z.object({
222
+ 'Accept-Language': z.string().optional(),
223
+ 'x-account-key': z.string(),
224
+ }),
225
+ responses: {
226
+ 200: z
227
+ .object({
228
+ type: z.literal('web_config'),
229
+ menu: z.object({
230
+ menuItems: z.array(
231
+ z.union([menuItemWithSubItemsSchema, externalLinkSchema]),
232
+ ),
233
+ }),
234
+ footer: z.object({
235
+ copyright: z.string(),
236
+ legalLinks: z.array(
237
+ z.union([menuItemWithSubItemsSchema, externalLinkSchema]),
238
+ ),
239
+ }),
240
+ errorMessage: z.object({
241
+ error404: z.string(),
242
+ genericError: z.string(),
243
+ }),
244
+ })
245
+ .openapi({
246
+ title: 'WebConfig',
247
+ description: 'Web configuration with menu and footer',
248
+ }),
249
+ },
250
+ });
251
+ ```
252
+
253
+ ### Contract Structure Example
254
+
255
+ ```typescript
256
+ import { initContract } from '@ts-rest/core';
257
+
258
+ const contract = initContract();
259
+
260
+ const webConfigEndpoints = {
261
+ getWebConfig: {
262
+ method: 'GET',
263
+ path: '/api/web-config',
264
+ headers: z.object({
265
+ 'Accept-Language': z.string().optional(),
266
+ 'x-account-key': z.string(),
267
+ }),
268
+ responses: {
269
+ 200: webConfigSchema,
270
+ },
271
+ summary: 'Get web config',
272
+ metadata: {
273
+ openApiSecurity: [
274
+ {
275
+ bearer: [],
276
+ },
277
+ ],
278
+ },
279
+ },
280
+ } as const;
281
+
282
+ export const webConfigContract = contract.router(webConfigEndpoints);
283
+
284
+ const mainContract = initContract();
285
+
286
+ export const specContract = mainContract.router({
287
+ orchestratorOutput: {
288
+ webconfig: webConfigContract,
289
+ },
290
+ });
291
+ ```
292
+
293
+ ## License
294
+
295
+ MIT
@@ -0,0 +1,5 @@
1
+ export * from './lib/transformers';
2
+ export * from './lib/parsers';
3
+ export * from './lib/types';
4
+ export * from './lib/ts-rest-open-api';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./lib/transformers"), exports);
18
+ __exportStar(require("./lib/parsers"), exports);
19
+ __exportStar(require("./lib/types"), exports);
20
+ __exportStar(require("./lib/ts-rest-open-api"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,gDAA8B;AAC9B,8CAA4B;AAC5B,yDAAuC"}
@@ -0,0 +1,15 @@
1
+ import { AppRouter } from '@ts-rest/core';
2
+ import { AsyncAndSyncHelper, PathSchemaResults, RouterPath, SchemaTransformerAsync, SchemaTransformerSync } from './types';
3
+ type PerformContractTraversalHelper = AsyncAndSyncHelper<{
4
+ contract: AppRouter;
5
+ jsonQuery: boolean;
6
+ }, {
7
+ transformSchema: SchemaTransformerSync;
8
+ }, {
9
+ transformSchema: SchemaTransformerAsync;
10
+ }, Array<RouterPath & {
11
+ schemaResults: PathSchemaResults;
12
+ }>>;
13
+ export declare const performContractTraversal: PerformContractTraversalHelper;
14
+ export {};
15
+ //# sourceMappingURL=contract-traversal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-traversal.d.ts","sourceRoot":"","sources":["../../src/lib/contract-traversal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAuC,MAAM,eAAe,CAAC;AAC/E,OAAO,EACL,kBAAkB,EAGlB,iBAAiB,EACjB,UAAU,EACV,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAOjB,KAAK,8BAA8B,GAAG,kBAAkB,CACtD;IACE,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;CACpB,EACD;IACE,eAAe,EAAE,qBAAqB,CAAC;CACxC,EACD;IACE,eAAe,EAAE,sBAAsB,CAAC;CACzC,EACD,KAAK,CAAC,UAAU,GAAG;IAAE,aAAa,EAAE,iBAAiB,CAAA;CAAE,CAAC,CACzD,CAAC;AAyLF,eAAO,MAAM,wBAAwB,EAAE,8BAGtC,CAAC"}
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.performContractTraversal = void 0;
4
+ const core_1 = require("@ts-rest/core");
5
+ const path_params_1 = require("./parsers/path-params");
6
+ const headers_1 = require("./parsers/headers");
7
+ const query_params_1 = require("./parsers/query-params");
8
+ const body_1 = require("./parsers/body");
9
+ /**
10
+ * Recursively step through the router and get all the individual routes with their paths etc.
11
+ */
12
+ const getPathsFromRouter = (router, pathHistory) => {
13
+ const paths = [];
14
+ Object.keys(router).forEach((key) => {
15
+ const value = router[key];
16
+ if ((0, core_1.isAppRoute)(value)) {
17
+ const pathWithPathParams = value.path.replace(/:(\w+)/g, '{$1}');
18
+ paths.push({
19
+ id: key,
20
+ path: pathWithPathParams,
21
+ route: value,
22
+ paths: pathHistory !== null && pathHistory !== void 0 ? pathHistory : [],
23
+ });
24
+ }
25
+ else {
26
+ paths.push(...getPathsFromRouter(value, [...(pathHistory !== null && pathHistory !== void 0 ? pathHistory : []), key]));
27
+ }
28
+ });
29
+ return paths;
30
+ };
31
+ const syncFunc = ({ contract, transformSchema, jsonQuery, }) => {
32
+ const paths = getPathsFromRouter(contract);
33
+ const results = [];
34
+ for (const path of paths) {
35
+ const concatenatedPath = [...path.paths, path.id].join('.');
36
+ const pathParams = path_params_1.getPathParameterSchema.sync({
37
+ transformSchema,
38
+ appRoute: path.route,
39
+ id: path.id,
40
+ concatenatedPath,
41
+ });
42
+ const headerParams = headers_1.getHeaderParameterSchema.sync({
43
+ transformSchema,
44
+ appRoute: path.route,
45
+ id: path.id,
46
+ concatenatedPath,
47
+ });
48
+ const querySchema = query_params_1.getQueryParameterSchema.sync({
49
+ transformSchema,
50
+ appRoute: path.route,
51
+ id: path.id,
52
+ concatenatedPath,
53
+ jsonQuery: !!jsonQuery,
54
+ });
55
+ const bodySchema = body_1.getBodySchema.sync({
56
+ transformSchema,
57
+ appRoute: path.route,
58
+ id: path.id,
59
+ concatenatedPath,
60
+ });
61
+ const responses = {};
62
+ for (const [statusCode, _response] of Object.entries(path.route.responses)) {
63
+ const schemaValidator = (0, core_1.isAppRouteOtherResponse)(_response)
64
+ ? _response.body
65
+ : _response;
66
+ const responseSchema = transformSchema({
67
+ schema: schemaValidator,
68
+ appRoute: path.route,
69
+ id: path.id,
70
+ concatenatedPath,
71
+ type: 'response',
72
+ });
73
+ if (responseSchema) {
74
+ responses[statusCode] = responseSchema;
75
+ }
76
+ }
77
+ results.push(Object.assign(Object.assign({}, path), { schemaResults: {
78
+ path: pathParams,
79
+ headers: headerParams,
80
+ query: querySchema,
81
+ body: bodySchema,
82
+ responses,
83
+ } }));
84
+ }
85
+ return results;
86
+ };
87
+ const asyncFunc = async ({ contract, transformSchema, jsonQuery, }) => {
88
+ const paths = getPathsFromRouter(contract);
89
+ const results = [];
90
+ for (const path of paths) {
91
+ const concatenatedPath = [...path.paths, path.id].join('.');
92
+ const pathParams = await path_params_1.getPathParameterSchema.async({
93
+ transformSchema,
94
+ appRoute: path.route,
95
+ id: path.id,
96
+ concatenatedPath,
97
+ });
98
+ const headerParams = await headers_1.getHeaderParameterSchema.async({
99
+ transformSchema,
100
+ appRoute: path.route,
101
+ id: path.id,
102
+ concatenatedPath,
103
+ });
104
+ const querySchema = await query_params_1.getQueryParameterSchema.async({
105
+ transformSchema,
106
+ appRoute: path.route,
107
+ id: path.id,
108
+ concatenatedPath,
109
+ jsonQuery: !!jsonQuery,
110
+ });
111
+ const bodySchema = await body_1.getBodySchema.async({
112
+ transformSchema,
113
+ appRoute: path.route,
114
+ id: path.id,
115
+ concatenatedPath,
116
+ });
117
+ const responses = {};
118
+ for (const [statusCode, _response] of Object.entries(path.route.responses)) {
119
+ const schemaValidator = (0, core_1.isAppRouteOtherResponse)(_response)
120
+ ? _response.body
121
+ : _response;
122
+ const responseSchema = await transformSchema({
123
+ schema: schemaValidator,
124
+ appRoute: path.route,
125
+ id: path.id,
126
+ concatenatedPath,
127
+ type: 'response',
128
+ });
129
+ if (responseSchema) {
130
+ responses[statusCode] = responseSchema;
131
+ }
132
+ }
133
+ results.push(Object.assign(Object.assign({}, path), { schemaResults: {
134
+ path: pathParams,
135
+ headers: headerParams,
136
+ query: querySchema,
137
+ body: bodySchema,
138
+ responses,
139
+ } }));
140
+ }
141
+ return results;
142
+ };
143
+ exports.performContractTraversal = {
144
+ sync: syncFunc,
145
+ async: asyncFunc,
146
+ };
147
+ //# sourceMappingURL=contract-traversal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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ncHelper, SchemaTransformerAsync, SchemaTransformerSync } from '../types';
3
+ import { SchemaObject } from 'openapi3-ts';
4
+ type GetBodySchemaHelper = AsyncAndSyncHelper<{
5
+ appRoute: AppRoute;
6
+ id: string;
7
+ concatenatedPath: string;
8
+ }, {
9
+ transformSchema: SchemaTransformerSync;
10
+ }, {
11
+ transformSchema: SchemaTransformerAsync;
12
+ }, SchemaObject | null>;
13
+ export declare const getBodySchema: GetBodySchemaHelper;
14
+ export {};
15
+ //# sourceMappingURL=body.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EACL,kBAAkB,EAGlB,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,KAAK,mBAAmB,GAAG,kBAAkB,CAC3C;IACE,QAAQ,EAAE,QAAQ,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB,EAAE,MAAM,CAAC;CAC1B,EACD;IACE,eAAe,EAAE,qBAAqB,CAAC;CACxC,EACD;IACE,eAAe,EAAE,sBAAsB,CAAC;CACzC,EACD,YAAY,GAAG,IAAI,CACpB,CAAC;AA4CF,eAAO,MAAM,aAAa,EAAE,mBAG3B,CAAC"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBodySchema = void 0;
4
+ const syncFunc = ({ transformSchema, appRoute, id, concatenatedPath, }) => {
5
+ const schema = 'body' in appRoute ? appRoute.body : undefined;
6
+ const transformedSchema = transformSchema({
7
+ schema,
8
+ appRoute,
9
+ id,
10
+ concatenatedPath,
11
+ type: 'body',
12
+ });
13
+ if (!transformedSchema) {
14
+ return null;
15
+ }
16
+ return transformedSchema;
17
+ };
18
+ const asyncFunc = async ({ transformSchema, appRoute, id, concatenatedPath, }) => {
19
+ const schema = 'body' in appRoute ? appRoute.body : undefined;
20
+ const transformedSchema = await transformSchema({
21
+ schema,
22
+ appRoute,
23
+ id,
24
+ concatenatedPath,
25
+ type: 'body',
26
+ });
27
+ return transformedSchema;
28
+ };
29
+ exports.getBodySchema = {
30
+ sync: syncFunc,
31
+ async: asyncFunc,
32
+ };
33
+ //# sourceMappingURL=body.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body.js","sourceRoot":"","sources":["../../../src/lib/parsers/body.ts"],"names":[],"mappings":";;;AAyBA,MAAM,QAAQ,GAAyC,CAAC,EACtD,eAAe,EACf,QAAQ,EACR,EAAE,EACF,gBAAgB,GACjB,EAAE,EAAE;IACH,MAAM,MAAM,GAAG,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAE9D,MAAM,iBAAiB,GAAG,eAAe,CAAC;QACxC,MAAM;QACN,QAAQ;QACR,EAAE;QACF,gBAAgB;QAChB,IAAI,EAAE,MAAM;KACb,CAAC,CAAC;IAEH,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,SAAS,GAA0C,KAAK,EAAE,EAC9D,eAAe,EACf,QAAQ,EACR,EAAE,EACF,gBAAgB,GACjB,EAAE,EAAE;IACH,MAAM,MAAM,GAAG,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAE9D,MAAM,iBAAiB,GAAG,MAAM,eAAe,CAAC;QAC9C,MAAM;QACN,QAAQ;QACR,EAAE;QACF,gBAAgB;QAChB,IAAI,EAAE,MAAM;KACb,CAAC,CAAC;IAEH,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAEW,QAAA,aAAa,GAAwB;IAChD,IAAI,EAAE,QAAQ;IACd,KAAK,EAAE,SAAS;CACjB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { AppRoute } from '@ts-rest/core';
2
+ import { AsyncAndSyncHelper, SchemaTransformerAsync, SchemaTransformerSync } from '../types';
3
+ import { ParameterObject } from 'openapi3-ts';
4
+ type GetHeaderParameterHelper = AsyncAndSyncHelper<{
5
+ appRoute: AppRoute;
6
+ id: string;
7
+ concatenatedPath: string;
8
+ }, {
9
+ transformSchema: SchemaTransformerSync;
10
+ }, {
11
+ transformSchema: SchemaTransformerAsync;
12
+ }, Array<ParameterObject>>;
13
+ export declare const getHeaderParameterSchema: GetHeaderParameterHelper;
14
+ export {};
15
+ //# sourceMappingURL=headers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAe,MAAM,eAAe,CAAC;AACtD,OAAO,EACL,kBAAkB,EAIlB,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,KAAK,wBAAwB,GAAG,kBAAkB,CAChD;IACE,QAAQ,EAAE,QAAQ,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB,EAAE,MAAM,CAAC;CAC1B,EACD;IACE,eAAe,EAAE,qBAAqB,CAAC;CACxC,EACD;IACE,eAAe,EAAE,sBAAsB,CAAC;CACzC,EACD,KAAK,CAAC,eAAe,CAAC,CACvB,CAAC;AAwIF,eAAO,MAAM,wBAAwB,EAAE,wBAGtC,CAAC"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHeaderParameterSchema = void 0;
4
+ const core_1 = require("@ts-rest/core");
5
+ const types_1 = require("../types");
6
+ const utils_1 = require("./utils");
7
+ const syncFunc = ({ transformSchema, appRoute, id, concatenatedPath, }) => {
8
+ const schema = appRoute.headers;
9
+ if (schema === null) {
10
+ return [];
11
+ }
12
+ if (schema === undefined) {
13
+ return [];
14
+ }
15
+ if (typeof schema === 'symbol') {
16
+ return [];
17
+ }
18
+ if ((0, core_1.isZodObject)(schema)) {
19
+ const transformedSchema = transformSchema({
20
+ schema,
21
+ appRoute,
22
+ id,
23
+ concatenatedPath,
24
+ type: 'header',
25
+ });
26
+ if (!transformedSchema) {
27
+ return [];
28
+ }
29
+ return (0, utils_1.schemaObjectToParameters)(transformedSchema, 'header');
30
+ }
31
+ const parameters = [];
32
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
+ for (const [key, subSchema] of Object.entries(schema)) {
34
+ if ((0, types_1.isStandardSchema)(subSchema)) {
35
+ const transformedSchema = transformSchema({
36
+ schema: subSchema,
37
+ appRoute,
38
+ id,
39
+ concatenatedPath,
40
+ type: 'header',
41
+ });
42
+ if (!transformedSchema) {
43
+ return [];
44
+ }
45
+ parameters.push(...(0, utils_1.schemaObjectToParameters)(transformedSchema, 'header'));
46
+ }
47
+ }
48
+ return parameters;
49
+ };
50
+ const asyncFunc = async ({ transformSchema, appRoute, id, concatenatedPath, }) => {
51
+ var _a;
52
+ const schema = appRoute.headers;
53
+ if (schema === null) {
54
+ return [];
55
+ }
56
+ if (schema === undefined) {
57
+ return [];
58
+ }
59
+ if (typeof schema === 'symbol') {
60
+ return [];
61
+ }
62
+ if ((0, core_1.isZodObject)(schema)) {
63
+ const transformedSchema = await transformSchema({
64
+ schema,
65
+ appRoute,
66
+ id,
67
+ concatenatedPath,
68
+ type: 'header',
69
+ });
70
+ if (!transformedSchema) {
71
+ return [];
72
+ }
73
+ return (0, utils_1.schemaObjectToParameters)(transformedSchema, 'header');
74
+ }
75
+ const parameters = [];
76
+ for (const [key, subSchema] of Object.entries(schema)) {
77
+ if ((0, types_1.isStandardSchema)(subSchema)) {
78
+ const transformedSchema = await transformSchema({
79
+ schema: subSchema,
80
+ appRoute,
81
+ id,
82
+ concatenatedPath,
83
+ type: 'header',
84
+ });
85
+ if (!transformedSchema) {
86
+ continue;
87
+ }
88
+ const validateEmptyResult = subSchema['~standard'].validate(undefined);
89
+ if (validateEmptyResult instanceof Promise) {
90
+ throw new Error('Schema validation must be synchronous');
91
+ }
92
+ const isRequired = Boolean((_a = validateEmptyResult.issues) === null || _a === void 0 ? void 0 : _a.length);
93
+ const asParameter = (0, utils_1.schemaToParameter)(transformedSchema, 'header', isRequired, key, false);
94
+ parameters.push(asParameter);
95
+ }
96
+ }
97
+ return parameters;
98
+ };
99
+ exports.getHeaderParameterSchema = {
100
+ sync: syncFunc,
101
+ async: asyncFunc,
102
+ };
103
+ //# sourceMappingURL=headers.js.map