hono-takibi 0.7.4 → 0.7.5

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 (89) hide show
  1. package/dist/cli/hono-takibi/index.d.ts +4 -0
  2. package/dist/cli/hono-takibi/index.js +37 -0
  3. package/dist/cli/{takibi.d.ts → hono-takibi/takibi.d.ts} +1 -1
  4. package/dist/cli/{takibi.js → hono-takibi/takibi.js} +7 -7
  5. package/dist/cli/hono-takibi/template-code.d.ts +3 -0
  6. package/dist/cli/{app.js → hono-takibi/template-code.js} +7 -7
  7. package/dist/cli/index.d.ts +1 -4
  8. package/dist/cli/index.js +1 -37
  9. package/dist/core/helper/get-camel-case-schema-name.js +1 -1
  10. package/dist/core/helper/get-pascal-case-schema-name.js +1 -1
  11. package/dist/core/helper/get-variable-name.d.ts +2 -3
  12. package/dist/core/helper/get-variable-name.js +4 -4
  13. package/dist/core/helper/get-variable-schema-name.d.ts +2 -3
  14. package/dist/core/helper/get-variable-schema-name.js +3 -5
  15. package/dist/core/helper/sanitize-identifier.d.ts +1 -0
  16. package/dist/core/helper/sanitize-identifier.js +3 -0
  17. package/dist/core/schema/references/get-ref-schema-name.d.ts +2 -3
  18. package/dist/core/schema/references/get-ref-schema-name.js +3 -3
  19. package/dist/core/{text/escape-str.d.ts → utils/escape-string-literal.d.ts} +1 -1
  20. package/dist/core/{text/escape-str.js → utils/escape-string-literal.js} +1 -1
  21. package/dist/core/utils/index.d.ts +6 -0
  22. package/dist/core/utils/index.js +6 -0
  23. package/dist/core/{text → utils}/regex-pattern.js +1 -2
  24. package/dist/core/utils/sanitizeIdentifier.d.ts +23 -0
  25. package/dist/core/utils/sanitizeIdentifier.js +25 -0
  26. package/dist/generator/zod/coerce.js +1 -1
  27. package/dist/generator/zod/object.js +6 -6
  28. package/dist/generator/zod/reference/generate-array-reference-schema.js +1 -1
  29. package/dist/generator/zod/reference/generate-reference-schema.js +1 -1
  30. package/dist/generator/zod/regex.js +1 -1
  31. package/dist/generator/zod/sub/generate-zod-schema-from-sub-schema.js +1 -1
  32. package/dist/generator/zod/zod.js +9 -9
  33. package/dist/generator/zod-openapi-hono/app/docs/index.d.ts +8 -0
  34. package/dist/generator/zod-openapi-hono/app/docs/index.js +9 -0
  35. package/dist/generator/zod-openapi-hono/app/{generators/generate-app-route-handler.d.ts → generator/app-route-handler.d.ts} +1 -1
  36. package/dist/generator/zod-openapi-hono/app/{generators/generate-app-route-handler.js → generator/app-route-handler.js} +1 -1
  37. package/dist/generator/zod-openapi-hono/app/{generators/generate-apply-openapi-routes.d.ts → generator/apply-openapi-routes.d.ts} +2 -2
  38. package/dist/generator/zod-openapi-hono/app/{generators/generate-apply-openapi-routes.js → generator/apply-openapi-routes.js} +4 -4
  39. package/dist/generator/zod-openapi-hono/app/{generators/generate-import-routes.d.ts → generator/import-routes.d.ts} +2 -2
  40. package/dist/generator/zod-openapi-hono/app/{generators/generate-import-routes.js → generator/import-routes.js} +2 -2
  41. package/dist/generator/zod-openapi-hono/app/generator/index.d.ts +3 -0
  42. package/dist/generator/zod-openapi-hono/app/generator/index.js +3 -0
  43. package/dist/generator/zod-openapi-hono/app/helper/get-route-maps.d.ts +3 -3
  44. package/dist/generator/zod-openapi-hono/app/helper/get-route-maps.js +3 -3
  45. package/dist/generator/zod-openapi-hono/app/index.d.ts +3 -3
  46. package/dist/generator/zod-openapi-hono/app/index.js +15 -13
  47. package/dist/generator/zod-openapi-hono/handler/import/get-handler-imports.js +1 -1
  48. package/dist/generator/zod-openapi-hono/handler/zod-openapi-hono-handler.d.ts +3 -3
  49. package/dist/generator/zod-openapi-hono/handler/zod-openapi-hono-handler.js +2 -5
  50. package/dist/generator/zod-openapi-hono/openapi/component/allof/{generate-allof-code.d.ts → all-of.d.ts} +1 -1
  51. package/dist/generator/zod-openapi-hono/openapi/component/allof/{generate-allof-code.js → all-of.js} +1 -1
  52. package/dist/generator/zod-openapi-hono/openapi/component/allof/index.d.ts +1 -0
  53. package/dist/generator/zod-openapi-hono/openapi/component/allof/index.js +1 -0
  54. package/dist/generator/zod-openapi-hono/openapi/component/anyof/{generate-anyof-code.d.ts → any-of.d.ts} +1 -1
  55. package/dist/generator/zod-openapi-hono/openapi/component/anyof/{generate-anyof-code.js → any-of.js} +4 -2
  56. package/dist/generator/zod-openapi-hono/openapi/component/anyof/index.d.ts +1 -0
  57. package/dist/generator/zod-openapi-hono/openapi/component/anyof/index.js +1 -0
  58. package/dist/generator/zod-openapi-hono/openapi/component/generate-components-code.js +1 -1
  59. package/dist/generator/zod-openapi-hono/openapi/component/not/index.d.ts +1 -0
  60. package/dist/generator/zod-openapi-hono/openapi/component/not/index.js +1 -0
  61. package/dist/generator/zod-openapi-hono/openapi/component/not/{generate-not-code.d.ts → not.d.ts} +1 -1
  62. package/dist/generator/zod-openapi-hono/openapi/component/not/{generate-not-code.js → not.js} +1 -1
  63. package/dist/generator/zod-openapi-hono/openapi/component/oneof/index.d.ts +1 -0
  64. package/dist/generator/zod-openapi-hono/openapi/component/oneof/index.js +1 -0
  65. package/dist/generator/zod-openapi-hono/openapi/component/oneof/{generate-oneof-code.d.ts → one-of.d.ts} +1 -1
  66. package/dist/generator/zod-openapi-hono/openapi/component/oneof/{generate-oneof-code.js → one-of.js} +4 -2
  67. package/dist/generator/zod-openapi-hono/openapi/route/generate-route-name.js +1 -1
  68. package/dist/generator/zod-openapi-hono/openapi/route/generate-route.js +3 -3
  69. package/dist/generator/zod-openapi-hono/openapi/route/response/generate-response-schema.js +3 -3
  70. package/dist/generator/zod-openapi-hono/openapi/zod-openapi-hono.d.ts +3 -3
  71. package/dist/generator/zod-openapi-hono/openapi/zod-openapi-hono.js +4 -9
  72. package/dist/generator/zod-to-openapi/defining/generate-zod-to-openapi-schema-definition.js +7 -9
  73. package/dist/openapi/index.d.ts +1 -1
  74. package/dist/openapi/parse-openapi.d.ts +3 -3
  75. package/dist/openapi/parse-openapi.js +1 -1
  76. package/dist/openapi/types.d.ts +4 -4
  77. package/package.json +2 -2
  78. package/dist/cli/app.d.ts +0 -3
  79. package/dist/core/text/index.d.ts +0 -5
  80. package/dist/core/text/index.js +0 -5
  81. package/dist/generator/zod-openapi-hono/app/docs/generate-docs.d.ts +0 -13
  82. package/dist/generator/zod-openapi-hono/app/docs/generate-docs.js +0 -14
  83. /package/dist/core/{text → utils}/capitalize.d.ts +0 -0
  84. /package/dist/core/{text → utils}/capitalize.js +0 -0
  85. /package/dist/core/{text → utils}/decapitalize.d.ts +0 -0
  86. /package/dist/core/{text → utils}/decapitalize.js +0 -0
  87. /package/dist/core/{text → utils}/regex-pattern.d.ts +0 -0
  88. /package/dist/core/{text → utils}/remove-zod-prefix.d.ts +0 -0
  89. /package/dist/core/{text → utils}/remove-zod-prefix.js +0 -0
