hono-takibi 0.5.4 → 0.5.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 (42) hide show
  1. package/dist/core/helper/get-camel-case-schema-name-helper.d.ts +2 -1
  2. package/dist/core/helper/get-camel-case-schema-name-helper.js +3 -2
  3. package/dist/core/helper/get-pascal-case-schema-name-helper.d.ts +2 -2
  4. package/dist/core/helper/get-pascal-case-schema-name-helper.js +3 -3
  5. package/dist/core/helper/get-variable-name-helper.d.ts +9 -1
  6. package/dist/core/helper/get-variable-name-helper.js +11 -4
  7. package/dist/core/helper/get-variable-schema-name-helper.d.ts +9 -1
  8. package/dist/core/helper/get-variable-schema-name-helper.js +13 -6
  9. package/dist/core/validator/is-all-optional.d.ts +2 -0
  10. package/dist/core/validator/is-all-optional.js +2 -0
  11. package/dist/core/validator/is-array-with-schema-reference.d.ts +3 -2
  12. package/dist/core/validator/is-array-with-schema-reference.js +3 -2
  13. package/dist/core/validator/is-schema-reference.d.ts +1 -1
  14. package/dist/core/validator/is-schema-reference.js +1 -1
  15. package/dist/core/validator/is-unique-content-schema.d.ts +2 -0
  16. package/dist/core/validator/is-unique-content-schema.js +2 -0
  17. package/dist/generator/zod/helper/strip-max-if-lt-exist-helper.d.ts +8 -0
  18. package/dist/generator/zod/helper/strip-max-if-lt-exist-helper.js +8 -0
  19. package/dist/generator/zod/helper/strip-min-if-gt-exist-helper.d.ts +8 -0
  20. package/dist/generator/zod/helper/strip-min-if-gt-exist-helper.js +8 -0
  21. package/dist/generator/zod/helper/strip-min-max-exist-helper.d.ts +9 -0
  22. package/dist/generator/zod/helper/strip-min-max-exist-helper.js +9 -0
  23. package/dist/generator/zod-openapi-hono/app/generators/generate-apply-openapi-routes.d.ts +7 -0
  24. package/dist/generator/zod-openapi-hono/app/generators/generate-apply-openapi-routes.js +7 -0
  25. package/dist/generator/zod-openapi-hono/app/generators/generate-import-routes.d.ts +7 -0
  26. package/dist/generator/zod-openapi-hono/app/generators/generate-import-routes.js +7 -0
  27. package/dist/generator/zod-openapi-hono/handler/generate-handler.d.ts +7 -0
  28. package/dist/generator/zod-openapi-hono/handler/generate-handler.js +7 -0
  29. package/dist/generator/zod-openapi-hono/handler/generate-zod-openapi-hono-handler.d.ts +7 -0
  30. package/dist/generator/zod-openapi-hono/handler/generate-zod-openapi-hono-handler.js +7 -0
  31. package/dist/generator/zod-openapi-hono/openapi/component/allof/generate-allof-code.d.ts +1 -0
  32. package/dist/generator/zod-openapi-hono/openapi/component/allof/generate-allof-code.js +1 -0
  33. package/dist/generator/zod-openapi-hono/openapi/component/allof/process/process-alllof.d.ts +1 -0
  34. package/dist/generator/zod-openapi-hono/openapi/component/allof/process/process-alllof.js +1 -0
  35. package/dist/generator/zod-openapi-hono/openapi/component/anyof/generate-anyof-code.d.ts +8 -0
  36. package/dist/generator/zod-openapi-hono/openapi/component/anyof/generate-anyof-code.js +8 -0
  37. package/dist/generator/zod-openapi-hono/openapi/component/oneof/generate-oneof-code.d.ts +7 -0
  38. package/dist/generator/zod-openapi-hono/openapi/component/oneof/generate-oneof-code.js +7 -0
  39. package/dist/generator/zod-openapi-hono/openapi/type/generate-types-code.js +1 -1
  40. package/dist/index.js +25 -19
  41. package/dist/vite-plugin/vite-mode.js +3 -3
  42. package/package.json +10 -10
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * Generates a camelCase schema name from a given schema name.
3
3
  *
