fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

test: add orpc contract test folder

Lubos a9764e72 6b17c2d0

+537 -1405
+6 -8
packages/codegen-core/.gitignore
··· 1 1 .DS_Store 2 2 .idea 3 - .tsdown 4 3 .tmp 5 - junit.xml 4 + .tsdown 6 5 logs 7 6 node_modules 8 - npm-debug.log* 9 7 temp 10 - yarn-debug.log* 11 - yarn-error.log* 12 8 13 - *.iml 9 + .env 10 + coverage 14 11 dist 15 - coverage 16 - .env 12 + 13 + # test files 14 + .gen
+4 -9
packages/openapi-python-tests/pydantic/v2/.gitignore
··· 1 1 .DS_Store 2 2 .idea 3 - .tsdown 4 3 .tmp 5 - junit.xml 4 + .tsdown 6 5 logs 7 6 node_modules 8 - npm-debug.log* 9 7 temp 10 - yarn-debug.log* 11 - yarn-error.log* 12 8 13 - *.iml 14 - dist 9 + .env 15 10 coverage 16 - .env 11 + dist 17 12 18 13 # test files 19 - .gen/ 14 + .gen
+4 -9
packages/openapi-python-tests/sdks/.gitignore
··· 1 1 .DS_Store 2 2 .idea 3 - .tsdown 4 3 .tmp 5 - junit.xml 4 + .tsdown 6 5 logs 7 6 node_modules 8 - npm-debug.log* 9 7 temp 10 - yarn-debug.log* 11 - yarn-error.log* 12 8 13 - *.iml 14 - dist 9 + .env 15 10 coverage 16 - .env 11 + dist 17 12 18 13 # test files 19 - .gen/ 14 + .gen
+9
packages/openapi-ts-tests/@orpc/contract/v1/.gitignore
··· 1 + .DS_Store 2 + .idea 3 + .tmp 4 + logs 5 + node_modules 6 + 7 + .env 8 + coverage 9 + dist
+18
packages/openapi-ts-tests/@orpc/contract/v1/package.json
··· 1 + { 2 + "name": "@test/openapi-ts-orpc-contract-v1", 3 + "version": "0.0.0", 4 + "private": true, 5 + "type": "module", 6 + "scripts": { 7 + "typecheck": "tsgo --noEmit" 8 + }, 9 + "devDependencies": { 10 + "@hey-api/openapi-ts": "workspace:*", 11 + "@orpc/contract": "1.13.4", 12 + "typescript": "5.9.3", 13 + "zod": "4.3.6" 14 + }, 15 + "engines": { 16 + "node": ">=20.19.0" 17 + } 18 + }
+70
packages/openapi-ts-tests/@orpc/contract/v1/test/3.0.x.test.ts
··· 1 + import fs from 'node:fs'; 2 + import path from 'node:path'; 3 + 4 + import { createClient } from '@hey-api/openapi-ts'; 5 + 6 + import { getFilePaths } from '../../../../utils'; 7 + import { snapshotsDir, tmpDir } from './constants'; 8 + import { createOrpcContractConfig } from './utils'; 9 + 10 + const version = '3.0.x'; 11 + 12 + const outputDir = path.join(tmpDir, version); 13 + 14 + describe(`OpenAPI ${version}`, () => { 15 + const createConfig = createOrpcContractConfig({ openApiVersion: version, outputDir }); 16 + 17 + const scenarios = [ 18 + { 19 + config: createConfig({ 20 + input: 'orpc-contract.yaml', 21 + output: 'default', 22 + }), 23 + description: 'generate oRPC contracts with Zod schemas', 24 + }, 25 + { 26 + config: createConfig({ 27 + input: 'orpc-contract.yaml', 28 + output: 'custom-contract-name', 29 + plugins: [ 30 + 'zod', 31 + { 32 + contractNameBuilder: (id: string) => `${id}Rpc`, 33 + name: '@orpc/contract', 34 + }, 35 + ], 36 + }), 37 + description: 'generate oRPC contracts with custom contract name builder', 38 + }, 39 + { 40 + config: createConfig({ 41 + input: 'orpc-contract.yaml', 42 + output: 'custom-router-name', 43 + plugins: [ 44 + 'zod', 45 + { 46 + name: '@orpc/contract', 47 + routerName: 'contract', 48 + }, 49 + ], 50 + }), 51 + description: 'generate oRPC contracts with custom router name', 52 + }, 53 + ]; 54 + 55 + it.each(scenarios)('$description', async ({ config }) => { 56 + await createClient(config); 57 + 58 + const outputString = config.output as string; 59 + const filePaths = getFilePaths(outputString); 60 + 61 + await Promise.all( 62 + filePaths.map(async (filePath) => { 63 + const fileContent = fs.readFileSync(filePath, 'utf-8'); 64 + await expect(fileContent).toMatchFileSnapshot( 65 + path.join(snapshotsDir, version, filePath.slice(outputDir.length + 1)), 66 + ); 67 + }), 68 + ); 69 + }); 70 + });
+69
packages/openapi-ts-tests/@orpc/contract/v1/test/3.1.x.test.ts
··· 1 + import fs from 'node:fs'; 2 + import path from 'node:path'; 3 + 4 + import { createClient } from '@hey-api/openapi-ts'; 5 + 6 + import { getFilePaths } from '../../../../utils'; 7 + import { snapshotsDir, tmpDir } from './constants'; 8 + import { createOrpcContractConfig } from './utils'; 9 + 10 + const version = '3.1.x'; 11 + 12 + const outputDir = path.join(tmpDir, version); 13 + 14 + describe(`OpenAPI ${version}`, () => { 15 + const createConfig = createOrpcContractConfig({ openApiVersion: version, outputDir }); 16 + 17 + const scenarios = [ 18 + { 19 + config: createConfig({ 20 + input: 'orpc-contract.yaml', 21 + output: 'default', 22 + }), 23 + description: 'generate oRPC contracts with Zod schemas', 24 + }, 25 + { 26 + config: createConfig({ 27 + input: 'orpc-contract.yaml', 28 + output: 'custom-contract-name', 29 + plugins: [ 30 + 'zod', 31 + { 32 + contractNameBuilder: (id: string) => `${id}Rpc`, 33 + name: '@orpc/contract', 34 + }, 35 + ], 36 + }), 37 + description: 'generate oRPC contracts with custom contract name builder', 38 + }, 39 + { 40 + config: createConfig({ 41 + input: 'orpc-contract.yaml', 42 + output: 'custom-router-name', 43 + plugins: [ 44 + 'zod', 45 + { 46 + name: '@orpc/contract', 47 + routerName: 'contract', 48 + }, 49 + ], 50 + }), 51 + description: 'generate oRPC contracts with custom router name', 52 + }, 53 + ]; 54 + 55 + it.each(scenarios)('$description', async ({ config }) => { 56 + await createClient(config); 57 + 58 + const filePaths = getFilePaths(config.output as string); 59 + 60 + await Promise.all( 61 + filePaths.map(async (filePath) => { 62 + const fileContent = fs.readFileSync(filePath, 'utf-8'); 63 + await expect(fileContent).toMatchFileSnapshot( 64 + path.join(snapshotsDir, version, filePath.slice(outputDir.length + 1)), 65 + ); 66 + }), 67 + ); 68 + }); 69 + });
+4
packages/openapi-ts-tests/@orpc/contract/v1/test/constants.ts
··· 1 + import path from 'node:path'; 2 + 3 + export const snapshotsDir = path.join(__dirname, '..', '__snapshots__'); 4 + export const tmpDir = path.join(__dirname, '..', '.tmp');
+7
packages/openapi-ts-tests/@orpc/contract/v1/test/globalTeardown.ts
··· 1 + import fs from 'node:fs'; 2 + 3 + import { tmpDir } from './constants'; 4 + 5 + export function teardown() { 6 + fs.rmSync(tmpDir, { force: true, recursive: true }); 7 + }
+31
packages/openapi-ts-tests/@orpc/contract/v1/test/utils.ts
··· 1 + import path from 'node:path'; 2 + 3 + import type { UserConfig } from '@hey-api/openapi-ts'; 4 + 5 + import { getSpecsPath } from '../../../../utils'; 6 + 7 + export const createOrpcContractConfig = 8 + ({ openApiVersion, outputDir }: { openApiVersion: string; outputDir: string }) => 9 + (userConfig: UserConfig) => { 10 + const input = userConfig.input instanceof Array ? userConfig.input[0]! : userConfig.input; 11 + const inputPath = path.join( 12 + getSpecsPath(), 13 + openApiVersion, 14 + typeof input === 'string' ? input : (input.path as string), 15 + ); 16 + const output = userConfig.output instanceof Array ? userConfig.output[0]! : userConfig.output; 17 + const outputPath = typeof output === 'string' ? output : (output?.path ?? ''); 18 + return { 19 + plugins: ['zod', '@orpc/contract'], 20 + ...userConfig, 21 + input: 22 + typeof userConfig.input === 'string' 23 + ? inputPath 24 + : { 25 + ...userConfig.input, 26 + path: inputPath, 27 + }, 28 + logs: { level: 'silent', path: './logs' }, 29 + output: path.join(outputDir, outputPath), 30 + } as UserConfig; 31 + };
+6
packages/openapi-ts-tests/@orpc/contract/v1/tsconfig.json
··· 1 + { 2 + "extends": "../../../tsconfig.base.json", 3 + "include": ["test/**/*", "__snapshots__/**/*"], 4 + "exclude": [".gen/**/*"], 5 + "references": [{ "path": "../../../../openapi-ts" }] 6 + }
+10
packages/openapi-ts-tests/@orpc/contract/v1/turbo.json
··· 1 + { 2 + "$schema": "../../../../../node_modules/turbo/schema.json", 3 + "extends": ["//"], 4 + "tasks": { 5 + "build": { 6 + "dependsOn": [], 7 + "outputs": ["dist/**"] 8 + } 9 + } 10 + }
+7
packages/openapi-ts-tests/@orpc/contract/v1/vitest.setup.ts
··· 1 + import { fileURLToPath } from 'node:url'; 2 + 3 + import { beforeAll } from 'vitest'; 4 + 5 + beforeAll(() => { 6 + process.chdir(fileURLToPath(new URL('.', import.meta.url))); 7 + });
+4 -9
packages/openapi-ts-tests/main/.gitignore
··· 1 1 .DS_Store 2 2 .idea 3 - .tsdown 4 3 .tmp 5 - junit.xml 4 + .tsdown 6 5 logs 7 6 node_modules 8 - npm-debug.log* 9 7 temp 10 - yarn-debug.log* 11 - yarn-error.log* 12 8 13 - *.iml 14 - dist 9 + .env 15 10 coverage 16 - .env 11 + dist 17 12 18 13 # test files 19 - .gen/ 14 + .gen 20 15 test/generated 21 16 generated/
-56
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/zod/custom-contract-name/@orpc/contract.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import { oc } from '@orpc/contract'; 4 - 5 - import { zFooBarPostResponse, zFooBarPutResponse, zFooPostResponse, zFooPutResponse, zGetFooBarResponse, zGetFooResponse } from '../zod.gen'; 6 - 7 - export const base = oc.$route({ inputStructure: 'detailed' }); 8 - 9 - export const getFooRpc = base.route({ 10 - method: 'GET', 11 - path: '/foo', 12 - tags: ['fooBaz'] 13 - }).output(zGetFooResponse); 14 - 15 - export const fooPostRpc = base.route({ 16 - method: 'POST', 17 - path: '/foo', 18 - operationId: 'foo.-post', 19 - tags: ['fooBaz'] 20 - }).output(zFooPostResponse); 21 - 22 - export const fooPutRpc = base.route({ 23 - method: 'PUT', 24 - path: '/foo', 25 - operationId: '/foo/-put/', 26 - tags: ['fooBaz'] 27 - }).output(zFooPutResponse); 28 - 29 - export const getFooBarRpc = base.route({ 30 - method: 'GET', 31 - path: '/foo/bar', 32 - tags: ['barBaz'] 33 - }).output(zGetFooBarResponse); 34 - 35 - export const fooBarPostRpc = base.route({ 36 - method: 'POST', 37 - path: '/foo/bar', 38 - operationId: 'foo.bar.post', 39 - tags: ['fooBaz', 'barBaz'] 40 - }).output(zFooBarPostResponse); 41 - 42 - export const fooBarPutRpc = base.route({ 43 - method: 'PUT', 44 - path: '/foo/bar', 45 - operationId: '/foo/bar/put/', 46 - tags: ['fooBaz', 'barBaz'] 47 - }).output(zFooBarPutResponse); 48 - 49 - export const router = { 50 - getFoo: getFooRpc, 51 - post: fooBarPostRpc, 52 - put: fooBarPutRpc, 53 - getFooBar: getFooBarRpc 54 - }; 55 - 56 - export type Router = typeof router;
-69
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/zod/custom-contract-name/zod.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import { z } from 'zod'; 4 - 5 - export const zGetFooData = z.object({ 6 - body: z.optional(z.never()), 7 - path: z.optional(z.never()), 8 - query: z.optional(z.never()) 9 - }); 10 - 11 - /** 12 - * OK 13 - */ 14 - export const zGetFooResponse = z.string(); 15 - 16 - export const zFooPostData = z.object({ 17 - body: z.optional(z.never()), 18 - path: z.optional(z.never()), 19 - query: z.optional(z.never()) 20 - }); 21 - 22 - /** 23 - * OK 24 - */ 25 - export const zFooPostResponse = z.string(); 26 - 27 - export const zFooPutData = z.object({ 28 - body: z.optional(z.never()), 29 - path: z.optional(z.never()), 30 - query: z.optional(z.never()) 31 - }); 32 - 33 - /** 34 - * OK 35 - */ 36 - export const zFooPutResponse = z.string(); 37 - 38 - export const zGetFooBarData = z.object({ 39 - body: z.optional(z.never()), 40 - path: z.optional(z.never()), 41 - query: z.optional(z.never()) 42 - }); 43 - 44 - /** 45 - * OK 46 - */ 47 - export const zGetFooBarResponse = z.string(); 48 - 49 - export const zFooBarPostData = z.object({ 50 - body: z.optional(z.never()), 51 - path: z.optional(z.never()), 52 - query: z.optional(z.never()) 53 - }); 54 - 55 - /** 56 - * OK 57 - */ 58 - export const zFooBarPostResponse = z.string(); 59 - 60 - export const zFooBarPutData = z.object({ 61 - body: z.optional(z.never()), 62 - path: z.optional(z.never()), 63 - query: z.optional(z.never()) 64 - }); 65 - 66 - /** 67 - * OK 68 - */ 69 - export const zFooBarPutResponse = z.string();
-56
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/zod/custom-group-key/@orpc/contract.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import { oc } from '@orpc/contract'; 4 - 5 - import { zFooBarPostResponse, zFooBarPutResponse, zFooPostResponse, zFooPutResponse, zGetFooBarResponse, zGetFooResponse } from '../zod.gen'; 6 - 7 - export const base = oc.$route({ inputStructure: 'detailed' }); 8 - 9 - export const getFooContract = base.route({ 10 - method: 'GET', 11 - path: '/foo', 12 - tags: ['fooBaz'] 13 - }).output(zGetFooResponse); 14 - 15 - export const fooPostContract = base.route({ 16 - method: 'POST', 17 - path: '/foo', 18 - operationId: 'foo.-post', 19 - tags: ['fooBaz'] 20 - }).output(zFooPostResponse); 21 - 22 - export const fooPutContract = base.route({ 23 - method: 'PUT', 24 - path: '/foo', 25 - operationId: '/foo/-put/', 26 - tags: ['fooBaz'] 27 - }).output(zFooPutResponse); 28 - 29 - export const getFooBarContract = base.route({ 30 - method: 'GET', 31 - path: '/foo/bar', 32 - tags: ['barBaz'] 33 - }).output(zGetFooBarResponse); 34 - 35 - export const fooBarPostContract = base.route({ 36 - method: 'POST', 37 - path: '/foo/bar', 38 - operationId: 'foo.bar.post', 39 - tags: ['fooBaz', 'barBaz'] 40 - }).output(zFooBarPostResponse); 41 - 42 - export const fooBarPutContract = base.route({ 43 - method: 'PUT', 44 - path: '/foo/bar', 45 - operationId: '/foo/bar/put/', 46 - tags: ['fooBaz', 'barBaz'] 47 - }).output(zFooBarPutResponse); 48 - 49 - export const router = { 50 - getFoo: getFooContract, 51 - post: fooBarPostContract, 52 - put: fooBarPutContract, 53 - getFooBar: getFooBarContract 54 - }; 55 - 56 - export type Router = typeof router;
-69
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/zod/custom-group-key/zod.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import { z } from 'zod'; 4 - 5 - export const zGetFooData = z.object({ 6 - body: z.optional(z.never()), 7 - path: z.optional(z.never()), 8 - query: z.optional(z.never()) 9 - }); 10 - 11 - /** 12 - * OK 13 - */ 14 - export const zGetFooResponse = z.string(); 15 - 16 - export const zFooPostData = z.object({ 17 - body: z.optional(z.never()), 18 - path: z.optional(z.never()), 19 - query: z.optional(z.never()) 20 - }); 21 - 22 - /** 23 - * OK 24 - */ 25 - export const zFooPostResponse = z.string(); 26 - 27 - export const zFooPutData = z.object({ 28 - body: z.optional(z.never()), 29 - path: z.optional(z.never()), 30 - query: z.optional(z.never()) 31 - }); 32 - 33 - /** 34 - * OK 35 - */ 36 - export const zFooPutResponse = z.string(); 37 - 38 - export const zGetFooBarData = z.object({ 39 - body: z.optional(z.never()), 40 - path: z.optional(z.never()), 41 - query: z.optional(z.never()) 42 - }); 43 - 44 - /** 45 - * OK 46 - */ 47 - export const zGetFooBarResponse = z.string(); 48 - 49 - export const zFooBarPostData = z.object({ 50 - body: z.optional(z.never()), 51 - path: z.optional(z.never()), 52 - query: z.optional(z.never()) 53 - }); 54 - 55 - /** 56 - * OK 57 - */ 58 - export const zFooBarPostResponse = z.string(); 59 - 60 - export const zFooBarPutData = z.object({ 61 - body: z.optional(z.never()), 62 - path: z.optional(z.never()), 63 - query: z.optional(z.never()) 64 - }); 65 - 66 - /** 67 - * OK 68 - */ 69 - export const zFooBarPutResponse = z.string();
-56
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/zod/custom-router-name/@orpc/contract.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import { oc } from '@orpc/contract'; 4 - 5 - import { zFooBarPostResponse, zFooBarPutResponse, zFooPostResponse, zFooPutResponse, zGetFooBarResponse, zGetFooResponse } from '../zod.gen'; 6 - 7 - export const base = oc.$route({ inputStructure: 'detailed' }); 8 - 9 - export const getFooContract = base.route({ 10 - method: 'GET', 11 - path: '/foo', 12 - tags: ['fooBaz'] 13 - }).output(zGetFooResponse); 14 - 15 - export const fooPostContract = base.route({ 16 - method: 'POST', 17 - path: '/foo', 18 - operationId: 'foo.-post', 19 - tags: ['fooBaz'] 20 - }).output(zFooPostResponse); 21 - 22 - export const fooPutContract = base.route({ 23 - method: 'PUT', 24 - path: '/foo', 25 - operationId: '/foo/-put/', 26 - tags: ['fooBaz'] 27 - }).output(zFooPutResponse); 28 - 29 - export const getFooBarContract = base.route({ 30 - method: 'GET', 31 - path: '/foo/bar', 32 - tags: ['barBaz'] 33 - }).output(zGetFooBarResponse); 34 - 35 - export const fooBarPostContract = base.route({ 36 - method: 'POST', 37 - path: '/foo/bar', 38 - operationId: 'foo.bar.post', 39 - tags: ['fooBaz', 'barBaz'] 40 - }).output(zFooBarPostResponse); 41 - 42 - export const fooBarPutContract = base.route({ 43 - method: 'PUT', 44 - path: '/foo/bar', 45 - operationId: '/foo/bar/put/', 46 - tags: ['fooBaz', 'barBaz'] 47 - }).output(zFooBarPutResponse); 48 - 49 - export const contract = { 50 - getFoo: getFooContract, 51 - post: fooBarPostContract, 52 - put: fooBarPutContract, 53 - getFooBar: getFooBarContract 54 - }; 55 - 56 - export type Contract = typeof contract;
-69
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/zod/custom-router-name/zod.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import { z } from 'zod'; 4 - 5 - export const zGetFooData = z.object({ 6 - body: z.optional(z.never()), 7 - path: z.optional(z.never()), 8 - query: z.optional(z.never()) 9 - }); 10 - 11 - /** 12 - * OK 13 - */ 14 - export const zGetFooResponse = z.string(); 15 - 16 - export const zFooPostData = z.object({ 17 - body: z.optional(z.never()), 18 - path: z.optional(z.never()), 19 - query: z.optional(z.never()) 20 - }); 21 - 22 - /** 23 - * OK 24 - */ 25 - export const zFooPostResponse = z.string(); 26 - 27 - export const zFooPutData = z.object({ 28 - body: z.optional(z.never()), 29 - path: z.optional(z.never()), 30 - query: z.optional(z.never()) 31 - }); 32 - 33 - /** 34 - * OK 35 - */ 36 - export const zFooPutResponse = z.string(); 37 - 38 - export const zGetFooBarData = z.object({ 39 - body: z.optional(z.never()), 40 - path: z.optional(z.never()), 41 - query: z.optional(z.never()) 42 - }); 43 - 44 - /** 45 - * OK 46 - */ 47 - export const zGetFooBarResponse = z.string(); 48 - 49 - export const zFooBarPostData = z.object({ 50 - body: z.optional(z.never()), 51 - path: z.optional(z.never()), 52 - query: z.optional(z.never()) 53 - }); 54 - 55 - /** 56 - * OK 57 - */ 58 - export const zFooBarPostResponse = z.string(); 59 - 60 - export const zFooBarPutData = z.object({ 61 - body: z.optional(z.never()), 62 - path: z.optional(z.never()), 63 - query: z.optional(z.never()) 64 - }); 65 - 66 - /** 67 - * OK 68 - */ 69 - export const zFooBarPutResponse = z.string();
-56
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/zod/default/@orpc/contract.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import { oc } from '@orpc/contract'; 4 - 5 - import { zFooBarPostResponse, zFooBarPutResponse, zFooPostResponse, zFooPutResponse, zGetFooBarResponse, zGetFooResponse } from '../zod.gen'; 6 - 7 - export const base = oc.$route({ inputStructure: 'detailed' }); 8 - 9 - export const getFooContract = base.route({ 10 - method: 'GET', 11 - path: '/foo', 12 - tags: ['fooBaz'] 13 - }).output(zGetFooResponse); 14 - 15 - export const fooPostContract = base.route({ 16 - method: 'POST', 17 - path: '/foo', 18 - operationId: 'foo.-post', 19 - tags: ['fooBaz'] 20 - }).output(zFooPostResponse); 21 - 22 - export const fooPutContract = base.route({ 23 - method: 'PUT', 24 - path: '/foo', 25 - operationId: '/foo/-put/', 26 - tags: ['fooBaz'] 27 - }).output(zFooPutResponse); 28 - 29 - export const getFooBarContract = base.route({ 30 - method: 'GET', 31 - path: '/foo/bar', 32 - tags: ['barBaz'] 33 - }).output(zGetFooBarResponse); 34 - 35 - export const fooBarPostContract = base.route({ 36 - method: 'POST', 37 - path: '/foo/bar', 38 - operationId: 'foo.bar.post', 39 - tags: ['fooBaz', 'barBaz'] 40 - }).output(zFooBarPostResponse); 41 - 42 - export const fooBarPutContract = base.route({ 43 - method: 'PUT', 44 - path: '/foo/bar', 45 - operationId: '/foo/bar/put/', 46 - tags: ['fooBaz', 'barBaz'] 47 - }).output(zFooBarPutResponse); 48 - 49 - export const router = { 50 - getFoo: getFooContract, 51 - post: fooBarPostContract, 52 - put: fooBarPutContract, 53 - getFooBar: getFooBarContract 54 - }; 55 - 56 - export type Router = typeof router;
-69
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/zod/default/zod.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import { z } from 'zod'; 4 - 5 - export const zGetFooData = z.object({ 6 - body: z.optional(z.never()), 7 - path: z.optional(z.never()), 8 - query: z.optional(z.never()) 9 - }); 10 - 11 - /** 12 - * OK 13 - */ 14 - export const zGetFooResponse = z.string(); 15 - 16 - export const zFooPostData = z.object({ 17 - body: z.optional(z.never()), 18 - path: z.optional(z.never()), 19 - query: z.optional(z.never()) 20 - }); 21 - 22 - /** 23 - * OK 24 - */ 25 - export const zFooPostResponse = z.string(); 26 - 27 - export const zFooPutData = z.object({ 28 - body: z.optional(z.never()), 29 - path: z.optional(z.never()), 30 - query: z.optional(z.never()) 31 - }); 32 - 33 - /** 34 - * OK 35 - */ 36 - export const zFooPutResponse = z.string(); 37 - 38 - export const zGetFooBarData = z.object({ 39 - body: z.optional(z.never()), 40 - path: z.optional(z.never()), 41 - query: z.optional(z.never()) 42 - }); 43 - 44 - /** 45 - * OK 46 - */ 47 - export const zGetFooBarResponse = z.string(); 48 - 49 - export const zFooBarPostData = z.object({ 50 - body: z.optional(z.never()), 51 - path: z.optional(z.never()), 52 - query: z.optional(z.never()) 53 - }); 54 - 55 - /** 56 - * OK 57 - */ 58 - export const zFooBarPostResponse = z.string(); 59 - 60 - export const zFooBarPutData = z.object({ 61 - body: z.optional(z.never()), 62 - path: z.optional(z.never()), 63 - query: z.optional(z.never()) 64 - }); 65 - 66 - /** 67 - * OK 68 - */ 69 - export const zFooBarPutResponse = z.string();
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/zod/custom-contract-name/@orpc/contract.gen.ts packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.0.x/custom-contract-name/@orpc/contract.gen.ts
+38 -38
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/zod/custom-contract-name/zod.gen.ts packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.0.x/custom-contract-name/zod.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - import { z } from 'zod'; 3 + import * as z from 'zod'; 4 4 5 5 export const zUser = z.object({ 6 6 id: z.string(), 7 7 email: z.email(), 8 8 name: z.string(), 9 - createdAt: z.optional(z.iso.datetime()) 9 + createdAt: z.iso.datetime().optional() 10 10 }); 11 11 12 12 export const zCreateUserInput = z.object({ 13 13 email: z.email(), 14 14 name: z.string(), 15 - password: z.optional(z.string().min(8)) 15 + password: z.string().min(8).optional() 16 16 }); 17 17 18 18 export const zUpdateUserInput = z.object({ 19 - email: z.optional(z.email()), 20 - name: z.optional(z.string()) 19 + email: z.email().optional(), 20 + name: z.string().optional() 21 21 }); 22 22 23 23 export const zPost = z.object({ ··· 25 25 title: z.string(), 26 26 content: z.string(), 27 27 authorId: z.string(), 28 - status: z.optional(z.enum([ 28 + status: z.enum([ 29 29 'draft', 30 30 'published', 31 31 'archived' 32 - ])), 33 - createdAt: z.optional(z.iso.datetime()) 32 + ]).optional(), 33 + createdAt: z.iso.datetime().optional() 34 34 }); 35 35 36 36 export const zCreatePostInput = z.object({ 37 37 title: z.string(), 38 38 content: z.string(), 39 - status: z.optional(z.enum(['draft', 'published'])) 39 + status: z.enum(['draft', 'published']).optional() 40 40 }); 41 41 42 42 export const zGetUsersData = z.object({ 43 - body: z.optional(z.never()), 44 - path: z.optional(z.never()), 45 - query: z.optional(z.object({ 46 - limit: z.optional(z.int()).default(10), 47 - offset: z.optional(z.int()).default(0) 48 - })) 43 + body: z.never().optional(), 44 + path: z.never().optional(), 45 + query: z.object({ 46 + limit: z.int().optional().default(10), 47 + offset: z.int().optional().default(0) 48 + }).optional() 49 49 }); 50 50 51 51 /** ··· 55 55 56 56 export const zCreateUserData = z.object({ 57 57 body: zCreateUserInput, 58 - path: z.optional(z.never()), 59 - query: z.optional(z.never()) 58 + path: z.never().optional(), 59 + query: z.never().optional() 60 60 }); 61 61 62 62 /** ··· 65 65 export const zCreateUserResponse = zUser; 66 66 67 67 export const zDeleteUserData = z.object({ 68 - body: z.optional(z.never()), 68 + body: z.never().optional(), 69 69 path: z.object({ 70 70 userId: z.string() 71 71 }), 72 - query: z.optional(z.never()), 73 - headers: z.optional(z.object({ 74 - 'X-Request-Id': z.optional(z.string()) 75 - })) 72 + query: z.never().optional(), 73 + headers: z.object({ 74 + 'X-Request-Id': z.string().optional() 75 + }).optional() 76 76 }); 77 77 78 78 /** ··· 81 81 export const zDeleteUserResponse = z.void(); 82 82 83 83 export const zGetUserByIdData = z.object({ 84 - body: z.optional(z.never()), 84 + body: z.never().optional(), 85 85 path: z.object({ 86 86 userId: z.string() 87 87 }), 88 - query: z.optional(z.never()) 88 + query: z.never().optional() 89 89 }); 90 90 91 91 /** ··· 98 98 path: z.object({ 99 99 userId: z.string() 100 100 }), 101 - query: z.optional(z.never()) 101 + query: z.never().optional() 102 102 }); 103 103 104 104 /** ··· 107 107 export const zUpdateUserResponse = zUser; 108 108 109 109 export const zGetPostsData = z.object({ 110 - body: z.optional(z.never()), 111 - path: z.optional(z.never()), 112 - query: z.optional(z.object({ 113 - authorId: z.optional(z.string()), 114 - status: z.optional(z.enum([ 110 + body: z.never().optional(), 111 + path: z.never().optional(), 112 + query: z.object({ 113 + authorId: z.string().optional(), 114 + status: z.enum([ 115 115 'draft', 116 116 'published', 117 117 'archived' 118 - ])) 119 - })) 118 + ]).optional() 119 + }).optional() 120 120 }); 121 121 122 122 /** ··· 126 126 127 127 export const zCreatePostData = z.object({ 128 128 body: zCreatePostInput, 129 - path: z.optional(z.never()), 130 - query: z.optional(z.never()), 129 + path: z.never().optional(), 130 + query: z.never().optional(), 131 131 headers: z.object({ 132 132 'X-Author-Id': z.string() 133 133 }) ··· 139 139 export const zCreatePostResponse = zPost; 140 140 141 141 export const zGetPostByIdData = z.object({ 142 - body: z.optional(z.never()), 142 + body: z.never().optional(), 143 143 path: z.object({ 144 144 postId: z.string() 145 145 }), 146 - query: z.optional(z.object({ 147 - includeComments: z.optional(z.boolean()).default(false) 148 - })) 146 + query: z.object({ 147 + includeComments: z.boolean().optional().default(false) 148 + }).optional() 149 149 }); 150 150 151 151 /**
-110
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/zod/custom-group-key/@orpc/contract.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import { oc } from '@orpc/contract'; 4 - 5 - import { zCreatePostData, zCreatePostResponse, zCreateUserData, zCreateUserResponse, zDeleteUserData, zGetPostByIdData, zGetPostByIdResponse, zGetPostsData, zGetPostsResponse, zGetUserByIdData, zGetUserByIdResponse, zGetUsersData, zGetUsersResponse, zUpdateUserData, zUpdateUserResponse } from '../zod.gen'; 6 - 7 - export const base = oc.$route({ inputStructure: 'detailed' }); 8 - 9 - /** 10 - * Get all users 11 - */ 12 - export const getUsersContract = base.route({ 13 - method: 'GET', 14 - path: '/users', 15 - operationId: 'getUsers', 16 - summary: 'Get all users', 17 - tags: ['users'] 18 - }).input(zGetUsersData).output(zGetUsersResponse); 19 - 20 - /** 21 - * Create a new user 22 - */ 23 - export const createUserContract = base.route({ 24 - method: 'POST', 25 - path: '/users', 26 - operationId: 'createUser', 27 - summary: 'Create a new user', 28 - tags: ['users'], 29 - successStatus: 201 30 - }).input(zCreateUserData).output(zCreateUserResponse); 31 - 32 - /** 33 - * Delete a user 34 - */ 35 - export const deleteUserContract = base.route({ 36 - method: 'DELETE', 37 - path: '/users/{userId}', 38 - operationId: 'deleteUser', 39 - summary: 'Delete a user', 40 - tags: ['users'] 41 - }).input(zDeleteUserData); 42 - 43 - /** 44 - * Get a user by ID 45 - */ 46 - export const getUserByIdContract = base.route({ 47 - method: 'GET', 48 - path: '/users/{userId}', 49 - operationId: 'getUserById', 50 - summary: 'Get a user by ID', 51 - tags: ['users'] 52 - }).input(zGetUserByIdData).output(zGetUserByIdResponse); 53 - 54 - /** 55 - * Update a user 56 - */ 57 - export const updateUserContract = base.route({ 58 - method: 'PUT', 59 - path: '/users/{userId}', 60 - operationId: 'updateUser', 61 - summary: 'Update a user', 62 - tags: ['users'] 63 - }).input(zUpdateUserData).output(zUpdateUserResponse); 64 - 65 - /** 66 - * Get all posts 67 - */ 68 - export const getPostsContract = base.route({ 69 - method: 'GET', 70 - path: '/posts', 71 - operationId: 'getPosts', 72 - summary: 'Get all posts', 73 - tags: ['posts'] 74 - }).input(zGetPostsData).output(zGetPostsResponse); 75 - 76 - /** 77 - * Create a new post 78 - */ 79 - export const createPostContract = base.route({ 80 - method: 'POST', 81 - path: '/posts', 82 - operationId: 'createPost', 83 - summary: 'Create a new post', 84 - tags: ['posts'], 85 - successStatus: 201 86 - }).input(zCreatePostData).output(zCreatePostResponse); 87 - 88 - /** 89 - * Get a post by ID 90 - */ 91 - export const getPostByIdContract = base.route({ 92 - method: 'GET', 93 - path: '/posts/{postId}', 94 - operationId: 'getPostById', 95 - summary: 'Get a post by ID', 96 - tags: ['posts'] 97 - }).input(zGetPostByIdData).output(zGetPostByIdResponse); 98 - 99 - export const router = { 100 - getUsers: getUsersContract, 101 - createUser: createUserContract, 102 - deleteUser: deleteUserContract, 103 - getUserById: getUserByIdContract, 104 - updateUser: updateUserContract, 105 - getPosts: getPostsContract, 106 - createPost: createPostContract, 107 - getPostById: getPostByIdContract 108 - }; 109 - 110 - export type Router = typeof router;
-154
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/zod/custom-group-key/zod.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import { z } from 'zod'; 4 - 5 - export const zUser = z.object({ 6 - id: z.string(), 7 - email: z.email(), 8 - name: z.string(), 9 - createdAt: z.optional(z.iso.datetime()) 10 - }); 11 - 12 - export const zCreateUserInput = z.object({ 13 - email: z.email(), 14 - name: z.string(), 15 - password: z.optional(z.string().min(8)) 16 - }); 17 - 18 - export const zUpdateUserInput = z.object({ 19 - email: z.optional(z.email()), 20 - name: z.optional(z.string()) 21 - }); 22 - 23 - export const zPost = z.object({ 24 - id: z.string(), 25 - title: z.string(), 26 - content: z.string(), 27 - authorId: z.string(), 28 - status: z.optional(z.enum([ 29 - 'draft', 30 - 'published', 31 - 'archived' 32 - ])), 33 - createdAt: z.optional(z.iso.datetime()) 34 - }); 35 - 36 - export const zCreatePostInput = z.object({ 37 - title: z.string(), 38 - content: z.string(), 39 - status: z.optional(z.enum(['draft', 'published'])) 40 - }); 41 - 42 - export const zGetUsersData = z.object({ 43 - body: z.optional(z.never()), 44 - path: z.optional(z.never()), 45 - query: z.optional(z.object({ 46 - limit: z.optional(z.int()).default(10), 47 - offset: z.optional(z.int()).default(0) 48 - })) 49 - }); 50 - 51 - /** 52 - * List of users 53 - */ 54 - export const zGetUsersResponse = z.array(zUser); 55 - 56 - export const zCreateUserData = z.object({ 57 - body: zCreateUserInput, 58 - path: z.optional(z.never()), 59 - query: z.optional(z.never()) 60 - }); 61 - 62 - /** 63 - * User created 64 - */ 65 - export const zCreateUserResponse = zUser; 66 - 67 - export const zDeleteUserData = z.object({ 68 - body: z.optional(z.never()), 69 - path: z.object({ 70 - userId: z.string() 71 - }), 72 - query: z.optional(z.never()), 73 - headers: z.optional(z.object({ 74 - 'X-Request-Id': z.optional(z.string()) 75 - })) 76 - }); 77 - 78 - /** 79 - * User deleted 80 - */ 81 - export const zDeleteUserResponse = z.void(); 82 - 83 - export const zGetUserByIdData = z.object({ 84 - body: z.optional(z.never()), 85 - path: z.object({ 86 - userId: z.string() 87 - }), 88 - query: z.optional(z.never()) 89 - }); 90 - 91 - /** 92 - * User found 93 - */ 94 - export const zGetUserByIdResponse = zUser; 95 - 96 - export const zUpdateUserData = z.object({ 97 - body: zUpdateUserInput, 98 - path: z.object({ 99 - userId: z.string() 100 - }), 101 - query: z.optional(z.never()) 102 - }); 103 - 104 - /** 105 - * User updated 106 - */ 107 - export const zUpdateUserResponse = zUser; 108 - 109 - export const zGetPostsData = z.object({ 110 - body: z.optional(z.never()), 111 - path: z.optional(z.never()), 112 - query: z.optional(z.object({ 113 - authorId: z.optional(z.string()), 114 - status: z.optional(z.enum([ 115 - 'draft', 116 - 'published', 117 - 'archived' 118 - ])) 119 - })) 120 - }); 121 - 122 - /** 123 - * List of posts 124 - */ 125 - export const zGetPostsResponse = z.array(zPost); 126 - 127 - export const zCreatePostData = z.object({ 128 - body: zCreatePostInput, 129 - path: z.optional(z.never()), 130 - query: z.optional(z.never()), 131 - headers: z.object({ 132 - 'X-Author-Id': z.string() 133 - }) 134 - }); 135 - 136 - /** 137 - * Post created 138 - */ 139 - export const zCreatePostResponse = zPost; 140 - 141 - export const zGetPostByIdData = z.object({ 142 - body: z.optional(z.never()), 143 - path: z.object({ 144 - postId: z.string() 145 - }), 146 - query: z.optional(z.object({ 147 - includeComments: z.optional(z.boolean()).default(false) 148 - })) 149 - }); 150 - 151 - /** 152 - * Post found 153 - */ 154 - export const zGetPostByIdResponse = zPost;
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/zod/custom-router-name/@orpc/contract.gen.ts packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.0.x/custom-router-name/@orpc/contract.gen.ts
+38 -38
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/zod/custom-router-name/zod.gen.ts packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.0.x/custom-router-name/zod.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - import { z } from 'zod'; 3 + import * as z from 'zod'; 4 4 5 5 export const zUser = z.object({ 6 6 id: z.string(), 7 7 email: z.email(), 8 8 name: z.string(), 9 - createdAt: z.optional(z.iso.datetime()) 9 + createdAt: z.iso.datetime().optional() 10 10 }); 11 11 12 12 export const zCreateUserInput = z.object({ 13 13 email: z.email(), 14 14 name: z.string(), 15 - password: z.optional(z.string().min(8)) 15 + password: z.string().min(8).optional() 16 16 }); 17 17 18 18 export const zUpdateUserInput = z.object({ 19 - email: z.optional(z.email()), 20 - name: z.optional(z.string()) 19 + email: z.email().optional(), 20 + name: z.string().optional() 21 21 }); 22 22 23 23 export const zPost = z.object({ ··· 25 25 title: z.string(), 26 26 content: z.string(), 27 27 authorId: z.string(), 28 - status: z.optional(z.enum([ 28 + status: z.enum([ 29 29 'draft', 30 30 'published', 31 31 'archived' 32 - ])), 33 - createdAt: z.optional(z.iso.datetime()) 32 + ]).optional(), 33 + createdAt: z.iso.datetime().optional() 34 34 }); 35 35 36 36 export const zCreatePostInput = z.object({ 37 37 title: z.string(), 38 38 content: z.string(), 39 - status: z.optional(z.enum(['draft', 'published'])) 39 + status: z.enum(['draft', 'published']).optional() 40 40 }); 41 41 42 42 export const zGetUsersData = z.object({ 43 - body: z.optional(z.never()), 44 - path: z.optional(z.never()), 45 - query: z.optional(z.object({ 46 - limit: z.optional(z.int()).default(10), 47 - offset: z.optional(z.int()).default(0) 48 - })) 43 + body: z.never().optional(), 44 + path: z.never().optional(), 45 + query: z.object({ 46 + limit: z.int().optional().default(10), 47 + offset: z.int().optional().default(0) 48 + }).optional() 49 49 }); 50 50 51 51 /** ··· 55 55 56 56 export const zCreateUserData = z.object({ 57 57 body: zCreateUserInput, 58 - path: z.optional(z.never()), 59 - query: z.optional(z.never()) 58 + path: z.never().optional(), 59 + query: z.never().optional() 60 60 }); 61 61 62 62 /** ··· 65 65 export const zCreateUserResponse = zUser; 66 66 67 67 export const zDeleteUserData = z.object({ 68 - body: z.optional(z.never()), 68 + body: z.never().optional(), 69 69 path: z.object({ 70 70 userId: z.string() 71 71 }), 72 - query: z.optional(z.never()), 73 - headers: z.optional(z.object({ 74 - 'X-Request-Id': z.optional(z.string()) 75 - })) 72 + query: z.never().optional(), 73 + headers: z.object({ 74 + 'X-Request-Id': z.string().optional() 75 + }).optional() 76 76 }); 77 77 78 78 /** ··· 81 81 export const zDeleteUserResponse = z.void(); 82 82 83 83 export const zGetUserByIdData = z.object({ 84 - body: z.optional(z.never()), 84 + body: z.never().optional(), 85 85 path: z.object({ 86 86 userId: z.string() 87 87 }), 88 - query: z.optional(z.never()) 88 + query: z.never().optional() 89 89 }); 90 90 91 91 /** ··· 98 98 path: z.object({ 99 99 userId: z.string() 100 100 }), 101 - query: z.optional(z.never()) 101 + query: z.never().optional() 102 102 }); 103 103 104 104 /** ··· 107 107 export const zUpdateUserResponse = zUser; 108 108 109 109 export const zGetPostsData = z.object({ 110 - body: z.optional(z.never()), 111 - path: z.optional(z.never()), 112 - query: z.optional(z.object({ 113 - authorId: z.optional(z.string()), 114 - status: z.optional(z.enum([ 110 + body: z.never().optional(), 111 + path: z.never().optional(), 112 + query: z.object({ 113 + authorId: z.string().optional(), 114 + status: z.enum([ 115 115 'draft', 116 116 'published', 117 117 'archived' 118 - ])) 119 - })) 118 + ]).optional() 119 + }).optional() 120 120 }); 121 121 122 122 /** ··· 126 126 127 127 export const zCreatePostData = z.object({ 128 128 body: zCreatePostInput, 129 - path: z.optional(z.never()), 130 - query: z.optional(z.never()), 129 + path: z.never().optional(), 130 + query: z.never().optional(), 131 131 headers: z.object({ 132 132 'X-Author-Id': z.string() 133 133 }) ··· 139 139 export const zCreatePostResponse = zPost; 140 140 141 141 export const zGetPostByIdData = z.object({ 142 - body: z.optional(z.never()), 142 + body: z.never().optional(), 143 143 path: z.object({ 144 144 postId: z.string() 145 145 }), 146 - query: z.optional(z.object({ 147 - includeComments: z.optional(z.boolean()).default(false) 148 - })) 146 + query: z.object({ 147 + includeComments: z.boolean().optional().default(false) 148 + }).optional() 149 149 }); 150 150 151 151 /**
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/zod/default/@orpc/contract.gen.ts packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.0.x/default/@orpc/contract.gen.ts
+38 -38
packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/zod/default/zod.gen.ts packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.0.x/default/zod.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - import { z } from 'zod'; 3 + import * as z from 'zod'; 4 4 5 5 export const zUser = z.object({ 6 6 id: z.string(), 7 7 email: z.email(), 8 8 name: z.string(), 9 - createdAt: z.optional(z.iso.datetime()) 9 + createdAt: z.iso.datetime().optional() 10 10 }); 11 11 12 12 export const zCreateUserInput = z.object({ 13 13 email: z.email(), 14 14 name: z.string(), 15 - password: z.optional(z.string().min(8)) 15 + password: z.string().min(8).optional() 16 16 }); 17 17 18 18 export const zUpdateUserInput = z.object({ 19 - email: z.optional(z.email()), 20 - name: z.optional(z.string()) 19 + email: z.email().optional(), 20 + name: z.string().optional() 21 21 }); 22 22 23 23 export const zPost = z.object({ ··· 25 25 title: z.string(), 26 26 content: z.string(), 27 27 authorId: z.string(), 28 - status: z.optional(z.enum([ 28 + status: z.enum([ 29 29 'draft', 30 30 'published', 31 31 'archived' 32 - ])), 33 - createdAt: z.optional(z.iso.datetime()) 32 + ]).optional(), 33 + createdAt: z.iso.datetime().optional() 34 34 }); 35 35 36 36 export const zCreatePostInput = z.object({ 37 37 title: z.string(), 38 38 content: z.string(), 39 - status: z.optional(z.enum(['draft', 'published'])) 39 + status: z.enum(['draft', 'published']).optional() 40 40 }); 41 41 42 42 export const zGetUsersData = z.object({ 43 - body: z.optional(z.never()), 44 - path: z.optional(z.never()), 45 - query: z.optional(z.object({ 46 - limit: z.optional(z.int()).default(10), 47 - offset: z.optional(z.int()).default(0) 48 - })) 43 + body: z.never().optional(), 44 + path: z.never().optional(), 45 + query: z.object({ 46 + limit: z.int().optional().default(10), 47 + offset: z.int().optional().default(0) 48 + }).optional() 49 49 }); 50 50 51 51 /** ··· 55 55 56 56 export const zCreateUserData = z.object({ 57 57 body: zCreateUserInput, 58 - path: z.optional(z.never()), 59 - query: z.optional(z.never()) 58 + path: z.never().optional(), 59 + query: z.never().optional() 60 60 }); 61 61 62 62 /** ··· 65 65 export const zCreateUserResponse = zUser; 66 66 67 67 export const zDeleteUserData = z.object({ 68 - body: z.optional(z.never()), 68 + body: z.never().optional(), 69 69 path: z.object({ 70 70 userId: z.string() 71 71 }), 72 - query: z.optional(z.never()), 73 - headers: z.optional(z.object({ 74 - 'X-Request-Id': z.optional(z.string()) 75 - })) 72 + query: z.never().optional(), 73 + headers: z.object({ 74 + 'X-Request-Id': z.string().optional() 75 + }).optional() 76 76 }); 77 77 78 78 /** ··· 81 81 export const zDeleteUserResponse = z.void(); 82 82 83 83 export const zGetUserByIdData = z.object({ 84 - body: z.optional(z.never()), 84 + body: z.never().optional(), 85 85 path: z.object({ 86 86 userId: z.string() 87 87 }), 88 - query: z.optional(z.never()) 88 + query: z.never().optional() 89 89 }); 90 90 91 91 /** ··· 98 98 path: z.object({ 99 99 userId: z.string() 100 100 }), 101 - query: z.optional(z.never()) 101 + query: z.never().optional() 102 102 }); 103 103 104 104 /** ··· 107 107 export const zUpdateUserResponse = zUser; 108 108 109 109 export const zGetPostsData = z.object({ 110 - body: z.optional(z.never()), 111 - path: z.optional(z.never()), 112 - query: z.optional(z.object({ 113 - authorId: z.optional(z.string()), 114 - status: z.optional(z.enum([ 110 + body: z.never().optional(), 111 + path: z.never().optional(), 112 + query: z.object({ 113 + authorId: z.string().optional(), 114 + status: z.enum([ 115 115 'draft', 116 116 'published', 117 117 'archived' 118 - ])) 119 - })) 118 + ]).optional() 119 + }).optional() 120 120 }); 121 121 122 122 /** ··· 126 126 127 127 export const zCreatePostData = z.object({ 128 128 body: zCreatePostInput, 129 - path: z.optional(z.never()), 130 - query: z.optional(z.never()), 129 + path: z.never().optional(), 130 + query: z.never().optional(), 131 131 headers: z.object({ 132 132 'X-Author-Id': z.string() 133 133 }) ··· 139 139 export const zCreatePostResponse = zPost; 140 140 141 141 export const zGetPostByIdData = z.object({ 142 - body: z.optional(z.never()), 142 + body: z.never().optional(), 143 143 path: z.object({ 144 144 postId: z.string() 145 145 }), 146 - query: z.optional(z.object({ 147 - includeComments: z.optional(z.boolean()).default(false) 148 - })) 146 + query: z.object({ 147 + includeComments: z.boolean().optional().default(false) 148 + }).optional() 149 149 }); 150 150 151 151 /**
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/zod/custom-contract-name/@orpc/contract.gen.ts packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.1.x/custom-contract-name/@orpc/contract.gen.ts
+38 -38
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/zod/custom-contract-name/zod.gen.ts packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.1.x/custom-contract-name/zod.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - import { z } from 'zod'; 3 + import * as z from 'zod'; 4 4 5 5 export const zUser = z.object({ 6 6 id: z.string(), 7 7 email: z.email(), 8 8 name: z.string(), 9 - createdAt: z.optional(z.iso.datetime()) 9 + createdAt: z.iso.datetime().optional() 10 10 }); 11 11 12 12 export const zCreateUserInput = z.object({ 13 13 email: z.email(), 14 14 name: z.string(), 15 - password: z.optional(z.string().min(8)) 15 + password: z.string().min(8).optional() 16 16 }); 17 17 18 18 export const zUpdateUserInput = z.object({ 19 - email: z.optional(z.email()), 20 - name: z.optional(z.string()) 19 + email: z.email().optional(), 20 + name: z.string().optional() 21 21 }); 22 22 23 23 export const zPost = z.object({ ··· 25 25 title: z.string(), 26 26 content: z.string(), 27 27 authorId: z.string(), 28 - status: z.optional(z.enum([ 28 + status: z.enum([ 29 29 'draft', 30 30 'published', 31 31 'archived' 32 - ])), 33 - createdAt: z.optional(z.iso.datetime()) 32 + ]).optional(), 33 + createdAt: z.iso.datetime().optional() 34 34 }); 35 35 36 36 export const zCreatePostInput = z.object({ 37 37 title: z.string(), 38 38 content: z.string(), 39 - status: z.optional(z.enum(['draft', 'published'])) 39 + status: z.enum(['draft', 'published']).optional() 40 40 }); 41 41 42 42 export const zGetUsersData = z.object({ 43 - body: z.optional(z.never()), 44 - path: z.optional(z.never()), 45 - query: z.optional(z.object({ 46 - limit: z.optional(z.int()).default(10), 47 - offset: z.optional(z.int()).default(0) 48 - })) 43 + body: z.never().optional(), 44 + path: z.never().optional(), 45 + query: z.object({ 46 + limit: z.int().optional().default(10), 47 + offset: z.int().optional().default(0) 48 + }).optional() 49 49 }); 50 50 51 51 /** ··· 55 55 56 56 export const zCreateUserData = z.object({ 57 57 body: zCreateUserInput, 58 - path: z.optional(z.never()), 59 - query: z.optional(z.never()) 58 + path: z.never().optional(), 59 + query: z.never().optional() 60 60 }); 61 61 62 62 /** ··· 65 65 export const zCreateUserResponse = zUser; 66 66 67 67 export const zDeleteUserData = z.object({ 68 - body: z.optional(z.never()), 68 + body: z.never().optional(), 69 69 path: z.object({ 70 70 userId: z.string() 71 71 }), 72 - query: z.optional(z.never()), 73 - headers: z.optional(z.object({ 74 - 'X-Request-Id': z.optional(z.string()) 75 - })) 72 + query: z.never().optional(), 73 + headers: z.object({ 74 + 'X-Request-Id': z.string().optional() 75 + }).optional() 76 76 }); 77 77 78 78 /** ··· 81 81 export const zDeleteUserResponse = z.void(); 82 82 83 83 export const zGetUserByIdData = z.object({ 84 - body: z.optional(z.never()), 84 + body: z.never().optional(), 85 85 path: z.object({ 86 86 userId: z.string() 87 87 }), 88 - query: z.optional(z.never()) 88 + query: z.never().optional() 89 89 }); 90 90 91 91 /** ··· 98 98 path: z.object({ 99 99 userId: z.string() 100 100 }), 101 - query: z.optional(z.never()) 101 + query: z.never().optional() 102 102 }); 103 103 104 104 /** ··· 107 107 export const zUpdateUserResponse = zUser; 108 108 109 109 export const zGetPostsData = z.object({ 110 - body: z.optional(z.never()), 111 - path: z.optional(z.never()), 112 - query: z.optional(z.object({ 113 - authorId: z.optional(z.string()), 114 - status: z.optional(z.enum([ 110 + body: z.never().optional(), 111 + path: z.never().optional(), 112 + query: z.object({ 113 + authorId: z.string().optional(), 114 + status: z.enum([ 115 115 'draft', 116 116 'published', 117 117 'archived' 118 - ])) 119 - })) 118 + ]).optional() 119 + }).optional() 120 120 }); 121 121 122 122 /** ··· 126 126 127 127 export const zCreatePostData = z.object({ 128 128 body: zCreatePostInput, 129 - path: z.optional(z.never()), 130 - query: z.optional(z.never()), 129 + path: z.never().optional(), 130 + query: z.never().optional(), 131 131 headers: z.object({ 132 132 'X-Author-Id': z.string() 133 133 }) ··· 139 139 export const zCreatePostResponse = zPost; 140 140 141 141 export const zGetPostByIdData = z.object({ 142 - body: z.optional(z.never()), 142 + body: z.never().optional(), 143 143 path: z.object({ 144 144 postId: z.string() 145 145 }), 146 - query: z.optional(z.object({ 147 - includeComments: z.optional(z.boolean()).default(false) 148 - })) 146 + query: z.object({ 147 + includeComments: z.boolean().optional().default(false) 148 + }).optional() 149 149 }); 150 150 151 151 /**
-110
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/zod/custom-group-key/@orpc/contract.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import { oc } from '@orpc/contract'; 4 - 5 - import { zCreatePostData, zCreatePostResponse, zCreateUserData, zCreateUserResponse, zDeleteUserData, zGetPostByIdData, zGetPostByIdResponse, zGetPostsData, zGetPostsResponse, zGetUserByIdData, zGetUserByIdResponse, zGetUsersData, zGetUsersResponse, zUpdateUserData, zUpdateUserResponse } from '../zod.gen'; 6 - 7 - export const base = oc.$route({ inputStructure: 'detailed' }); 8 - 9 - /** 10 - * Get all users 11 - */ 12 - export const getUsersContract = base.route({ 13 - method: 'GET', 14 - path: '/users', 15 - operationId: 'getUsers', 16 - summary: 'Get all users', 17 - tags: ['users'] 18 - }).input(zGetUsersData).output(zGetUsersResponse); 19 - 20 - /** 21 - * Create a new user 22 - */ 23 - export const createUserContract = base.route({ 24 - method: 'POST', 25 - path: '/users', 26 - operationId: 'createUser', 27 - summary: 'Create a new user', 28 - tags: ['users'], 29 - successStatus: 201 30 - }).input(zCreateUserData).output(zCreateUserResponse); 31 - 32 - /** 33 - * Delete a user 34 - */ 35 - export const deleteUserContract = base.route({ 36 - method: 'DELETE', 37 - path: '/users/{userId}', 38 - operationId: 'deleteUser', 39 - summary: 'Delete a user', 40 - tags: ['users'] 41 - }).input(zDeleteUserData); 42 - 43 - /** 44 - * Get a user by ID 45 - */ 46 - export const getUserByIdContract = base.route({ 47 - method: 'GET', 48 - path: '/users/{userId}', 49 - operationId: 'getUserById', 50 - summary: 'Get a user by ID', 51 - tags: ['users'] 52 - }).input(zGetUserByIdData).output(zGetUserByIdResponse); 53 - 54 - /** 55 - * Update a user 56 - */ 57 - export const updateUserContract = base.route({ 58 - method: 'PUT', 59 - path: '/users/{userId}', 60 - operationId: 'updateUser', 61 - summary: 'Update a user', 62 - tags: ['users'] 63 - }).input(zUpdateUserData).output(zUpdateUserResponse); 64 - 65 - /** 66 - * Get all posts 67 - */ 68 - export const getPostsContract = base.route({ 69 - method: 'GET', 70 - path: '/posts', 71 - operationId: 'getPosts', 72 - summary: 'Get all posts', 73 - tags: ['posts'] 74 - }).input(zGetPostsData).output(zGetPostsResponse); 75 - 76 - /** 77 - * Create a new post 78 - */ 79 - export const createPostContract = base.route({ 80 - method: 'POST', 81 - path: '/posts', 82 - operationId: 'createPost', 83 - summary: 'Create a new post', 84 - tags: ['posts'], 85 - successStatus: 201 86 - }).input(zCreatePostData).output(zCreatePostResponse); 87 - 88 - /** 89 - * Get a post by ID 90 - */ 91 - export const getPostByIdContract = base.route({ 92 - method: 'GET', 93 - path: '/posts/{postId}', 94 - operationId: 'getPostById', 95 - summary: 'Get a post by ID', 96 - tags: ['posts'] 97 - }).input(zGetPostByIdData).output(zGetPostByIdResponse); 98 - 99 - export const router = { 100 - getUsers: getUsersContract, 101 - createUser: createUserContract, 102 - deleteUser: deleteUserContract, 103 - getUserById: getUserByIdContract, 104 - updateUser: updateUserContract, 105 - getPosts: getPostsContract, 106 - createPost: createPostContract, 107 - getPostById: getPostByIdContract 108 - }; 109 - 110 - export type Router = typeof router;
-154
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/zod/custom-group-key/zod.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import { z } from 'zod'; 4 - 5 - export const zUser = z.object({ 6 - id: z.string(), 7 - email: z.email(), 8 - name: z.string(), 9 - createdAt: z.optional(z.iso.datetime()) 10 - }); 11 - 12 - export const zCreateUserInput = z.object({ 13 - email: z.email(), 14 - name: z.string(), 15 - password: z.optional(z.string().min(8)) 16 - }); 17 - 18 - export const zUpdateUserInput = z.object({ 19 - email: z.optional(z.email()), 20 - name: z.optional(z.string()) 21 - }); 22 - 23 - export const zPost = z.object({ 24 - id: z.string(), 25 - title: z.string(), 26 - content: z.string(), 27 - authorId: z.string(), 28 - status: z.optional(z.enum([ 29 - 'draft', 30 - 'published', 31 - 'archived' 32 - ])), 33 - createdAt: z.optional(z.iso.datetime()) 34 - }); 35 - 36 - export const zCreatePostInput = z.object({ 37 - title: z.string(), 38 - content: z.string(), 39 - status: z.optional(z.enum(['draft', 'published'])) 40 - }); 41 - 42 - export const zGetUsersData = z.object({ 43 - body: z.optional(z.never()), 44 - path: z.optional(z.never()), 45 - query: z.optional(z.object({ 46 - limit: z.optional(z.int()).default(10), 47 - offset: z.optional(z.int()).default(0) 48 - })) 49 - }); 50 - 51 - /** 52 - * List of users 53 - */ 54 - export const zGetUsersResponse = z.array(zUser); 55 - 56 - export const zCreateUserData = z.object({ 57 - body: zCreateUserInput, 58 - path: z.optional(z.never()), 59 - query: z.optional(z.never()) 60 - }); 61 - 62 - /** 63 - * User created 64 - */ 65 - export const zCreateUserResponse = zUser; 66 - 67 - export const zDeleteUserData = z.object({ 68 - body: z.optional(z.never()), 69 - path: z.object({ 70 - userId: z.string() 71 - }), 72 - query: z.optional(z.never()), 73 - headers: z.optional(z.object({ 74 - 'X-Request-Id': z.optional(z.string()) 75 - })) 76 - }); 77 - 78 - /** 79 - * User deleted 80 - */ 81 - export const zDeleteUserResponse = z.void(); 82 - 83 - export const zGetUserByIdData = z.object({ 84 - body: z.optional(z.never()), 85 - path: z.object({ 86 - userId: z.string() 87 - }), 88 - query: z.optional(z.never()) 89 - }); 90 - 91 - /** 92 - * User found 93 - */ 94 - export const zGetUserByIdResponse = zUser; 95 - 96 - export const zUpdateUserData = z.object({ 97 - body: zUpdateUserInput, 98 - path: z.object({ 99 - userId: z.string() 100 - }), 101 - query: z.optional(z.never()) 102 - }); 103 - 104 - /** 105 - * User updated 106 - */ 107 - export const zUpdateUserResponse = zUser; 108 - 109 - export const zGetPostsData = z.object({ 110 - body: z.optional(z.never()), 111 - path: z.optional(z.never()), 112 - query: z.optional(z.object({ 113 - authorId: z.optional(z.string()), 114 - status: z.optional(z.enum([ 115 - 'draft', 116 - 'published', 117 - 'archived' 118 - ])) 119 - })) 120 - }); 121 - 122 - /** 123 - * List of posts 124 - */ 125 - export const zGetPostsResponse = z.array(zPost); 126 - 127 - export const zCreatePostData = z.object({ 128 - body: zCreatePostInput, 129 - path: z.optional(z.never()), 130 - query: z.optional(z.never()), 131 - headers: z.object({ 132 - 'X-Author-Id': z.string() 133 - }) 134 - }); 135 - 136 - /** 137 - * Post created 138 - */ 139 - export const zCreatePostResponse = zPost; 140 - 141 - export const zGetPostByIdData = z.object({ 142 - body: z.optional(z.never()), 143 - path: z.object({ 144 - postId: z.string() 145 - }), 146 - query: z.optional(z.object({ 147 - includeComments: z.optional(z.boolean()).default(false) 148 - })) 149 - }); 150 - 151 - /** 152 - * Post found 153 - */ 154 - export const zGetPostByIdResponse = zPost;
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/zod/custom-router-name/@orpc/contract.gen.ts packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.1.x/custom-router-name/@orpc/contract.gen.ts
+38 -38
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/zod/custom-router-name/zod.gen.ts packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.1.x/custom-router-name/zod.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - import { z } from 'zod'; 3 + import * as z from 'zod'; 4 4 5 5 export const zUser = z.object({ 6 6 id: z.string(), 7 7 email: z.email(), 8 8 name: z.string(), 9 - createdAt: z.optional(z.iso.datetime()) 9 + createdAt: z.iso.datetime().optional() 10 10 }); 11 11 12 12 export const zCreateUserInput = z.object({ 13 13 email: z.email(), 14 14 name: z.string(), 15 - password: z.optional(z.string().min(8)) 15 + password: z.string().min(8).optional() 16 16 }); 17 17 18 18 export const zUpdateUserInput = z.object({ 19 - email: z.optional(z.email()), 20 - name: z.optional(z.string()) 19 + email: z.email().optional(), 20 + name: z.string().optional() 21 21 }); 22 22 23 23 export const zPost = z.object({ ··· 25 25 title: z.string(), 26 26 content: z.string(), 27 27 authorId: z.string(), 28 - status: z.optional(z.enum([ 28 + status: z.enum([ 29 29 'draft', 30 30 'published', 31 31 'archived' 32 - ])), 33 - createdAt: z.optional(z.iso.datetime()) 32 + ]).optional(), 33 + createdAt: z.iso.datetime().optional() 34 34 }); 35 35 36 36 export const zCreatePostInput = z.object({ 37 37 title: z.string(), 38 38 content: z.string(), 39 - status: z.optional(z.enum(['draft', 'published'])) 39 + status: z.enum(['draft', 'published']).optional() 40 40 }); 41 41 42 42 export const zGetUsersData = z.object({ 43 - body: z.optional(z.never()), 44 - path: z.optional(z.never()), 45 - query: z.optional(z.object({ 46 - limit: z.optional(z.int()).default(10), 47 - offset: z.optional(z.int()).default(0) 48 - })) 43 + body: z.never().optional(), 44 + path: z.never().optional(), 45 + query: z.object({ 46 + limit: z.int().optional().default(10), 47 + offset: z.int().optional().default(0) 48 + }).optional() 49 49 }); 50 50 51 51 /** ··· 55 55 56 56 export const zCreateUserData = z.object({ 57 57 body: zCreateUserInput, 58 - path: z.optional(z.never()), 59 - query: z.optional(z.never()) 58 + path: z.never().optional(), 59 + query: z.never().optional() 60 60 }); 61 61 62 62 /** ··· 65 65 export const zCreateUserResponse = zUser; 66 66 67 67 export const zDeleteUserData = z.object({ 68 - body: z.optional(z.never()), 68 + body: z.never().optional(), 69 69 path: z.object({ 70 70 userId: z.string() 71 71 }), 72 - query: z.optional(z.never()), 73 - headers: z.optional(z.object({ 74 - 'X-Request-Id': z.optional(z.string()) 75 - })) 72 + query: z.never().optional(), 73 + headers: z.object({ 74 + 'X-Request-Id': z.string().optional() 75 + }).optional() 76 76 }); 77 77 78 78 /** ··· 81 81 export const zDeleteUserResponse = z.void(); 82 82 83 83 export const zGetUserByIdData = z.object({ 84 - body: z.optional(z.never()), 84 + body: z.never().optional(), 85 85 path: z.object({ 86 86 userId: z.string() 87 87 }), 88 - query: z.optional(z.never()) 88 + query: z.never().optional() 89 89 }); 90 90 91 91 /** ··· 98 98 path: z.object({ 99 99 userId: z.string() 100 100 }), 101 - query: z.optional(z.never()) 101 + query: z.never().optional() 102 102 }); 103 103 104 104 /** ··· 107 107 export const zUpdateUserResponse = zUser; 108 108 109 109 export const zGetPostsData = z.object({ 110 - body: z.optional(z.never()), 111 - path: z.optional(z.never()), 112 - query: z.optional(z.object({ 113 - authorId: z.optional(z.string()), 114 - status: z.optional(z.enum([ 110 + body: z.never().optional(), 111 + path: z.never().optional(), 112 + query: z.object({ 113 + authorId: z.string().optional(), 114 + status: z.enum([ 115 115 'draft', 116 116 'published', 117 117 'archived' 118 - ])) 119 - })) 118 + ]).optional() 119 + }).optional() 120 120 }); 121 121 122 122 /** ··· 126 126 127 127 export const zCreatePostData = z.object({ 128 128 body: zCreatePostInput, 129 - path: z.optional(z.never()), 130 - query: z.optional(z.never()), 129 + path: z.never().optional(), 130 + query: z.never().optional(), 131 131 headers: z.object({ 132 132 'X-Author-Id': z.string() 133 133 }) ··· 139 139 export const zCreatePostResponse = zPost; 140 140 141 141 export const zGetPostByIdData = z.object({ 142 - body: z.optional(z.never()), 142 + body: z.never().optional(), 143 143 path: z.object({ 144 144 postId: z.string() 145 145 }), 146 - query: z.optional(z.object({ 147 - includeComments: z.optional(z.boolean()).default(false) 148 - })) 146 + query: z.object({ 147 + includeComments: z.boolean().optional().default(false) 148 + }).optional() 149 149 }); 150 150 151 151 /**
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/zod/default/@orpc/contract.gen.ts packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.1.x/default/@orpc/contract.gen.ts
+38 -38
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/zod/default/zod.gen.ts packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.1.x/default/zod.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - import { z } from 'zod'; 3 + import * as z from 'zod'; 4 4 5 5 export const zUser = z.object({ 6 6 id: z.string(), 7 7 email: z.email(), 8 8 name: z.string(), 9 - createdAt: z.optional(z.iso.datetime()) 9 + createdAt: z.iso.datetime().optional() 10 10 }); 11 11 12 12 export const zCreateUserInput = z.object({ 13 13 email: z.email(), 14 14 name: z.string(), 15 - password: z.optional(z.string().min(8)) 15 + password: z.string().min(8).optional() 16 16 }); 17 17 18 18 export const zUpdateUserInput = z.object({ 19 - email: z.optional(z.email()), 20 - name: z.optional(z.string()) 19 + email: z.email().optional(), 20 + name: z.string().optional() 21 21 }); 22 22 23 23 export const zPost = z.object({ ··· 25 25 title: z.string(), 26 26 content: z.string(), 27 27 authorId: z.string(), 28 - status: z.optional(z.enum([ 28 + status: z.enum([ 29 29 'draft', 30 30 'published', 31 31 'archived' 32 - ])), 33 - createdAt: z.optional(z.iso.datetime()) 32 + ]).optional(), 33 + createdAt: z.iso.datetime().optional() 34 34 }); 35 35 36 36 export const zCreatePostInput = z.object({ 37 37 title: z.string(), 38 38 content: z.string(), 39 - status: z.optional(z.enum(['draft', 'published'])) 39 + status: z.enum(['draft', 'published']).optional() 40 40 }); 41 41 42 42 export const zGetUsersData = z.object({ 43 - body: z.optional(z.never()), 44 - path: z.optional(z.never()), 45 - query: z.optional(z.object({ 46 - limit: z.optional(z.int()).default(10), 47 - offset: z.optional(z.int()).default(0) 48 - })) 43 + body: z.never().optional(), 44 + path: z.never().optional(), 45 + query: z.object({ 46 + limit: z.int().optional().default(10), 47 + offset: z.int().optional().default(0) 48 + }).optional() 49 49 }); 50 50 51 51 /** ··· 55 55 56 56 export const zCreateUserData = z.object({ 57 57 body: zCreateUserInput, 58 - path: z.optional(z.never()), 59 - query: z.optional(z.never()) 58 + path: z.never().optional(), 59 + query: z.never().optional() 60 60 }); 61 61 62 62 /** ··· 65 65 export const zCreateUserResponse = zUser; 66 66 67 67 export const zDeleteUserData = z.object({ 68 - body: z.optional(z.never()), 68 + body: z.never().optional(), 69 69 path: z.object({ 70 70 userId: z.string() 71 71 }), 72 - query: z.optional(z.never()), 73 - headers: z.optional(z.object({ 74 - 'X-Request-Id': z.optional(z.string()) 75 - })) 72 + query: z.never().optional(), 73 + headers: z.object({ 74 + 'X-Request-Id': z.string().optional() 75 + }).optional() 76 76 }); 77 77 78 78 /** ··· 81 81 export const zDeleteUserResponse = z.void(); 82 82 83 83 export const zGetUserByIdData = z.object({ 84 - body: z.optional(z.never()), 84 + body: z.never().optional(), 85 85 path: z.object({ 86 86 userId: z.string() 87 87 }), 88 - query: z.optional(z.never()) 88 + query: z.never().optional() 89 89 }); 90 90 91 91 /** ··· 98 98 path: z.object({ 99 99 userId: z.string() 100 100 }), 101 - query: z.optional(z.never()) 101 + query: z.never().optional() 102 102 }); 103 103 104 104 /** ··· 107 107 export const zUpdateUserResponse = zUser; 108 108 109 109 export const zGetPostsData = z.object({ 110 - body: z.optional(z.never()), 111 - path: z.optional(z.never()), 112 - query: z.optional(z.object({ 113 - authorId: z.optional(z.string()), 114 - status: z.optional(z.enum([ 110 + body: z.never().optional(), 111 + path: z.never().optional(), 112 + query: z.object({ 113 + authorId: z.string().optional(), 114 + status: z.enum([ 115 115 'draft', 116 116 'published', 117 117 'archived' 118 - ])) 119 - })) 118 + ]).optional() 119 + }).optional() 120 120 }); 121 121 122 122 /** ··· 126 126 127 127 export const zCreatePostData = z.object({ 128 128 body: zCreatePostInput, 129 - path: z.optional(z.never()), 130 - query: z.optional(z.never()), 129 + path: z.never().optional(), 130 + query: z.never().optional(), 131 131 headers: z.object({ 132 132 'X-Author-Id': z.string() 133 133 }) ··· 139 139 export const zCreatePostResponse = zPost; 140 140 141 141 export const zGetPostByIdData = z.object({ 142 - body: z.optional(z.never()), 142 + body: z.never().optional(), 143 143 path: z.object({ 144 144 postId: z.string() 145 145 }), 146 - query: z.optional(z.object({ 147 - includeComments: z.optional(z.boolean()).default(false) 148 - })) 146 + query: z.object({ 147 + includeComments: z.boolean().optional().default(false) 148 + }).optional() 149 149 }); 150 150 151 151 /**
-50
packages/openapi-ts-tests/main/test/plugins.test.ts
··· 580 580 }), 581 581 description: 'generate Angular requests and resources (class)', 582 582 }, 583 - { 584 - config: createConfig({ 585 - input: version === '2.0.x' ? 'sdk-instance.yaml' : 'orpc-contract.yaml', 586 - output: 'default', 587 - plugins: ['zod', '@orpc/contract'], 588 - }), 589 - description: 'generate oRPC contracts with Zod schemas', 590 - }, 591 - { 592 - config: createConfig({ 593 - input: version === '2.0.x' ? 'sdk-instance.yaml' : 'orpc-contract.yaml', 594 - output: 'custom-contract-name', 595 - plugins: [ 596 - 'zod', 597 - { 598 - contractNameBuilder: (id: string) => `${id}Rpc`, 599 - name: '@orpc/contract', 600 - }, 601 - ], 602 - }), 603 - description: 'generate oRPC contracts with custom contract name builder', 604 - }, 605 - { 606 - config: createConfig({ 607 - input: version === '2.0.x' ? 'sdk-instance.yaml' : 'orpc-contract.yaml', 608 - output: 'custom-group-key', 609 - plugins: [ 610 - 'zod', 611 - { 612 - groupKeyBuilder: (operation) => operation.method, 613 - name: '@orpc/contract', 614 - }, 615 - ], 616 - }), 617 - description: 'generate oRPC contracts with custom group key builder', 618 - }, 619 - { 620 - config: createConfig({ 621 - input: version === '2.0.x' ? 'sdk-instance.yaml' : 'orpc-contract.yaml', 622 - output: 'custom-router-name', 623 - plugins: [ 624 - 'zod', 625 - { 626 - name: '@orpc/contract', 627 - routerName: 'contract', 628 - }, 629 - ], 630 - }), 631 - description: 'generate oRPC contracts with custom router name', 632 - }, 633 583 ]; 634 584 635 585 it.each(scenarios)('$description', async ({ config }) => {
+4 -9
packages/openapi-ts-tests/sdks/.gitignore
··· 1 1 .DS_Store 2 2 .idea 3 - .tsdown 4 3 .tmp 5 - junit.xml 4 + .tsdown 6 5 logs 7 6 node_modules 8 - npm-debug.log* 9 7 temp 10 - yarn-debug.log* 11 - yarn-error.log* 12 8 13 - *.iml 14 - dist 9 + .env 15 10 coverage 16 - .env 11 + dist 17 12 18 13 # test files 19 - .gen/ 14 + .gen
+4 -9
packages/openapi-ts-tests/valibot/v1/.gitignore
··· 1 1 .DS_Store 2 2 .idea 3 - .tsdown 4 3 .tmp 5 - junit.xml 4 + .tsdown 6 5 logs 7 6 node_modules 8 - npm-debug.log* 9 7 temp 10 - yarn-debug.log* 11 - yarn-error.log* 12 8 13 - *.iml 14 - dist 9 + .env 15 10 coverage 16 - .env 11 + dist 17 12 18 13 # test files 19 - .gen/ 14 + .gen
+4 -9
packages/openapi-ts-tests/zod/v3/.gitignore
··· 1 1 .DS_Store 2 2 .idea 3 - .tsdown 4 3 .tmp 5 - junit.xml 4 + .tsdown 6 5 logs 7 6 node_modules 8 - npm-debug.log* 9 7 temp 10 - yarn-debug.log* 11 - yarn-error.log* 12 8 13 - *.iml 14 - dist 9 + .env 15 10 coverage 16 - .env 11 + dist 17 12 18 13 # test files 19 - .gen/ 14 + .gen
+4 -9
packages/openapi-ts-tests/zod/v4/.gitignore
··· 1 1 .DS_Store 2 2 .idea 3 - .tsdown 4 3 .tmp 5 - junit.xml 4 + .tsdown 6 5 logs 7 6 node_modules 8 - npm-debug.log* 9 7 temp 10 - yarn-debug.log* 11 - yarn-error.log* 12 8 13 - *.iml 14 - dist 9 + .env 15 10 coverage 16 - .env 11 + dist 17 12 18 13 # test files 19 - .gen/ 14 + .gen
+2 -4
packages/openapi-ts/src/plugins/@orpc/contract/config.ts
··· 1 - import type { OperationsStrategy } from '~/openApi/shared/locations'; 2 - import { definePluginConfig } from '~/plugins/shared/utils/config'; 3 - import type { PluginContext } from '~/plugins/types'; 4 - import { resolveNaming } from '~/utils/naming'; 1 + import type { OperationsStrategy, PluginContext } from '@hey-api/shared'; 2 + import { definePluginConfig, resolveNaming } from '@hey-api/shared'; 5 3 6 4 import { handler } from './plugin'; 7 5 import type { OrpcContractPlugin, RouterConfig, UserRouterConfig } from './types';
+5 -8
packages/openapi-ts/src/plugins/@orpc/contract/plugin.ts
··· 1 1 import type { NodeName } from '@hey-api/codegen-core'; 2 + import type { IR } from '@hey-api/shared'; 3 + import { applyNaming, OperationPath, OperationStrategy, toCase } from '@hey-api/shared'; 2 4 3 - import type { IR } from '~/ir/types'; 4 - import { OperationPath, OperationStrategy } from '~/openApi/shared/locations'; 5 - import { createOperationComment } from '~/plugins/shared/utils/operation'; 6 - import { $ } from '~/ts-dsl'; 7 - import type { ObjectTsDsl } from '~/ts-dsl/expr/object'; 8 - import { applyNaming, toCase } from '~/utils/naming'; 9 - 5 + import { $ } from '../../../ts-dsl'; 6 + import { createOperationComment } from '../../shared/utils/operation'; 10 7 import type { OrpcContractPlugin, RouterConfig } from './types'; 11 8 12 9 function hasInput(operation: IR.OperationObject): boolean { ··· 86 83 type NestedNode = { children: Map<string, NestedValue>; type: 'node' }; 87 84 type NestedValue = NestedLeaf | NestedNode; 88 85 89 - function buildNestedObject(node: NestedNode): ObjectTsDsl { 86 + function buildNestedObject(node: NestedNode): ReturnType<typeof $.object> { 90 87 const obj = $.object(); 91 88 for (const [key, child] of node.children) { 92 89 if (child.type === 'leaf') {
+6 -8
packages/shared/.gitignore
··· 1 1 .DS_Store 2 2 .idea 3 - .tsdown 4 3 .tmp 5 - junit.xml 4 + .tsdown 6 5 logs 7 6 node_modules 8 - npm-debug.log* 9 7 temp 10 - yarn-debug.log* 11 - yarn-error.log* 12 8 13 - *.iml 9 + .env 10 + coverage 14 11 dist 15 - coverage 16 - .env 12 + 13 + # test files 14 + .gen
+7 -8
packages/vite-plugin/.gitignore
··· 1 1 .DS_Store 2 2 .idea 3 - .tsdown 4 3 .tmp 5 - junit.xml 4 + .tsdown 6 5 logs 7 6 node_modules 8 - npm-debug.log* 9 7 temp 10 - yarn-debug.log* 11 - yarn-error.log* 12 8 13 - *.iml 9 + .env 10 + coverage 14 11 dist 15 - coverage 16 - .env 12 + 13 + # test files 14 + .gen 15 + 17 16 18 17 # test files 19 18 test/generated
+15
pnpm-lock.yaml
··· 1461 1461 specifier: 0.16.0 1462 1462 version: 0.16.0 1463 1463 1464 + packages/openapi-ts-tests/@orpc/contract/v1: 1465 + devDependencies: 1466 + '@hey-api/openapi-ts': 1467 + specifier: workspace:* 1468 + version: link:../../../../openapi-ts 1469 + '@orpc/contract': 1470 + specifier: 1.13.4 1471 + version: 1.13.4 1472 + typescript: 1473 + specifier: 5.9.3 1474 + version: 5.9.3 1475 + zod: 1476 + specifier: 4.3.6 1477 + version: 4.3.6 1478 + 1464 1479 packages/openapi-ts-tests/main: 1465 1480 devDependencies: 1466 1481 '@angular-devkit/build-angular':
+9
vitest.config.ts
··· 70 70 { 71 71 extends: true, 72 72 test: { 73 + globalSetup: ['./test/globalTeardown.ts'], 74 + name: '@test/openapi-ts-orpc-contract-v1', 75 + root: 'packages/openapi-ts-tests/@orpc/contract/v1', 76 + setupFiles: ['./vitest.setup.ts'], 77 + }, 78 + }, 79 + { 80 + extends: true, 81 + test: { 73 82 name: '@test/openapi-ts-sdks', 74 83 root: 'packages/openapi-ts-tests/sdks', 75 84 setupFiles: ['./vitest.setup.ts'],