@@ -0,0 +1,4 @@
1
+ import type { Result } from '../../result/index.js';
2
+ export declare function honoTakibi(): Promise<Result<{
3
+ message: string;
4
+ }, string>>;
@@ -0,0 +1,37 @@
1
+ import { ok, asyncAndThen } from '../../result/index.js';
2
+ import { getConfig } from '../../config/index.js';
3
+ import { resolveConfig } from '../config/index.js';
4
+ import { takibi } from './takibi.js';
5
+ import { parseCli } from '../args/parse-cli.js';
6
+ import { isHelpRequested, sliceArgv } from '../utils/index.js';
7
+ const HELP_TEXT = `
8
+ Usage:
9
+ hono-takibi <input.yaml|json> -o <routes.ts> [options]
10
+
11
+ Options:
12
+ --export-type Export generated type aliases
13
+
14
+ --export-schema Export generated schema objects
15
+
16
+ --naming-case-type <PascalCase|camelCase>
17
+ Casing for generated *type aliases*
18
+ (default: PascalCase)
19
+
20
+ --naming-case-schema <PascalCase|camelCase>
21
+ Casing for generated *schema objects*
22
+ (default: PascalCase)
23
+
24
+ --template Generate an app file and handler stubs
25
+
26
+ --test Generate empty *.test.ts files for handlers
27
+
28
+ --base-path <path> API prefix (e.g. /api)
29
+
30
+ --help Show this help and exit
31
+ `.trimStart();
32
+ export async function honoTakibi() {
33
+ const args = sliceArgv(process.argv);
34
+ return isHelpRequested(args)
35
+ ? ok({ message: HELP_TEXT })
36
+ : await asyncAndThen(getConfig(), async (config) => asyncAndThen(parseCli(args, config), async (cli) => asyncAndThen(resolveConfig(config, cli), async (finalConfig) => takibi(finalConfig, cli.template, cli.test, cli.basePath))));
37
+ }
@@ -1,4 +1,4 @@
1
- import type { Result } from '../result/types.js';
1
+ import type { Result } from '../../result/types.js';
2
2
  export declare function takibi(config: {
3
3
  schema: {
4
4
  name: 'PascalCase' | 'camelCase';
@@ -1,12 +1,12 @@
1
1
  import path from 'node:path';
2
- import { ok, asyncAndThen } from '../result/index.js';
3
- import { fmt } from '../format/index.js';
4
- import { parseOpenAPI } from '../openapi/parse-openapi.js';
5
- import { zodOpenAPIHono } from '../generator/zod-openapi-hono/openapi/zod-openapi-hono.js';
6
- import { app } from './app.js';
7
- import { mkdir, writeFile } from '../fsp/index.js';
2
+ import { ok, asyncAndThen } from '../../result/index.js';
3
+ import { fmt } from '../../format/index.js';
4
+ import { parseOpenAPI } from '../../openapi/parse-openapi.js';
5
+ import { zodOpenAPIHono } from '../../generator/zod-openapi-hono/openapi/zod-openapi-hono.js';
6
+ import { templateCode } from './template-code.js';
7
+ import { mkdir, writeFile } from '../../fsp/index.js';
8
8
  export async function takibi(config, template, test, basePath) {
9
- return await asyncAndThen(await parseOpenAPI(config.input), async (openAPI) => asyncAndThen(await fmt(zodOpenAPIHono(openAPI, config)), async (code) => asyncAndThen(await mkdir(path.dirname(config.output)), async () => asyncAndThen(await writeFile(config.output, code), async () => asyncAndThen(await app(openAPI, config.output, template, test, basePath), async () => ok({
9
+ return await asyncAndThen(await parseOpenAPI(config.input), async (openAPI) => asyncAndThen(await fmt(zodOpenAPIHono(openAPI, config)), async (code) => asyncAndThen(await mkdir(path.dirname(config.output)), async () => asyncAndThen(await writeFile(config.output, code), async () => asyncAndThen(await templateCode(openAPI, config.output, template, test, basePath), async () => ok({
10
10
  message: template
11
11
  ? 'Generated code and template files written'
12
12
  : `Generated code written to ${config.output}`,
@@ -0,0 +1,3 @@
1
+ import type { OpenAPI } from '../../openapi/index.js';
2
+ import type { Result } from '../../result/index.js';
3
+ export declare function templateCode(openAPI: OpenAPI, output: `${string}.ts`, template: boolean, test: boolean, basePath?: string): Promise<Result<void, string>>;
@@ -1,11 +1,11 @@
1
1
  import path from 'node:path';
2
- import { ok, err, asyncAndThen } from '../result/index.js';
3
- import { readdir, writeFile } from '../fsp/index.js';
4
- import { fmt } from '../format/index.js';
5
- import { generateApp } from '../generator/zod-openapi-hono/app/index.js';
6
- import { zodOpenapiHonoHandler } from '../generator/zod-openapi-hono/handler/zod-openapi-hono-handler.js';
7
- export async function app(openAPI, output, template, test, basePath) {
8
- if (!(template || !output.includes('/')))
2
+ import { ok, asyncAndThen } from '../../result/index.js';
3
+ import { readdir, writeFile } from '../../fsp/index.js';
4
+ import { fmt } from '../../format/index.js';
5
+ import { generateApp } from '../../generator/zod-openapi-hono/app/index.js';
6
+ import { zodOpenapiHonoHandler } from '../../generator/zod-openapi-hono/handler/zod-openapi-hono-handler.js';
7
+ export async function templateCode(openAPI, output, template, test, basePath) {
8
+ if (!(template && output.includes('/')))
9
9
  return ok(undefined);
10
10
  const dir = path.dirname(output);
11
11
  return await asyncAndThen(await fmt(generateApp(openAPI, output, basePath)), async (appCode) => asyncAndThen(await readdir(dir), async (files) => {
@@ -1,4 +1 @@
1
- import type { Result } from '../result/index.js';
2
- export declare function honoTakibi(): Promise<Result<{
3
- message: string;
4
- }, string>>;
1
+ export { honoTakibi } from './hono-takibi/index.js';
package/dist/cli/index.js CHANGED
@@ -1,37 +1 @@
1
- import { ok, asyncAndThen } from '../result/index.js';
2
- import { getConfig } from '../config/index.js';
3
- import { resolveConfig } from './config/index.js';
4
- import { takibi } from './takibi.js';
5
- import { parseCli } from './args/parse-cli.js';
6
- import { isHelpRequested, sliceArgv } from './utils/index.js';
7
- const HELP_TEXT = `
8
- Usage:
9
- hono-takibi <input.yaml|json> -o <routes.ts> [options]
10
-
11
- Options:
12
- --export-type Export generated type aliases
13
-
14
- --export-schema Export generated schema objects
15
-
16
- --naming-case-type <PascalCase|camelCase>
17
- Casing for generated *type aliases*
18
- (default: PascalCase)
19
-
20
- --naming-case-schema <PascalCase|camelCase>
21
- Casing for generated *schema objects*
22
- (default: PascalCase)
23
-
24
- --template Generate an app file and handler stubs
25
-
26
- --test Generate empty *.test.ts files for handlers
27
-
28
- --base-path <path> API prefix (e.g. /api)
29
-
30
- --help Show this help and exit
31
- `.trimStart();
32
- export async function honoTakibi() {
33
- const args = sliceArgv(process.argv);
34
- return isHelpRequested(args)
35
- ? ok({ message: HELP_TEXT })
36
- : await asyncAndThen(getConfig(), async (config) => asyncAndThen(parseCli(args, config), async (cli) => asyncAndThen(resolveConfig(config, cli), async (finalConfig) => takibi(finalConfig, cli.template, cli.test, cli.basePath))));
37
- }
1
+ export { honoTakibi } from './hono-takibi/index.js';
@@ -1,4 +1,4 @@
1
- import { decapitalize } from '../text/index.js';
1
+ import { decapitalize } from '../utils/index.js';
2
2
  /**
3
3
  * Generates a camelCase schema name from a given schema name.
4
4
  * @param { string } schemaName - The original schema name.
@@ -1,4 +1,4 @@
1
- import { capitalize } from '../text/index.js';
1
+ import { capitalize } from '../utils/index.js';
2
2
  /**
3
3
  * Generates a PascalCase schema name from a given schema name.
4
4
  * @param { string } schemaName - The original schema name.
@@ -1,8 +1,7 @@
1
- import type { Config } from '../../config/index.js';
2
1
  /**
3
2
  * Generates a variable name from a given name and config.
4
3
  * @param { string } name - The name of the schema.
5
- * @param { Config } config - The config of the schema.
4
+ * @param { 'camelCase' | 'PascalCase' } style - The style of the variable name.
6
5
  * @returns { string } The variable name.
7
6
  */
8
- export declare function getVariableName(name: string, config: Config): string;
7
+ export declare function getVariableName(name: string, style?: 'camelCase' | 'PascalCase'): string;
@@ -1,10 +1,10 @@
1
- import { capitalize, decapitalize } from '../text/index.js';
1
+ import { capitalize, decapitalize } from '../utils/index.js';
2
2
  /**
3
3
  * Generates a variable name from a given name and config.
4
4
  * @param { string } name - The name of the schema.
5
- * @param { Config } config - The config of the schema.
5
+ * @param { 'camelCase' | 'PascalCase' } style - The style of the variable name.
6
6
  * @returns { string } The variable name.
7
7
  */
8
- export function getVariableName(name, config) {
9
- return config.type.name === 'camelCase' ? decapitalize(name) : capitalize(name);
8
+ export function getVariableName(name, style = 'PascalCase') {
9
+ return style === 'camelCase' ? decapitalize(name) : capitalize(name);
10
10
  }
@@ -1,8 +1,7 @@
1
- import type { Config } from '../../config/index.js';
2
1
  /**
3
2
  * Generates a variable schema name from a given name and config.
4
3
  * @param { string } name - The name of the schema.
5
- * @param { Config } config - The config of the schema.
4
+ * @param { 'camelCase' | 'PascalCase' } style - The style of the variable name.
6
5
  * @returns { string } The variable schema name.
7
6
  */
8
- export declare function getVariableSchemaName(name: string, config: Config): string;
7
+ export declare function getVariableSchemaName(name: string, style?: 'camelCase' | 'PascalCase'): string;
@@ -2,11 +2,9 @@ import { getCamelCaseSchemaName, getPascalCaseSchemaName } from './index.js';
2
2
  /**
3
3
  * Generates a variable schema name from a given name and config.
4
4
  * @param { string } name - The name of the schema.
5
- * @param { Config } config - The config of the schema.
5
+ * @param { 'camelCase' | 'PascalCase' } style - The style of the variable name.
6
6
  * @returns { string } The variable schema name.
7
7
  */
8
- export function getVariableSchemaName(name, config) {
9
- return config.schema.name === 'camelCase'
10
- ? getCamelCaseSchemaName(name)
11
- : getPascalCaseSchemaName(name);
8
+ export function getVariableSchemaName(name, style = 'PascalCase') {
9
+ return style === 'camelCase' ? getCamelCaseSchemaName(name) : getPascalCaseSchemaName(name);
12
10
  }
@@ -0,0 +1 @@
1
+ export declare function sanitizeIdentifier(str: string): string;
@@ -0,0 +1,3 @@
1
+ export function sanitizeIdentifier(str) {
2
+ return str.replace(/[^A-Za-z0-9_$]/g, '_');
3
+ }
@@ -1,10 +1,9 @@
1
- import type { Config } from '../../../config/index.js';
2
1
  import type { Schema } from '../../../openapi/index.js';
3
2
  /**
4
3
  * Retrieves the referenced schema name from a schema object.
5
4
  * @param { Schema } schema - The schema object
6
- * @param { Config } config - The configuration object
5
+ * @param { 'camelCase' | 'PascalCase' } style - The naming style for the schema name, either 'camelCase' or 'PascalCase'
7
6
  * @returns { string } The referenced schema name
8
7
  * @throws { Error } Will throw an error if the $ref property or the reference name is not found
9
8
  */
10
- export declare function getRefSchemaName(schema: Schema, config: Config): string;
9
+ export declare function getRefSchemaName(schema: Schema, style?: 'camelCase' | 'PascalCase'): string;
@@ -3,11 +3,11 @@ import { getRefName } from './get-ref-name.js';
3
3
  /**
4
4
  * Retrieves the referenced schema name from a schema object.
5
5
  * @param { Schema } schema - The schema object
6
- * @param { Config } config - The configuration object
6
+ * @param { 'camelCase' | 'PascalCase' } style - The naming style for the schema name, either 'camelCase' or 'PascalCase'
7
7
  * @returns { string } The referenced schema name
8
8
  * @throws { Error } Will throw an error if the $ref property or the reference name is not found
9
9
  */
10
- export function getRefSchemaName(schema, config) {
10
+ export function getRefSchemaName(schema, style = 'PascalCase') {
11
11
  if (!schema.$ref) {
12
12
  throw new Error('refName is not found');
13
13
  }
@@ -15,5 +15,5 @@ export function getRefSchemaName(schema, config) {
15
15
  if (!refName) {
16
16
  throw new Error('refName is not found');
17
17
  }
18
- return getVariableSchemaName(refName, config);
18
+ return getVariableSchemaName(refName, style);
19
19
  }
@@ -3,4 +3,4 @@
3
3
  * @param { string } text - The text to escape
4
4
  * @returns { string } The escaped text
5
5
  */
6
- export declare function escapeStr(text: string): string;
6
+ export declare function escapeStringLiteral(text: string): string;
@@ -3,7 +3,7 @@
3
3
  * @param { string } text - The text to escape
4
4
  * @returns { string } The escaped text
5
5
  */
6
- export function escapeStr(text) {
6
+ export function escapeStringLiteral(text) {
7
7
  return (text
8
8
  // Basic text cleaning
9
9
  .replace(/\n/g, ' ') // Replace line breaks with spaces
@@ -0,0 +1,6 @@
1
+ export { capitalize } from './capitalize.js';
2
+ export { decapitalize } from './decapitalize.js';
3
+ export { escapeStringLiteral } from './escape-string-literal.js';
4
+ export { regexPattern } from './regex-pattern.js';
5
+ export { removeZodPrefix } from './remove-zod-prefix.js';
6
+ export { sanitizeIdentifier } from './sanitizeIdentifier.js';
@@ -0,0 +1,6 @@
1
+ export { capitalize } from './capitalize.js';
2
+ export { decapitalize } from './decapitalize.js';
3
+ export { escapeStringLiteral } from './escape-string-literal.js';
4
+ export { regexPattern } from './regex-pattern.js';
5
+ export { removeZodPrefix } from './remove-zod-prefix.js';
6
+ export { sanitizeIdentifier } from './sanitizeIdentifier.js';
@@ -5,6 +5,5 @@
5
5
  */
6
6
  export function regexPattern(pattern) {
7
7
  const escapedPattern = pattern.replace(/(?<!\\)\//g, '\\/');
8
- const res = `/${escapedPattern}/`;
9
- return res;
8
+ return `/${escapedPattern}/`;
10
9
  }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Converts an arbitrary string into a safe TypeScript identifier
3
+ * by replacing invalid characters with underscores (`_`).
4
+ *
5
+ * This is useful when generating variable names from external strings
6
+ * such as schema names, object keys, or user input.
7
+ *
8
+ * Only letters, digits, underscores, and dollar signs are allowed.
9
+ * All other characters are replaced with `_`.
10
+ *
11
+ * @param str - The raw string to sanitize.
12
+ * @returns A sanitized string that can be used as a TypeScript identifier.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * sanitizeIdentifier('foo-bar') // 'foo_bar'
17
+ * sanitizeIdentifier('123user@name') // '123user_name'
18
+ * sanitizeIdentifier('日本語') // '___'
19
+ * sanitizeIdentifier('post.title') // 'post_title'
20
+ * sanitizeIdentifier('valid_Name') // 'valid_Name'
21
+ * ```
22
+ */
23
+ export declare function sanitizeIdentifier(str: string): string;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Converts an arbitrary string into a safe TypeScript identifier
3
+ * by replacing invalid characters with underscores (`_`).
4
+ *
5
+ * This is useful when generating variable names from external strings
6
+ * such as schema names, object keys, or user input.
7
+ *
8
+ * Only letters, digits, underscores, and dollar signs are allowed.
9
+ * All other characters are replaced with `_`.
10
+ *
11
+ * @param str - The raw string to sanitize.
12
+ * @returns A sanitized string that can be used as a TypeScript identifier.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * sanitizeIdentifier('foo-bar') // 'foo_bar'
17
+ * sanitizeIdentifier('123user@name') // '123user_name'
18
+ * sanitizeIdentifier('日本語') // '___'
19
+ * sanitizeIdentifier('post.title') // 'post_title'
20
+ * sanitizeIdentifier('valid_Name') // 'valid_Name'
21
+ * ```
22
+ */
23
+ export function sanitizeIdentifier(str) {
24
+ return str.replace(/[^A-Za-z0-9_$]/g, '_');
25
+ }
@@ -1,4 +1,4 @@
1
- import { removeZodPrefix } from '../../core/text/index.js';
1
+ import { removeZodPrefix } from '../../core/utils/index.js';
2
2
  /**
3
3
  * Generates a zod pipe function to coerce a value to a zod schema.
4
4
  * @param { string } z - The zod schema to coerce to.
@@ -1,7 +1,7 @@
1
1
  import { record, passthrough } from './index.js';
2
- import { generateAllOfCode } from '../zod-openapi-hono/openapi/component/allof/generate-allof-code.js';
3
- import { generateOneOfCode } from '../zod-openapi-hono/openapi/component/oneof/generate-oneof-code.js';
4
- import { generateAnyOfCode } from '../zod-openapi-hono/openapi/component/anyof/generate-anyof-code.js';
2
+ import { allOf } from '../zod-openapi-hono/openapi/component/allof/index.js';
3
+ import { oneOf } from '../zod-openapi-hono/openapi/component/oneof/index.js';
4
+ import { anyOf } from '../zod-openapi-hono/openapi/component/anyof/any-of.js';
5
5
  import { generateZodPropertiesSchema } from './property/generate-zod-properties-schema.js';
6
6
  /**
7
7
  * Generate Zod object schema
@@ -21,13 +21,13 @@ export function object(schema, config) {
21
21
  return record(schema.additionalProperties, config);
22
22
  }
23
23
  if (schema.allOf) {
24
- return generateAllOfCode(schema, config);
24
+ return allOf(schema, config);
25
25
  }
26
26
  if (schema.oneOf) {
27
- return generateOneOfCode(schema, config);
27
+ return oneOf(schema, config);
28
28
  }
29
29
  if (schema.anyOf) {
30
- return generateAnyOfCode(schema, config);
30
+ return anyOf(schema, config);
31
31
  }
32
32
  if (!schema.properties) {
33
33
  return 'z.object({})';
@@ -15,6 +15,6 @@ export function generateArrayReferenceSchema(schema, config) {
15
15
  if (!refName) {
16
16
  return 'z.array(z.any())';
17
17
  }
18
- const variableName = getVariableSchemaName(refName, config);
18
+ const variableName = getVariableSchemaName(refName, config.schema.name);
19
19
  return array(variableName);
20
20
  }
@@ -14,5 +14,5 @@ export function generateReferenceSchema(schema, config) {
14
14
  if (!refName) {
15
15
  return 'z.any()';
16
16
  }
17
- return getVariableSchemaName(refName, config) || 'z.any()';
17
+ return getVariableSchemaName(refName, config.schema.name) || 'z.any()';
18
18
  }
@@ -1,4 +1,4 @@
1
- import { regexPattern } from '../../core/text/index.js';
1
+ import { regexPattern } from '../../core/utils/index.js';
2
2
  /**
3
3
  * Generate Zod regex validation
4
4
  * @param { string } pattern - Regex pattern
@@ -7,5 +7,5 @@ import { zod } from '../index.js';
7
7
  * @returns { string } The generated Zod schema as a string.
8
8
  */
9
9
  export function generateZodSchemaFromSubSchema(subSchema, config) {
10
- return subSchema.$ref ? getRefSchemaName(subSchema, config) : zod(config, subSchema);
10
+ return subSchema.$ref ? getRefSchemaName(subSchema, config.schema.name) : zod(config, subSchema);
11
11
  }
@@ -3,10 +3,10 @@ import { getVariableSchemaName } from '../../core/helper/index.js';
3
3
  import { stripMinIfgTExistHelper } from './helper/strip-min-if-gt-exist-helper.js';
4
4
  import { stripMaxIfLtExistHelper } from './helper/strip-max-if-lt-exist-helper.js';
5
5
  import { stripMinMaxExistHelper } from './helper/strip-min-max-exist-helper.js';
6
- import { generateOneOfCode } from '../zod-openapi-hono/openapi/component/oneof/generate-oneof-code.js';
7
- import { generateAnyOfCode } from '../zod-openapi-hono/openapi/component/anyof/generate-anyof-code.js';
8
- import { generateAllOfCode } from '../zod-openapi-hono/openapi/component/allof/generate-allof-code.js';
9
- import { generateNotCode } from '../zod-openapi-hono/openapi/component/not/generate-not-code.js';
6
+ import { oneOf } from '../zod-openapi-hono/openapi/component/oneof/index.js';
7
+ import { anyOf } from '../zod-openapi-hono/openapi/component/anyof/index.js';
8
+ import { allOf } from '../zod-openapi-hono/openapi/component/allof/index.js';
9
+ import { not } from '../zod-openapi-hono/openapi/component/not/index.js';
10
10
  import { zodToOpenAPI } from '../zod-to-openapi/index.js';
11
11
  /**
12
12
  * Mapping of OpenAPI/JSON Schema types to Zod schema strings
@@ -153,24 +153,24 @@ export function zod(config, schema) {
153
153
  }
154
154
  // oneOf
155
155
  if (schema.oneOf) {
156
- return generateOneOfCode(schema, config);
156
+ return oneOf(schema, config);
157
157
  }
158
158
  // anyOf
159
159
  if (schema.anyOf) {
160
- return generateAnyOfCode(schema, config);
160
+ return anyOf(schema, config);
161
161
  }
162
162
  // allOf
163
163
  if (schema.allOf) {
164
- return generateAllOfCode(schema, config);
164
+ return allOf(schema, config);
165
165
  }
166
166
  // not
167
167
  if (schema.not) {
168
- return generateNotCode(schema);
168
+ return not(schema);
169
169
  }
170
170
  if (schema.$ref) {
171
171
  const refParts = schema.$ref.split('/');
172
172
  const refName = refParts[refParts.length - 1];
173
- const schemaName = getVariableSchemaName(refName, config);
173
+ const schemaName = getVariableSchemaName(refName, config.schema.name);
174
174
  return schemaName;
175
175
  }
176
176
  // fallback
@@ -0,0 +1,8 @@
1
+ import type { OpenAPI } from '../../../../openapi/index.js';
2
+ export declare function docs(openapi: OpenAPI): {
3
+ openapi: string | undefined;
4
+ info: OpenAPI['info'];
5
+ servers: OpenAPI['servers'];
6
+ externalDocs: OpenAPI['externalDocs'];
7
+ tags: OpenAPI['tags'];
8
+ };
@@ -0,0 +1,9 @@
1
+ export function docs(openapi) {
2
+ return {
3
+ openapi: openapi.openapi,
4
+ info: openapi.info,
5
+ servers: openapi.servers,
6
+ externalDocs: openapi.externalDocs,
7
+ tags: openapi.tags,
8
+ };
9
+ }
@@ -3,4 +3,4 @@
3
3
  * @param { string } routeName - Route name
4
4
  * @param { string } handlerName - Handler name
5
5
  */
6
- export declare function generateAppRouteHandler(routeName: string, handlerName: string): string;
6
+ export declare function appRouteHandler(routeName: string, handlerName: string): string;
@@ -3,6 +3,6 @@
3
3
  * @param { string } routeName - Route name
4
4
  * @param { string } handlerName - Handler name
5
5
  */
6
- export function generateAppRouteHandler(routeName, handlerName) {
6
+ export function appRouteHandler(routeName, handlerName) {
7
7
  return `.openapi(${routeName},${handlerName})`;
8
8
  }
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Generates the application route handlers.
3
3
  *
4
- * @function generateApplyOpenapiRoutes
4
+ * @function applyOpenapiRoutes
5
5
  * @param routeMappings - An array of objects containing route name, handler name, and path.
6
6
  * @returns A string of application route handlers.
7
7
  */
8
- export declare function generateApplyOpenapiRoutes(routeMappings: {
8
+ export declare function applyOpenapiRoutes(routeMappings: {
9
9
  routeName: string;
10
10
  handlerName: string;
11
11
  path: string;
@@ -1,15 +1,15 @@
1
- import { generateAppRouteHandler } from './generate-app-route-handler.js';
1
+ import { appRouteHandler } from './index.js';
2
2
  /**
3
3
  * Generates the application route handlers.
4
4
  *
5
- * @function generateApplyOpenapiRoutes
5
+ * @function applyOpenapiRoutes
6
6
  * @param routeMappings - An array of objects containing route name, handler name, and path.
7
7
  * @returns A string of application route handlers.
8
8
  */
9
- export function generateApplyOpenapiRoutes(routeMappings) {
9
+ export function applyOpenapiRoutes(routeMappings) {
10
10
  return routeMappings
11
11
  .map(({ routeName, handlerName }) => {
12
- return generateAppRouteHandler(routeName, handlerName);
12
+ return appRouteHandler(routeName, handlerName);
13
13
  })
14
14
  .join('\n');
15
15
  }
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Generates import statements for the routes.
3
3
  *
4
- * @function generateImportRoutes
4
+ * @function importRoutes
5
5
  * @param importsMap - A map of import paths to the names of the routes.
6
6
  * @returns An array of import statements.
7
7
  */
8
- export declare function generateImportRoutes(importsMap: {
8
+ export declare function importRoutes(importsMap: {
9
9
  [importPath: string]: string[];
10
10
  }): string[];
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Generates import statements for the routes.
3
3
  *
4
- * @function generateImportRoutes
4
+ * @function importRoutes
5
5
  * @param importsMap - A map of import paths to the names of the routes.
6
6
  * @returns An array of import statements.
7
7
  */
8
- export function generateImportRoutes(importsMap) {
8
+ export function importRoutes(importsMap) {
9
9
  const importRoutes = [];
10
10
  for (const [importPath, names] of Object.entries(importsMap)) {
11
11
  const uniqueNames = Array.from(new Set(names));
@@ -0,0 +1,3 @@
1
+ export { appRouteHandler } from './app-route-handler.js';
2
+ export { applyOpenapiRoutes } from './apply-openapi-routes.js';
3
+ export { importRoutes } from './import-routes.js';
@@ -0,0 +1,3 @@
1
+ export { appRouteHandler } from './app-route-handler.js';
2
+ export { applyOpenapiRoutes } from './apply-openapi-routes.js';
3
+ export { importRoutes } from './import-routes.js';
@@ -1,10 +1,10 @@
1
- import type { OpenAPISpec } from '../../../../openapi/index.js';
1
+ import type { OpenAPI } from '../../../../openapi/index.js';
2
2
  /**
3
3
  * Get route maps
4
- * @param { OpenAPISpec } openAPISpec - OpenAPI spec
4
+ * @param { openAPI } OpenAPI - OpenAPI spec
5
5
  * @returns { { routeName: string, handlerName: string, path: string }[] } Route maps
6
6
  */
7
- export declare function getRouteMaps(openAPISpec: OpenAPISpec): {
7
+ export declare function getRouteMaps(openapi: OpenAPI): {
8
8
  routeName: string;
9
9
  handlerName: string;
10
10
  path: string;
@@ -2,11 +2,11 @@ import { handlerName } from '../../handler/generator/index.js';
2
2
  import { generateRouteName } from '../../openapi/route/generate-route-name.js';
3
3
  /**
4
4
  * Get route maps
5
- * @param { OpenAPISpec } openAPISpec - OpenAPI spec
5
+ * @param { openAPI } OpenAPI - OpenAPI spec
6
6
  * @returns { { routeName: string, handlerName: string, path: string }[] } Route maps
7
7
  */
8
- export function getRouteMaps(openAPISpec) {
9
- const paths = openAPISpec.paths;
8
+ export function getRouteMaps(openapi) {
9
+ const paths = openapi.paths;
10
10
  const routeMappings = Object.entries(paths).flatMap(([path, pathItem]) => {
11
11
  return Object.entries(pathItem).flatMap(([method]) => {
12
12
  return {