4
+ * @function getCamelCaseSchemaNameHelper
4
5
  * @param schemaName - The original schema name.
5
6
  * @returns The camelCase schema name.
6
7
  */
7
- export declare function getCamelCaseSchemaName(schemaName: string): string;
8
+ export declare function getCamelCaseSchemaNameHelper(schemaName: string): string;
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCamelCaseSchemaName = getCamelCaseSchemaName;
3
+ exports.getCamelCaseSchemaNameHelper = getCamelCaseSchemaNameHelper;
4
4
  const decapitalize_1 = require("../text/decapitalize");
5
5
  /**
6
6
  * Generates a camelCase schema name from a given schema name.
7
7
  *
8
+ * @function getCamelCaseSchemaNameHelper
8
9
  * @param schemaName - The original schema name.
9
10
  * @returns The camelCase schema name.
10
11
  */
11
- function getCamelCaseSchemaName(schemaName) {
12
+ function getCamelCaseSchemaNameHelper(schemaName) {
12
13
  const decapitalizedSchemaName = (0, decapitalize_1.decapitalize)(schemaName);
13
14
  return `${decapitalizedSchemaName}Schema`;
14
15
  }
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Generates a PascalCase schema name from a given schema name.
3
3
  *
4
- * @function getPascalCaseSchemaName
4
+ * @function getPascalCaseSchemaNameHelper
5
5
  * @param schemaName - The original schema name.
6
6
  * @returns The PascalCase schema name.
7
7
  */
8
- export declare function getPascalCaseSchemaName(schemaName: string): string;
8
+ export declare function getPascalCaseSchemaNameHelper(schemaName: string): string;
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPascalCaseSchemaName = getPascalCaseSchemaName;
3
+ exports.getPascalCaseSchemaNameHelper = getPascalCaseSchemaNameHelper;
4
4
  const capitalize_1 = require("../text/capitalize");
5
5
  /**
6
6
  * Generates a PascalCase schema name from a given schema name.
7
7
  *
8
- * @function getPascalCaseSchemaName
8
+ * @function getPascalCaseSchemaNameHelper
9
9
  * @param schemaName - The original schema name.
10
10
  * @returns The PascalCase schema name.
11
11
  */
12
- function getPascalCaseSchemaName(schemaName) {
12
+ function getPascalCaseSchemaNameHelper(schemaName) {
13
13
  const capitalizedSchemaName = (0, capitalize_1.capitalize)(schemaName);
14
14
  return `${capitalizedSchemaName}Schema`;
15
15
  }
@@ -1,2 +1,10 @@
1
1
  import type { Config } from '../../config';
2
- export declare const getVariableNameHelper: (name: string, config: Config) => string;
2
+ /**
3
+ * Generates a variable name from a given name and config.
4
+ *
5
+ * @function getVariableNameHelper
6
+ * @param name - The name of the schema.
7
+ * @param config - The config of the schema.
8
+ * @returns The variable name.
9
+ */
10
+ export declare function getVariableNameHelper(name: string, config: Config): string;
@@ -1,9 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVariableNameHelper = void 0;
3
+ exports.getVariableNameHelper = getVariableNameHelper;
4
4
  const capitalize_1 = require("../text/capitalize");
5
5
  const decapitalize_1 = require("../text/decapitalize");
6
- const getVariableNameHelper = (name, config) => {
6
+ /**
7
+ * Generates a variable name from a given name and config.
8
+ *
9
+ * @function getVariableNameHelper
10
+ * @param name - The name of the schema.
11
+ * @param config - The config of the schema.
12
+ * @returns The variable name.
13
+ */
14
+ function getVariableNameHelper(name, config) {
7
15
  return config.type.name === 'camelCase' ? (0, decapitalize_1.decapitalize)(name) : (0, capitalize_1.capitalize)(name);
8
- };
9
- exports.getVariableNameHelper = getVariableNameHelper;
16
+ }
@@ -1,2 +1,10 @@
1
1
  import type { Config } from '../../config';
2
- export declare const getVariableSchemaNameHelper: (name: string, config: Config) => string;
2
+ /**
3
+ * Generates a variable schema name from a given name and config.
4
+ *
5
+ * @function getVariableSchemaNameHelper
6
+ * @param name - The name of the schema.
7
+ * @param config - The config of the schema.
8
+ * @returns The variable schema name.
9
+ */
10
+ export declare function getVariableSchemaNameHelper(name: string, config: Config): string;
@@ -1,11 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVariableSchemaNameHelper = void 0;
3
+ exports.getVariableSchemaNameHelper = getVariableSchemaNameHelper;
4
4
  const get_camel_case_schema_name_helper_1 = require("./get-camel-case-schema-name-helper");
5
5
  const get_pascal_case_schema_name_helper_1 = require("./get-pascal-case-schema-name-helper");
6
- const getVariableSchemaNameHelper = (name, config) => {
6
+ /**
7
+ * Generates a variable schema name from a given name and config.
8
+ *
9
+ * @function getVariableSchemaNameHelper
10
+ * @param name - The name of the schema.
11
+ * @param config - The config of the schema.
12
+ * @returns The variable schema name.
13
+ */
14
+ function getVariableSchemaNameHelper(name, config) {
7
15
  return config.schema.name === 'camelCase'
8
- ? (0, get_camel_case_schema_name_helper_1.getCamelCaseSchemaName)(name)
9
- : (0, get_pascal_case_schema_name_helper_1.getPascalCaseSchemaName)(name);
10
- };
11
- exports.getVariableSchemaNameHelper = getVariableSchemaNameHelper;
16
+ ? (0, get_camel_case_schema_name_helper_1.getCamelCaseSchemaNameHelper)(name)
17
+ : (0, get_pascal_case_schema_name_helper_1.getPascalCaseSchemaNameHelper)(name);
18
+ }
@@ -1,5 +1,7 @@
1
1
  /**
2
2
  * Check if all properties in the object are optional
3
+ *
4
+ * @function isAllOptional
3
5
  * @param objectProperties - An array of strings representing the object properties
4
6
  * @returns A boolean indicating if all properties are optional
5
7
  */
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isAllOptional = isAllOptional;
4
4
  /**
5
5
  * Check if all properties in the object are optional
6
+ *
7
+ * @function isAllOptional
6
8
  * @param objectProperties - An array of strings representing the object properties
7
9
  * @returns A boolean indicating if all properties are optional
8
10
  */
@@ -1,8 +1,9 @@
1
1
  import type { Schema } from '../../type';
2
2
  /**
3
- * array has $ref
3
+ * Checks if an array has a schema reference.
4
4
  *
5
- * @param schema - schema
5
+ * @function isArrayWithSchemaReference
6
+ * @param schema - The schema to check.
6
7
  * @returns boolean
7
8
  */
8
9
  export declare function isArrayWithSchemaReference(schema: Schema): boolean;
@@ -2,9 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isArrayWithSchemaReference = isArrayWithSchemaReference;
4
4
  /**
5
- * array has $ref
5
+ * Checks if an array has a schema reference.
6
6
  *
7
- * @param schema - schema
7
+ * @function isArrayWithSchemaReference
8
+ * @param schema - The schema to check.
8
9
  * @returns boolean
9
10
  */
10
11
  function isArrayWithSchemaReference(schema) {
@@ -2,7 +2,7 @@ import type { Schema } from '../../type';
2
2
  /**
3
3
  * isSchemaReference
4
4
  * is schema reference
5
- *
5
+ * @function isSchemaReference
6
6
  * @param schema
7
7
  * @returns boolean
8
8
  */
@@ -4,7 +4,7 @@ exports.isSchemaReference = isSchemaReference;
4
4
  /**
5
5
  * isSchemaReference
6
6
  * is schema reference
7
- *
7
+ * @function isSchemaReference
8
8
  * @param schema
9
9
  * @returns boolean
10
10
  */
@@ -1,6 +1,8 @@
1
1
  import type { Content } from '../../type';
2
2
  /**
3
3
  * Get unique content schema
4
+ *
5
+ * @function isUniqueContentSchema
4
6
  * @param contentTypes - Content types
5
7
  * @param content - Content
6
8
  * @returns Unique content schema
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isUniqueContentSchema = isUniqueContentSchema;
4
4
  /**
5
5
  * Get unique content schema
6
+ *
7
+ * @function isUniqueContentSchema
6
8
  * @param contentTypes - Content types
7
9
  * @param content - Content
8
10
  * @returns Unique content schema
@@ -1 +1,9 @@
1
+ /**
2
+ * Strips max if less than exist.
3
+ *
4
+ * @function stripMaxIfLtExistHelper
5
+ * @param str - The string to strip max if less than exist from.
6
+ * @param maximum - The maximum value.
7
+ * @returns The string without max if less than exist.
8
+ */
1
9
  export declare function stripMaxIfLtExistHelper(str: string, maximum: number): string;
@@ -1,6 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stripMaxIfLtExistHelper = stripMaxIfLtExistHelper;
4
+ /**
5
+ * Strips max if less than exist.
6
+ *
7
+ * @function stripMaxIfLtExistHelper
8
+ * @param str - The string to strip max if less than exist from.
9
+ * @param maximum - The maximum value.
10
+ * @returns The string without max if less than exist.
11
+ */
4
12
  function stripMaxIfLtExistHelper(str, maximum) {
5
13
  return str.replace(`.max(${maximum})`, '');
6
14
  }
@@ -1 +1,9 @@
1
+ /**
2
+ * Strips min if greater than exist.
3
+ *
4
+ * @function stripMinIfgTExistHelper
5
+ * @param str - The string to strip min if greater than exist from.
6
+ * @param minimum - The minimum value.
7
+ * @returns The string without min if greater than exist.
8
+ */
1
9
  export declare function stripMinIfgTExistHelper(str: string, minimum: number): string;
@@ -1,6 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stripMinIfgTExistHelper = stripMinIfgTExistHelper;
4
+ /**
5
+ * Strips min if greater than exist.
6
+ *
7
+ * @function stripMinIfgTExistHelper
8
+ * @param str - The string to strip min if greater than exist from.
9
+ * @param minimum - The minimum value.
10
+ * @returns The string without min if greater than exist.
11
+ */
4
12
  function stripMinIfgTExistHelper(str, minimum) {
5
13
  return str.replace(`.min(${minimum})`, '');
6
14
  }
@@ -1 +1,10 @@
1
+ /**
2
+ * Strips min and max from a string.
3
+ *
4
+ * @function stripMinMaxExistHelper
5
+ * @param str - The string to strip min and max from.
6
+ * @param min - The min value.
7
+ * @param max - The max value.
8
+ * @returns The string without min and max.
9
+ */
1
10
  export declare function stripMinMaxExistHelper(str: string, min: number, max: number): string;
@@ -1,6 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stripMinMaxExistHelper = stripMinMaxExistHelper;
4
+ /**
5
+ * Strips min and max from a string.
6
+ *
7
+ * @function stripMinMaxExistHelper
8
+ * @param str - The string to strip min and max from.
9
+ * @param min - The min value.
10
+ * @param max - The max value.
11
+ * @returns The string without min and max.
12
+ */
4
13
  function stripMinMaxExistHelper(str, min, max) {
5
14
  return str.replace(`.min(${min})`, '').replace(`.max(${max})`, '');
6
15
  }
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Generates the application route handlers.
3
+ *
4
+ * @function generateApplyOpenapiRoutes
5
+ * @param routeMappings - An array of objects containing route name, handler name, and path.
6
+ * @returns A string of application route handlers.
7
+ */
1
8
  export declare function generateApplyOpenapiRoutes(routeMappings: {
2
9
  routeName: string;
3
10
  handlerName: string;
@@ -2,6 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateApplyOpenapiRoutes = generateApplyOpenapiRoutes;
4
4
  const generate_app_route_handler_1 = require("../generate-app-route-handler");
5
+ /**
6
+ * Generates the application route handlers.
7
+ *
8
+ * @function generateApplyOpenapiRoutes
9
+ * @param routeMappings - An array of objects containing route name, handler name, and path.
10
+ * @returns A string of application route handlers.
11
+ */
5
12
  function generateApplyOpenapiRoutes(routeMappings) {
6
13
  return routeMappings
7
14
  .map(({ routeName, handlerName }) => {
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Generates import statements for the routes.
3
+ *
4
+ * @function generateImportRoutes
5
+ * @param importsMap - A map of import paths to the names of the routes.
6
+ * @returns An array of import statements.
7
+ */
1
8
  export declare function generateImportRoutes(importsMap: {
2
9
  [importPath: string]: string[];
3
10
  }): string[];
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateImportRoutes = generateImportRoutes;
4
+ /**
5
+ * Generates import statements for the routes.
6
+ *
7
+ * @function generateImportRoutes
8
+ * @param importsMap - A map of import paths to the names of the routes.
9
+ * @returns An array of import statements.
10
+ */
4
11
  function generateImportRoutes(importsMap) {
5
12
  const importRoutes = [];
6
13
  for (const [importPath, names] of Object.entries(importsMap)) {
@@ -1 +1,8 @@
1
+ /**
2
+ * Generates a handler function for a route.
3
+ *
4
+ * @param handlerName - The name of the handler function.
5
+ * @param routeName - The name of the route.
6
+ * @returns A string of the handler function.
7
+ */
1
8
  export declare function generateHandler(handlerName: string, routeName: string): string;
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateHandler = generateHandler;
4
+ /**
5
+ * Generates a handler function for a route.
6
+ *
7
+ * @param handlerName - The name of the handler function.
8
+ * @param routeName - The name of the route.
9
+ * @returns A string of the handler function.
10
+ */
4
11
  function generateHandler(handlerName, routeName) {
5
12
  return `export const ${handlerName}:RouteHandler<typeof ${routeName}>=async(c)=>{}`;
6
13
  }
@@ -6,4 +6,11 @@ export type HandlerOutput = {
6
6
  routeHandlerContents: string[];
7
7
  routeNames: string[];
8
8
  };
9
+ /**
10
+ * Generates the Zod OpenAPI Hono handler.
11
+ *
12
+ * @param openapi - The OpenAPI specification.
13
+ * @param config - The configuration.
14
+ * @param test - Whether to generate the test file.
15
+ */
9
16
  export declare function generateZodOpenapiHonoHandler(openapi: OpenAPISpec, config: Config, test: boolean): Promise<void>;
@@ -11,6 +11,13 @@ const group_handlers_by_file_name_helper_1 = require("./helper/group-handlers-by
11
11
  const format_1 = require("../../../format");
12
12
  const generate_handler_name_1 = require("../handler/generate-handler-name");
13
13
  const ROUTE_HANDLER = `import type { RouteHandler } from '@hono/zod-openapi'`;
14
+ /**
15
+ * Generates the Zod OpenAPI Hono handler.
16
+ *
17
+ * @param openapi - The OpenAPI specification.
18
+ * @param config - The configuration.
19
+ * @param test - Whether to generate the test file.
20
+ */
14
21
  async function generateZodOpenapiHonoHandler(openapi, config, test) {
15
22
  const paths = openapi.paths;
16
23
  const handlers = [];
@@ -3,6 +3,7 @@ import type { Config } from '../../../../../config';
3
3
  /**
4
4
  * Converts an `allOf` schema into a Zod schema.
5
5
  *
6
+ * @function generateAllOfCode
6
7
  * @param schema - The OpenAPI schema object.
7
8
  * @param config - The configuration object.
8
9
  * @returns The generated Zod schema as a string.
@@ -6,6 +6,7 @@ const generate_zod_intersection_1 = require("../../../../zod/generate-zod-inters
6
6
  /**
7
7
  * Converts an `allOf` schema into a Zod schema.
8
8
  *
9
+ * @function generateAllOfCode
9
10
  * @param schema - The OpenAPI schema object.
10
11
  * @param config - The configuration object.
11
12
  * @returns The generated Zod schema as a string.
@@ -7,6 +7,7 @@ type Accumulator = {
7
7
  /**
8
8
  * Processes the `allOf` array, separating the `nullable` flag and the array of schemas.
9
9
  *
10
+ * @function processAllOf
10
11
  * @param allOf - The `allOf` array.
11
12
  * @param config - The configuration object.
12
13
  * @returns An object containing the `nullable` flag and the generated array of schemas.
@@ -6,6 +6,7 @@ const generate_zod_schema_from_sub_schema_1 = require("../../../../../zod/sub/ge
6
6
  /**
7
7
  * Processes the `allOf` array, separating the `nullable` flag and the array of schemas.
8
8
  *
9
+ * @function processAllOf
9
10
  * @param allOf - The `allOf` array.
10
11
  * @param config - The configuration object.
11
12
  * @returns An object containing the `nullable` flag and the generated array of schemas.
@@ -1,3 +1,11 @@
1
1
  import type { Schema } from '../../../../../type';
2
2
  import type { Config } from '../../../../../config';
3
+ /**
4
+ * Generates the Zod code for an `anyOf` schema.
5
+ *
6
+ * @function generateAnyOfCode
7
+ * @param schema - The OpenAPI schema object.
8
+ * @param config - The configuration object.
9
+ * @returns The generated Zod code as a string.
10
+ */
3
11
  export declare function generateAnyOfCode(schema: Schema, config: Config): string;
@@ -4,6 +4,14 @@ exports.generateAnyOfCode = generateAnyOfCode;
4
4
  const get_ref_schema_name_1 = require("../../../../../core/schema/references/get-ref-schema-name");
5
5
  const generate_zod_union_1 = require("../../../../zod/generate-zod-union");
6
6
  const generate_zod_1 = require("../../../../zod/generate-zod");
7
+ /**
8
+ * Generates the Zod code for an `anyOf` schema.
9
+ *
10
+ * @function generateAnyOfCode
11
+ * @param schema - The OpenAPI schema object.
12
+ * @param config - The configuration object.
13
+ * @returns The generated Zod code as a string.
14
+ */
7
15
  function generateAnyOfCode(schema, config) {
8
16
  if (!schema.anyOf || schema.anyOf.length === 0) {
9
17
  console.warn('not exists anyOf');
@@ -1,3 +1,10 @@
1
1
  import type { Schema } from '../../../../../type';
2
2
  import type { Config } from '../../../../../config';
3
+ /**
4
+ * Generates the Zod code for a `oneOf` schema.
5
+ *
6
+ * @param schema - The OpenAPI schema object.
7
+ * @param config - The configuration object.
8
+ * @returns The generated Zod code as a string.
9
+ */
3
10
  export declare function generateOneOfCode(schema: Schema, config: Config): string;
@@ -4,6 +4,13 @@ exports.generateOneOfCode = generateOneOfCode;
4
4
  const get_ref_schema_name_1 = require("../../../../../core/schema/references/get-ref-schema-name");
5
5
  const generate_zod_union_1 = require("../../../../zod/generate-zod-union");
6
6
  const generate_zod_1 = require("../../../../zod/generate-zod");
7
+ /**
8
+ * Generates the Zod code for a `oneOf` schema.
9
+ *
10
+ * @param schema - The OpenAPI schema object.
11
+ * @param config - The configuration object.
12
+ * @returns The generated Zod code as a string.
13
+ */
7
14
  function generateOneOfCode(schema, config) {
8
15
  if (!schema.oneOf || schema.oneOf.length === 0) {
9
16
  console.warn('not exists oneOf');
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  // import { resolveSchemasDependencies } from "../../core/schema/references/resolve-schemas-dependencies";
3
- // import type { Components } from "../../types";
3
+ // import type { Components } from "../../type";
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.generateTypesCode = generateTypesCode;
6
6
  // export function generateTypesCode(components: Components) {
package/dist/index.js CHANGED
@@ -5,14 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.main = main;
8
- const swagger_parser_1 = __importDefault(require("@apidevtools/swagger-parser"));
9
- const node_fs_1 = __importDefault(require("node:fs"));
10
- const node_path_1 = __importDefault(require("node:path"));
11
8
  const generate_zod_openapi_hono_1 = require("./generator/zod-openapi-hono/openapi/generate-zod-openapi-hono");
12
9
  const generate_zod_openapi_hono_handler_1 = require("./generator/zod-openapi-hono/handler/generate-zod-openapi-hono-handler");
13
10
  const config_1 = require("./config");
14
11
  const format_1 = require("./format");
15
12
  const app_1 = require("./generator/zod-openapi-hono/app");
13
+ const swagger_parser_1 = __importDefault(require("@apidevtools/swagger-parser"));
14
+ const node_fs_1 = __importDefault(require("node:fs"));
15
+ const node_path_1 = __importDefault(require("node:path"));
16
+ const node_process_1 = require("node:process");
16
17
  /**
17
18
  * CLI entry point for hono-takibi
18
19
  *
@@ -32,35 +33,40 @@ const app_1 = require("./generator/zod-openapi-hono/app");
32
33
  * ```
33
34
  */
34
35
  async function main(dev = false, config = (0, config_1.getConfig)()) {
35
- // 1. argv ['**/bin/node', '**/dist/index.js', 'example/pet-store.yaml', '-o', 'routes/petstore-index.ts']
36
- // 2. slice [ 'example/pet-store.yaml', '-o', 'routes/petstore-index.ts']
36
+ // argv ['**/bin/node', '**/dist/index.js', 'example/pet-store.yaml', '-o', 'routes/petstore-index.ts']
37
+ if (!node_process_1.argv.includes('-o')) {
38
+ console.error('Usage: hono-takibi <input-file> [-o output-file]');
39
+ process.exit(1);
40
+ }
41
+ // slice [ 'example/pet-store.yaml', '-o', 'routes/petstore-index.ts']
37
42
  const args = process.argv.slice(2);
38
- // 3. input = 'example/pet-store.yaml'
43
+ // input = 'example/pet-store.yaml'
39
44
  const input = config.input ?? args[0];
40
45
  config.input = input;
41
- // 4. output = 'routes/petstore-index.ts'
46
+ // output = 'routes/petstore-index.ts'
42
47
  const output = config.output ?? args[args.indexOf('-o') + 1];
43
48
  config.output = output;
44
49
  try {
45
- // 5. parse OpenAPI YAML or JSON
50
+ // parse OpenAPI YAML or JSON
46
51
  const openAPI = (await swagger_parser_1.default.parse(input));
47
- // 6. generate Hono code
52
+ // generate Hono code
48
53
  const hono = (0, generate_zod_openapi_hono_1.generateZodOpenAPIHono)(openAPI, config);
49
- // 7. format code
54
+ // format code
50
55
  const formattedCode = await (0, format_1.formatCode)(hono);
51
- // 8. write to file
56
+ // write to file
52
57
  if (config.output) {
53
- // 8.1 output routes/petstore-index.ts
58
+ // output routes/petstore-index.ts
54
59
  const outputDir = node_path_1.default.dirname(output);
55
- // 8.2 outputDir routes
60
+ // outputDir routes
56
61
  if (!node_fs_1.default.existsSync(outputDir)) {
57
62
  node_fs_1.default.mkdirSync(outputDir, { recursive: true });
58
63
  }
59
64
  }
60
- // 9. write to file
65
+ // write to file
61
66
  node_fs_1.default.writeFileSync(output, formattedCode, { encoding: 'utf-8' });
62
- // 10. generate template code
67
+ // generate template code
63
68
  const template = args.includes('-template');
69
+ // check if the output path contains a slash
64
70
  const isSlash = output.includes('/');
65
71
  if (!isSlash && template === true) {
66
72
  console.warn("To use the '-template' option, you must specify a valid directory path. Ensure the directory exists before executing the command.");
@@ -77,14 +83,14 @@ async function main(dev = false, config = (0, config_1.getConfig)()) {
77
83
  const basePathIndex = args.indexOf('--base-path');
78
84
  const hasBasePathEquals = basePathIndex !== -1 && args[basePathIndex + 1] === '=';
79
85
  const basePath = hasBasePathEquals ? args[basePathIndex + 2] : undefined;
80
- // 10.1 generate app code
86
+ // generate app code
81
87
  const appCode = (0, app_1.generateApp)(openAPI, config, env, basePath);
82
- // 10.2 generate handler code
88
+ // generate handler code
83
89
  await (0, generate_zod_openapi_hono_handler_1.generateZodOpenapiHonoHandler)(openAPI, config, test);
84
- // 10.3 format app code
90
+ // format app code
85
91
  const formattedAppCode = await (0, format_1.formatCode)(appCode);
86
92
  const outputDir = node_path_1.default.dirname(output);
87
- // 10.4 write to file
93
+ // write to file
88
94
  const defaultFileName = 'index.ts';
89
95
  const alternativeFileName = 'main.ts';
90
96
  const outputFile = node_fs_1.default.existsSync(defaultFileName) ? alternativeFileName : defaultFileName;
@@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.viteMode = viteMode;
7
- const swagger_parser_1 = __importDefault(require("@apidevtools/swagger-parser"));
8
- const node_fs_1 = __importDefault(require("node:fs"));
9
- const node_path_1 = __importDefault(require("node:path"));
10
7
  const generate_zod_openapi_hono_1 = require("../generator/zod-openapi-hono/openapi/generate-zod-openapi-hono");
11
8
  const config_1 = require("../config");
12
9
  const format_1 = require("../format");
10
+ const swagger_parser_1 = __importDefault(require("@apidevtools/swagger-parser"));
11
+ const node_fs_1 = __importDefault(require("node:fs"));
12
+ const node_path_1 = __importDefault(require("node:path"));
13
13
  async function viteMode(config = (0, config_1.getConfig)()) {
14
14
  try {
15
15
  if (config.input) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hono-takibi",
3
3
  "description": "Hono Takibi is a CLI tool that generates Hono routes from OpenAPI specifications.",
4
- "version": "0.5.4",
4
+ "version": "0.5.5",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "hono",
@@ -44,16 +44,16 @@
44
44
  "release": "npm pkg fix && npm publish"
45
45
  },
46
46
  "dependencies": {
47
- "@apidevtools/swagger-parser": "^10.1.0",
48
- "prettier": "^3.4.2"
47
+ "@apidevtools/swagger-parser": "^10.1.1",
48
+ "prettier": "^3.5.3"
49
49
  },
50
50
  "devDependencies": {
51
- "@hono/zod-openapi": "^0.18.3",
52
- "@types/node": "^22.10.2",
53
- "@vitest/coverage-v8": "^2.1.8",
54
- "tsx": "^4.7.1",
55
- "typescript": "^5.7.2",
56
- "vite": "^6.1.0",
57
- "vitest": "^2.1.8"
51
+ "@hono/zod-openapi": "^0.19.2",
52
+ "@types/node": "^22.13.10",
53
+ "@vitest/coverage-v8": "^3.0.8",
54
+ "tsx": "^4.19.3",
55
+ "typescript": "^5.8.2",
56
+ "vite": "^6.2.1",
57
+ "vitest": "^3.0.8"
58
58
  }
59
59
  }