hono-takibi 0.9.76 → 0.9.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -75,7 +75,9 @@ export const getRoute = createRoute({
75
75
  description: 'OK',
76
76
  content: {
77
77
  'application/json': {
78
- schema: z.object({ message: z.string().openapi({ example: 'Hono Takibi🔥' }) }),
78
+ schema: z
79
+ .object({ message: z.string().openapi({ example: 'Hono Takibi🔥' }) })
80
+ .openapi({ required: ['message'] }),
79
81
  },
80
82
  },
81
83
  },
package/dist/cli/index.js CHANGED
@@ -227,7 +227,7 @@ export async function honoTakibi() {
227
227
  ? type(openAPI, config.type.output, config.type.readonly)
228
228
  : Promise.resolve(undefined),
229
229
  config.rpc
230
- ? rpc(openAPI, config.rpc.output, config.rpc.import, config.rpc.split ?? false)
230
+ ? rpc(openAPI, config.rpc.output, config.rpc.import, config.rpc.split ?? false, config.rpc.client ?? 'client')
231
231
  : Promise.resolve(undefined),
232
232
  ]);
233
233
  if (takibiResult && !takibiResult.ok)
@@ -78,6 +78,7 @@ type Config = {
78
78
  readonly output: string | `${string}.ts`;
79
79
  readonly import: string;
80
80
  readonly split?: boolean;
81
+ readonly client?: string;
81
82
  };
82
83
  };
83
84
  /**
@@ -199,6 +199,9 @@ export function parseConfig(config) {
199
199
  if (config.rpc.split !== undefined && typeof config.rpc.split !== 'boolean') {
200
200
  return { ok: false, error: `Invalid split format for rpc: ${String(config.rpc.split)}` };
201
201
  }
202
+ if (config.rpc.client !== undefined && typeof config.rpc.client !== 'string') {
203
+ return { ok: false, error: `Invalid client format for rpc: ${String(config.rpc.client)}` };
204
+ }
202
205
  // split: true requires directory (no .ts)
203
206
  if (config.rpc.split === true && isTs(config.rpc.output)) {
204
207
  return {
@@ -1,5 +1,5 @@
1
1
  import type { OpenAPI } from '../../openapi/index.js';
2
- export declare function rpc(openAPI: OpenAPI, output: string | `${string}.ts`, importPath: string, split?: boolean): Promise<{
2
+ export declare function rpc(openAPI: OpenAPI, output: string | `${string}.ts`, importPath: string, split?: boolean, clientName?: string): Promise<{
3
3
  readonly ok: true;
4
4
  readonly value: string;
5
5
  } | {
@@ -293,16 +293,17 @@ const resolveSplitOutDir = (output) => {
293
293
  *
294
294
  * @param importPath - The import path for the Hono client
295
295
  * @param needsInferRequestType - Whether InferRequestType import is needed
296
+ * @param clientName - The name of the client to import (default: 'client')
296
297
  * @returns Import header string
297
298
  */
298
- const makeHeader = (importPath, needsInferRequestType) => {
299
+ const makeHeader = (importPath, needsInferRequestType, clientName) => {
299
300
  const typeImports = needsInferRequestType
300
301
  ? 'InferRequestType,ClientRequestOptions'
301
302
  : 'ClientRequestOptions';
302
- return `import type{${typeImports}}from'hono/client'\nimport{client}from'${importPath}'\n\n`;
303
+ return `import type{${typeImports}}from'hono/client'\nimport{${clientName}}from'${importPath}'\n\n`;
303
304
  };
304
- export async function rpc(openAPI, output, importPath, split) {
305
- const client = 'client';
305
+ export async function rpc(openAPI, output, importPath, split, clientName = 'client') {
306
+ const client = clientName;
306
307
  const pathsMaybe = openAPI.paths;
307
308
  if (!isOpenAPIPaths(pathsMaybe)) {
308
309
  return { ok: false, error: 'Invalid OpenAPI paths' };
@@ -322,7 +323,7 @@ export async function rpc(openAPI, output, importPath, split) {
322
323
  if (!split) {
323
324
  const body = operationCodes.map(({ code }) => code).join('\n\n');
324
325
  const needsInferRequestType = operationCodes.some(({ hasArgs }) => hasArgs);
325
- const header = makeHeader(importPath, needsInferRequestType);
326
+ const header = makeHeader(importPath, needsInferRequestType, client);
326
327
  const code = `${header}${body}${operationCodes.length ? '\n' : ''}`;
327
328
  const coreResult = await core(code, path.dirname(output), output);
328
329
  if (!coreResult.ok)
@@ -335,7 +336,7 @@ export async function rpc(openAPI, output, importPath, split) {
335
336
  const index = `${exportLines.join('\n')}\n`;
336
337
  const allResults = await Promise.all([
337
338
  ...operationCodes.map(({ funcName, code, hasArgs }) => {
338
- const header = makeHeader(importPath, hasArgs);
339
+ const header = makeHeader(importPath, hasArgs, client);
339
340
  const fileSrc = `${header}${code}\n`;
340
341
  const filePath = path.join(outDir, `${funcName}.ts`);
341
342
  return core(fileSrc, path.dirname(filePath), filePath);
@@ -368,7 +368,7 @@ const runAllGenerationTasks = async (configuration) => {
368
368
  const outputDirectory = toAbsolutePath(rpcConfig.output);
369
369
  const beforeFiles = await listTypeScriptFilesShallow(outputDirectory);
370
370
  await deleteTypeScriptFiles(beforeFiles);
371
- const rpcResult = await rpc(openAPI, outputDirectory, rpcConfig.import, true);
371
+ const rpcResult = await rpc(openAPI, outputDirectory, rpcConfig.import, true, rpcConfig.client ?? 'client');
372
372
  if (!rpcResult.ok)
373
373
  return `✗ rpc(split): ${rpcResult.error}`;
374
374
  return beforeFiles.length > 0
@@ -376,7 +376,7 @@ const runAllGenerationTasks = async (configuration) => {
376
376
  : `✓ rpc(split) -> ${outputDirectory}/*.ts`;
377
377
  }
378
378
  const outputPath = toAbsolutePath(rpcConfig.output);
379
- const rpcResult = await rpc(openAPI, outputPath, rpcConfig.import, false);
379
+ const rpcResult = await rpc(openAPI, outputPath, rpcConfig.import, false, rpcConfig.client ?? 'client');
380
380
  return rpcResult.ok ? `✓ rpc -> ${outputPath}` : `✗ rpc: ${rpcResult.error}`;
381
381
  })();
382
382
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hono-takibi",
3
- "description": "Hono Takibi is a CLI tool that generates Hono routes from OpenAPI specifications.",
4
- "version": "0.9.76",
3
+ "description": "Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi",
4
+ "version": "0.9.78",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "keywords": [