hono-takibi 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +71 -58
  2. package/dist/config/index.d.ts +12 -6
  3. package/dist/config/index.js +10 -6
  4. package/dist/core/{schema/references/get-camel-case-schema-name.js → helper/get-camel-case-schema-name-helper.js} +1 -1
  5. package/dist/core/{schema/references/get-pascal-case-schema-name.js → helper/get-pascal-case-schema-name-helper.js} +1 -1
  6. package/dist/core/helper/get-variable-name-helper.js +1 -1
  7. package/dist/core/helper/get-variable-schema-name-helper.js +5 -5
  8. package/dist/core/schema/references/extract-refs.d.ts +2 -0
  9. package/dist/core/schema/references/extract-refs.js +26 -0
  10. package/dist/core/schema/references/get-ref-schema-name.d.ts +11 -0
  11. package/dist/core/schema/references/get-ref-schema-name.js +23 -0
  12. package/dist/core/schema/references/resolve-schemas-dependencies.js +45 -12
  13. package/dist/core/text/sanitize.d.ts +1 -0
  14. package/dist/core/text/sanitize.js +6 -0
  15. package/dist/core/validator/is-nullable-schema.d.ts +8 -0
  16. package/dist/core/validator/is-nullable-schema.js +12 -0
  17. package/dist/core/validator/is-ref-object.d.ts +6 -0
  18. package/dist/core/validator/is-ref-object.js +6 -0
  19. package/dist/format/index.d.ts +1 -0
  20. package/dist/format/index.js +12 -0
  21. package/dist/generators/app/generate-app-route-handler.d.ts +1 -0
  22. package/dist/generators/app/generate-app-route-handler.js +6 -0
  23. package/dist/generators/handler/generate-handler-name.d.ts +1 -0
  24. package/dist/generators/handler/generate-handler-name.js +7 -0
  25. package/dist/generators/handler/generate-handler.d.ts +1 -0
  26. package/dist/generators/handler/generate-handler.js +6 -0
  27. package/dist/generators/hono/app/generators/generate-apply-openapi-routes.d.ts +5 -0
  28. package/dist/generators/hono/app/generators/generate-apply-openapi-routes.js +11 -0
  29. package/dist/generators/hono/app/generators/generate-import-routes.d.ts +3 -0
  30. package/dist/generators/hono/app/generators/generate-import-routes.js +17 -0
  31. package/dist/generators/hono/app/helper/get-route-maps.d.ts +6 -0
  32. package/dist/generators/hono/app/helper/get-route-maps.js +16 -0
  33. package/dist/generators/hono/app/helper/process-import-map.d.ts +8 -0
  34. package/dist/generators/hono/app/helper/process-import-map.js +17 -0
  35. package/dist/generators/hono/app/index.d.ts +3 -0
  36. package/dist/generators/hono/app/index.js +55 -0
  37. package/dist/generators/hono/generate-zod-openapi-hono.js +5 -2
  38. package/dist/generators/hono/handler/generate-zod-openapi-hono-handler.d.ts +9 -0
  39. package/dist/generators/hono/handler/generate-zod-openapi-hono-handler.js +61 -0
  40. package/dist/generators/hono/handler/helper/group-handlers-by-file-name-helper.d.ts +2 -0
  41. package/dist/generators/hono/handler/helper/group-handlers-by-file-name-helper.js +24 -0
  42. package/dist/generators/hono/handler/import/generate-import-handlers.d.ts +4 -0
  43. package/dist/generators/hono/handler/import/generate-import-handlers.js +21 -0
  44. package/dist/generators/hono/handler/import/get-handler-imports.d.ts +7 -0
  45. package/dist/generators/hono/handler/import/get-handler-imports.js +18 -0
  46. package/dist/generators/openapi/components/allof/generate-allof-code.d.ts +10 -0
  47. package/dist/generators/openapi/components/allof/generate-allof-code.js +28 -0
  48. package/dist/generators/openapi/components/allof/process/process-alllof.d.ts +15 -0
  49. package/dist/generators/openapi/components/allof/process/process-alllof.js +23 -0
  50. package/dist/generators/openapi/components/anyof/generate-anyof-code.d.ts +3 -0
  51. package/dist/generators/openapi/components/anyof/generate-anyof-code.js +17 -0
  52. package/dist/generators/openapi/components/generate-components-code.js +7 -4
  53. package/dist/generators/openapi/components/generate-register-component.d.ts +2 -0
  54. package/dist/generators/openapi/components/generate-register-component.js +10 -0
  55. package/dist/generators/openapi/components/oneof/generate-oneof-code.d.ts +3 -0
  56. package/dist/generators/openapi/components/oneof/generate-oneof-code.js +17 -0
  57. package/dist/generators/openapi/docs/generate-docs.d.ts +8 -0
  58. package/dist/generators/openapi/docs/generate-docs.js +12 -0
  59. package/dist/generators/openapi/paths/generate-route.js +3 -3
  60. package/dist/generators/request/params/generate-params-object.js +1 -1
  61. package/dist/generators/response/schemas/generate-response-schema.js +2 -2
  62. package/dist/generators/types/generate-types-code.js +3 -0
  63. package/dist/generators/zod/generate-zod-enum.d.ts +2 -0
  64. package/dist/generators/zod/generate-zod-enum.js +11 -0
  65. package/dist/generators/zod/generate-zod-integer-schema.js +1 -1
  66. package/dist/generators/zod/generate-zod-intersection.d.ts +7 -0
  67. package/dist/generators/zod/generate-zod-intersection.js +12 -0
  68. package/dist/generators/zod/generate-zod-number-schema.js +1 -1
  69. package/dist/generators/zod/generate-zod-object.d.ts +3 -0
  70. package/dist/generators/zod/generate-zod-object.js +25 -0
  71. package/dist/generators/zod/generate-zod-partial-schema.d.ts +1 -0
  72. package/dist/generators/zod/{generate-partial-schema.js → generate-zod-partial-schema.js} +2 -2
  73. package/dist/generators/zod/generate-zod-properties-schema.js +2 -2
  74. package/dist/generators/zod/generate-zod-property-schema.js +1 -1
  75. package/dist/generators/zod/generate-zod-record-schema.js +1 -1
  76. package/dist/generators/zod/generate-zod-string-schema.js +1 -1
  77. package/dist/generators/zod/generate-zod-union.d.ts +12 -0
  78. package/dist/generators/zod/generate-zod-union.js +17 -0
  79. package/dist/generators/zod/{generate-zod-schema-definition.d.ts → openapi/generate-zod-to-openapi-schema-definition.d.ts} +1 -1
  80. package/dist/generators/zod/{generate-zod-schema-definition.js → openapi/generate-zod-to-openapi-schema-definition.js} +2 -2
  81. package/dist/generators/zod/{generate-zod-to-openapi.d.ts → openapi/generate-zod-to-openapi.d.ts} +1 -1
  82. package/dist/generators/zod/{generate-zod-schema.d.ts → schema/generate-zod-schema.d.ts} +2 -2
  83. package/dist/generators/zod/{generate-zod-schema.js → schema/generate-zod-schema.js} +31 -18
  84. package/dist/generators/zod/sub/generate-zod-schema-from-sub-schema.d.ts +10 -0
  85. package/dist/generators/zod/sub/generate-zod-schema-from-sub-schema.js +15 -0
  86. package/dist/index.js +28 -9
  87. package/dist/types/index.d.ts +26 -3
  88. package/dist/vite-plugin/index.d.ts +10 -0
  89. package/dist/vite-plugin/index.js +31 -0
  90. package/package.json +6 -1
  91. package/dist/generators/zod/generate-partial-schema.d.ts +0 -1
  92. /package/dist/core/{schema/references/get-camel-case-schema-name.d.ts → helper/get-camel-case-schema-name-helper.d.ts} +0 -0
  93. /package/dist/core/{schema/references/get-pascal-case-schema-name.d.ts → helper/get-pascal-case-schema-name-helper.d.ts} +0 -0
  94. /package/dist/generators/zod/{generate-zod-to-openapi.js → openapi/generate-zod-to-openapi.js} +0 -0
package/README.md CHANGED
@@ -5,64 +5,7 @@
5
5
  ![img](https://raw.githubusercontent.com/nakita628/hono-takibi/refs/heads/main/assets/img/hono-takibi.png)
6
6
 
7
7
  ```bash
8
- npm add -D hono-takibi
9
- ```
10
-
11
- ## Configuration
12
-
13
- You can customize the code generation behavior by creating a `hono-takibi.json` file in your project root.
14
-
15
- ### Schema Options
16
-
17
- | Option | Type | Default | Description |
18
- |--------|------|---------|-------------|
19
- | `namingCase` | `"camelCase"` \| `"PascalCase"` | `"camelCase"` | Naming convention for generated schema variables |
20
- | `exportEnabled` | `boolean` | `false` | When true, exports all schema definitions |
21
-
22
- ### Type Options
23
-
24
- | Option | Type | Default | Description |
25
- |--------|------|---------|-------------|
26
- | `namingCase` | `"camelCase"` \| `"PascalCase"` | `"PascalCase"` | Naming convention for generated type definitions |
27
- | `exportEnabled` | `boolean` | `false` | When true, exports all type definitions |
28
-
29
- ## Input and Output
30
-
31
- You can specify input and output paths in two ways:
32
-
33
- 1. Command line arguments:
34
-
35
- 2. Configuration file (`hono-takibi.json`):
36
-
37
- | Option | Type | Default | Description |
38
- |--------|------|---------|-------------|
39
- | `input` | `string` | `""` | Input file path |
40
- | `output` | `string` | `""` | Output file path |
41
-
42
- > **⚠️** When using a configuration file, command line arguments are not required. The configuration file settings take precedence over command line arguments.
43
- >
44
- > **🔥** When you have configured `hono-takibi.json`, you can simply run:
45
- > ```bash
46
- > npx hono-takibi
47
- > ```
48
-
49
- ### Examples
50
-
51
- * Default Behavior (camelCase schemas, PascalCase types)
52
-
53
- ```json
54
- {
55
- "input": "src/openapi/openapi.yaml",
56
- "output": "src/openapi/index.ts",
57
- "schemaOptions": {
58
- "namingCase": "camelCase",
59
- "exportEnabled": false
60
- },
61
- "typeOptions": {
62
- "namingCase": "PascalCase",
63
- "exportEnabled": false
64
- }
65
- }
8
+ npm install -D hono-takibi
66
9
  ```
67
10
 
68
11
  ## Migrate Legacy APIs to Hono
@@ -501,6 +444,76 @@ export const deletePostsIdRoute = createRoute({
501
444
  })
502
445
  ```
503
446
 
447
+ ## Configuration
448
+
449
+ You can customize the code generation behavior by creating a `hono-takibi.json` file in your project root.
450
+
451
+ ### Schema Options
452
+
453
+ | Option | Type | Default | Description |
454
+ |--------|------|---------|-------------|
455
+ | `name` | `"PascalCase"` \| `"camelCase"` | `"PascalCase"` | Naming convention for generated schema variables |
456
+ | `export` | `boolean` | `false` | When true, exports all schema definitions |
457
+
458
+ ### Type Options
459
+
460
+ | Option | Type | Default | Description |
461
+ |--------|------|---------|-------------|
462
+ | `name` | `"PascalCase"` \| `"camelCase"` | `"PascalCase"` | Naming convention for generated type definitions |
463
+ | `export` | `boolean` | `false` | When true, exports all type definitions |
464
+
465
+ ### App Options
466
+
467
+ | Option | Type | Default | Description |
468
+ |--------|------|---------|-------------|
469
+ | output | boolean | false | Controls the generation of application and handler files. When enabled, creates both the main application file and corresponding route handlers |
470
+ | test | boolean | false | Enables automatic generation of test files for your API endpoints. |
471
+ | basePath | string | "" | Specifies the base URL path for your API endpoints. |
472
+ | isDev | string | "process.env.NODE_ENV" | Defines the environment variable used to determine development mode. Controls features like Swagger UI availability |
473
+
474
+ ## Input and Output
475
+
476
+ You can specify input and output paths in two ways:
477
+
478
+ 1. Command line arguments:
479
+
480
+ 2. Configuration file (`hono-takibi.json`):
481
+
482
+ | Option | Type | Default | Description |
483
+ |--------|------|---------|-------------|
484
+ | `input` | `string` | `""` | Input file path |
485
+ | `output` | `string` | `""` | Output file path |
486
+
487
+ > **⚠️** When using a configuration file, command line arguments are not required. The configuration file settings take precedence over command line arguments.
488
+ >
489
+ > **🔥** When you have configured `hono-takibi.json`, you can simply run:
490
+ > ```bash
491
+ > npx hono-takibi
492
+ > ```
493
+
494
+ ### Examples
495
+
496
+ * Default Behavior (PascalCase schemas, PascalCase types)
497
+
498
+ ```json
499
+ {
500
+ "schema": {
501
+ "name": "PascalCase",
502
+ "export": false
503
+ },
504
+ "type": {
505
+ "name": "PascalCase",
506
+ "export": false
507
+ },
508
+ "app": {
509
+ "output": true,
510
+ "test": true,
511
+ "basePath": "api",
512
+ "isDev": "process.env.NODE_ENV"
513
+ }
514
+ }
515
+ ```
516
+
504
517
  This project is in **early development** and being maintained by a developer with about 2 years of experience. While I'm doing my best to create a useful tool:
505
518
 
506
519
  ### ⚠️ WARNING: Potential Breaking Changes Without Notice
@@ -1,11 +1,17 @@
1
1
  export type Config = {
2
- schemaOptions: {
3
- namingCase: 'camelCase' | 'PascalCase';
4
- exportEnabled: boolean;
2
+ schema: {
3
+ name: 'PascalCase' | 'camelCase';
4
+ export: boolean;
5
5
  };
6
- typeOptions: {
7
- namingCase: 'camelCase' | 'PascalCase';
8
- exportEnabled: boolean;
6
+ type: {
7
+ name: 'PascalCase' | 'camelCase';
8
+ export: boolean;
9
+ };
10
+ app?: {
11
+ output?: boolean;
12
+ test?: boolean;
13
+ basePath?: string;
14
+ isDev?: string;
9
15
  };
10
16
  input?: string;
11
17
  output?: string;
@@ -7,13 +7,17 @@ exports.DEFAULT_CONFIG = void 0;
7
7
  exports.getConfig = getConfig;
8
8
  const node_fs_1 = __importDefault(require("node:fs"));
9
9
  exports.DEFAULT_CONFIG = {
10
- schemaOptions: {
11
- namingCase: 'camelCase',
12
- exportEnabled: false,
10
+ schema: {
11
+ name: 'PascalCase',
12
+ export: false,
13
13
  },
14
- typeOptions: {
15
- namingCase: 'PascalCase',
16
- exportEnabled: false,
14
+ type: {
15
+ name: 'PascalCase',
16
+ export: false,
17
+ },
18
+ app: {
19
+ output: false,
20
+ test: false,
17
21
  },
18
22
  };
19
23
  /**
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCamelCaseSchemaName = getCamelCaseSchemaName;
4
- const decapitalize_1 = require("../../text/decapitalize");
4
+ const decapitalize_1 = require("../text/decapitalize");
5
5
  /**
6
6
  * Generates a camelCase schema name from a given schema name.
7
7
  *
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPascalCaseSchemaName = getPascalCaseSchemaName;
4
- const capitalize_1 = require("../../text/capitalize");
4
+ const capitalize_1 = require("../text/capitalize");
5
5
  /**
6
6
  * Generates a PascalCase schema name from a given schema name.
7
7
  *
@@ -4,6 +4,6 @@ exports.getVariableNameHelper = void 0;
4
4
  const capitalize_1 = require("../text/capitalize");
5
5
  const decapitalize_1 = require("../text/decapitalize");
6
6
  const getVariableNameHelper = (name, config) => {
7
- return config.typeOptions.namingCase === 'camelCase' ? (0, decapitalize_1.decapitalize)(name) : (0, capitalize_1.capitalize)(name);
7
+ return config.type.name === 'camelCase' ? (0, decapitalize_1.decapitalize)(name) : (0, capitalize_1.capitalize)(name);
8
8
  };
9
9
  exports.getVariableNameHelper = getVariableNameHelper;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getVariableSchemaNameHelper = void 0;
4
- const get_camel_case_schema_name_1 = require("../schema/references/get-camel-case-schema-name");
5
- const get_pascal_case_schema_name_1 = require("../schema/references/get-pascal-case-schema-name");
4
+ const get_camel_case_schema_name_helper_1 = require("./get-camel-case-schema-name-helper");
5
+ const get_pascal_case_schema_name_helper_1 = require("./get-pascal-case-schema-name-helper");
6
6
  const getVariableSchemaNameHelper = (name, config) => {
7
- return config.schemaOptions.namingCase === 'camelCase'
8
- ? (0, get_camel_case_schema_name_1.getCamelCaseSchemaName)(name)
9
- : (0, get_pascal_case_schema_name_1.getPascalCaseSchemaName)(name);
7
+ 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
10
  };
11
11
  exports.getVariableSchemaNameHelper = getVariableSchemaNameHelper;
@@ -0,0 +1,2 @@
1
+ import type { Schema } from '../../../types';
2
+ export declare function extractRefs(schema: Schema): string[];
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractRefs = extractRefs;
4
+ const is_ref_object_1 = require("../../validator/is-ref-object");
5
+ function extractRefs(schema) {
6
+ const refs = [];
7
+ const traverse = (obj) => {
8
+ if (!(0, is_ref_object_1.isRefObject)(obj))
9
+ return;
10
+ for (const [key, value] of Object.entries(obj)) {
11
+ if (key !== '$ref') {
12
+ if ((0, is_ref_object_1.isRefObject)(value)) {
13
+ traverse(value);
14
+ }
15
+ continue;
16
+ }
17
+ if (typeof value !== 'string')
18
+ continue;
19
+ const refParts = value.split('/');
20
+ const refName = refParts[refParts.length - 1];
21
+ refs.push(refName);
22
+ }
23
+ };
24
+ traverse(schema);
25
+ return refs;
26
+ }
@@ -0,0 +1,11 @@
1
+ import type { Config } from '../../../config';
2
+ import type { Schema } from '../../../types';
3
+ /**
4
+ * Retrieves the referenced schema name from a schema object.
5
+ *
6
+ * @param schema - The schema object
7
+ * @param config - The configuration object
8
+ * @returns The referenced schema name
9
+ * @throws Will throw an error if the $ref property or the reference name is not found
10
+ */
11
+ export declare function getRefSchemaName(schema: Schema, config: Config): string;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRefSchemaName = getRefSchemaName;
4
+ const get_variable_schema_name_helper_1 = require("../../helper/get-variable-schema-name-helper");
5
+ const get_ref_name_1 = require("./get-ref-name");
6
+ /**
7
+ * Retrieves the referenced schema name from a schema object.
8
+ *
9
+ * @param schema - The schema object
10
+ * @param config - The configuration object
11
+ * @returns The referenced schema name
12
+ * @throws Will throw an error if the $ref property or the reference name is not found
13
+ */
14
+ function getRefSchemaName(schema, config) {
15
+ if (!schema.$ref) {
16
+ throw new Error('refName is not found');
17
+ }
18
+ const refName = (0, get_ref_name_1.getRefName)(schema.$ref);
19
+ if (!refName) {
20
+ throw new Error('refName is not found');
21
+ }
22
+ return (0, get_variable_schema_name_helper_1.getVariableSchemaNameHelper)(refName, config);
23
+ }
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveSchemasDependencies = resolveSchemasDependencies;
4
- const resolve_schema_order_1 = require("./resolve-schema-order");
5
- const resolve_schema_references_1 = require("./resolve-schema-references");
4
+ const extract_refs_1 = require("./extract-refs");
6
5
  /**
7
6
  * Resolves dependencies between schemas and returns them in topological order for safe processing
8
7
  *
@@ -50,16 +49,50 @@ const resolve_schema_references_1 = require("./resolve-schema-references");
50
49
  * - Uses depth-first search for dependency resolution
51
50
  * - Automatically handles circular dependencies by preventing infinite recursion
52
51
  */
52
+ // export function resolveSchemasDependencies(schemas: Record<string, Schema>): string[] {
53
+ // // 1. get schema reference relations as a map
54
+ // const dependencies = resolveSchemaReferences(schemas)
55
+ // // 2. initialize ordered list and visited set
56
+ // const ordered: string[] = []
57
+ // const visited = new Set<string>()
58
+ // // 3. resolve schema order
59
+ // for (const name of Object.keys(schemas)) {
60
+ // resolveSchemaOrder(name, dependencies, visited, ordered)
61
+ // }
62
+ // // 4. return ordered list
63
+ // return ordered
64
+ // }
53
65
  function resolveSchemasDependencies(schemas) {
54
- // 1. get schema reference relations as a map
55
- const dependencies = (0, resolve_schema_references_1.resolveSchemaReferences)(schemas);
56
- // 2. initialize ordered list and visited set
57
- const ordered = [];
58
- const visited = new Set();
59
- // 3. resolve schema order
60
- for (const name of Object.keys(schemas)) {
61
- (0, resolve_schema_order_1.resolveSchemaOrder)(name, dependencies, visited, ordered);
66
+ const visited = {};
67
+ const temp = {};
68
+ const result = [];
69
+ const visit = (schemaName) => {
70
+ if (temp[schemaName]) {
71
+ throw new Error(`bad schema: ${schemaName}`);
72
+ }
73
+ if (!visited[schemaName]) {
74
+ temp[schemaName] = true;
75
+ const schema = schemas[schemaName];
76
+ if (schema) {
77
+ const refs = (0, extract_refs_1.extractRefs)(schema);
78
+ for (const ref of refs) {
79
+ if (schemas[ref]) {
80
+ visit(ref);
81
+ }
82
+ else {
83
+ console.warn(`not found schema: ${ref}`);
84
+ }
85
+ }
86
+ }
87
+ visited[schemaName] = true;
88
+ temp[schemaName] = false;
89
+ result.push(schemaName);
90
+ }
91
+ };
92
+ for (const schemaName of Object.keys(schemas)) {
93
+ if (!visited[schemaName]) {
94
+ visit(schemaName);
95
+ }
62
96
  }
63
- // 4. return ordered list
64
- return ordered;
97
+ return result;
65
98
  }
@@ -0,0 +1 @@
1
+ export declare function sanitize(text: string): string;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sanitize = sanitize;
4
+ function sanitize(text) {
5
+ return text.replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
6
+ }
@@ -0,0 +1,8 @@
1
+ import type { Schema } from '../../types';
2
+ /**
3
+ * Determines whether a given sub-schema is `nullable`.
4
+ *
5
+ * @param subSchema - The sub-schema to evaluate
6
+ * @returns `true` if `nullable` is set to `true` and it is the only key in the schema, otherwise `false`
7
+ */
8
+ export declare function isNullableSchema(schema: Schema): boolean;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNullableSchema = isNullableSchema;
4
+ /**
5
+ * Determines whether a given sub-schema is `nullable`.
6
+ *
7
+ * @param subSchema - The sub-schema to evaluate
8
+ * @returns `true` if `nullable` is set to `true` and it is the only key in the schema, otherwise `false`
9
+ */
10
+ function isNullableSchema(schema) {
11
+ return 'nullable' in schema && schema.nullable === true && Object.keys(schema).length === 1;
12
+ }
@@ -0,0 +1,6 @@
1
+ type RefObject = {
2
+ $ref?: string;
3
+ [key: string]: unknown;
4
+ };
5
+ export declare function isRefObject(value: unknown): value is RefObject;
6
+ export {};
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRefObject = isRefObject;
4
+ function isRefObject(value) {
5
+ return typeof value === 'object' && value !== null;
6
+ }
@@ -0,0 +1 @@
1
+ export declare function formatCode(code: string): Promise<string>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatCode = formatCode;
4
+ const prettier_1 = require("prettier");
5
+ async function formatCode(code) {
6
+ return await (0, prettier_1.format)(code, {
7
+ parser: 'typescript',
8
+ printWidth: 100,
9
+ singleQuote: true,
10
+ semi: false,
11
+ });
12
+ }
@@ -0,0 +1 @@
1
+ export declare function generateAppRouteHandler(routeName: string, handlerName: string): string;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateAppRouteHandler = generateAppRouteHandler;
4
+ function generateAppRouteHandler(routeName, handlerName) {
5
+ return `.openapi(${routeName},${handlerName})`;
6
+ }
@@ -0,0 +1 @@
1
+ export declare function generateHandlerName(method: string, path: string): string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateHandlerName = generateHandlerName;
4
+ const generate_route_name_1 = require("../openapi/paths/generate-route-name");
5
+ function generateHandlerName(method, path) {
6
+ return `${(0, generate_route_name_1.generateRouteName)(method, path)}Handler`;
7
+ }
@@ -0,0 +1 @@
1
+ export declare function generateHandler(handlerName: string, routeName: string): string;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateHandler = generateHandler;
4
+ function generateHandler(handlerName, routeName) {
5
+ return `export const ${handlerName}:RouteHandler<typeof ${routeName}>=async(c)=>{}`;
6
+ }
@@ -0,0 +1,5 @@
1
+ export declare function generateApplyOpenapiRoutes(routeMappings: {
2
+ routeName: string;
3
+ handlerName: string;
4
+ path: string;
5
+ }[]): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateApplyOpenapiRoutes = generateApplyOpenapiRoutes;
4
+ const generate_app_route_handler_1 = require("../../../app/generate-app-route-handler");
5
+ function generateApplyOpenapiRoutes(routeMappings) {
6
+ return routeMappings
7
+ .map(({ routeName, handlerName }) => {
8
+ return (0, generate_app_route_handler_1.generateAppRouteHandler)(routeName, handlerName);
9
+ })
10
+ .join('\n');
11
+ }
@@ -0,0 +1,3 @@
1
+ export declare function generateImportRoutes(importsMap: {
2
+ [importPath: string]: string[];
3
+ }): string[];
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateImportRoutes = generateImportRoutes;
4
+ function generateImportRoutes(importsMap) {
5
+ const importRoutes = [];
6
+ for (const [importPath, names] of Object.entries(importsMap)) {
7
+ const uniqueNames = Array.from(new Set(names));
8
+ if (importPath.includes('/index.ts')) {
9
+ const normalizedPath = importPath.replace(/\/index\.ts$/, '');
10
+ importRoutes.push(`import { ${uniqueNames.join(',')} } from './${normalizedPath}';`);
11
+ }
12
+ else {
13
+ importRoutes.push(`import { ${uniqueNames.join(',')} } from './${importPath}';`);
14
+ }
15
+ }
16
+ return importRoutes;
17
+ }
@@ -0,0 +1,6 @@
1
+ import type { OpenAPISpec } from '../../../../types';
2
+ export declare function getRouteMaps(openAPISpec: OpenAPISpec): {
3
+ routeName: string;
4
+ handlerName: string;
5
+ path: string;
6
+ }[];
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRouteMaps = getRouteMaps;
4
+ const generate_handler_name_1 = require("../../../handler/generate-handler-name");
5
+ const generate_route_name_1 = require("../../../openapi/paths/generate-route-name");
6
+ function getRouteMaps(openAPISpec) {
7
+ const paths = openAPISpec.paths;
8
+ const routeMappings = Object.entries(paths).flatMap(([path, pathItem]) => {
9
+ return Object.entries(pathItem).flatMap(([method]) => {
10
+ const routeName = (0, generate_route_name_1.generateRouteName)(method, path);
11
+ const handlerName = (0, generate_handler_name_1.generateHandlerName)(method, path);
12
+ return { routeName, handlerName, path };
13
+ });
14
+ });
15
+ return routeMappings;
16
+ }
@@ -0,0 +1,8 @@
1
+ import type { Config } from '../../../../config';
2
+ export declare function processImportMap(routeMappings: {
3
+ routeName: string;
4
+ handlerName: string;
5
+ path: string;
6
+ }[], config: Config): {
7
+ [importPath: string]: string[];
8
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processImportMap = processImportMap;
4
+ function processImportMap(routeMappings, config) {
5
+ const importsMap = {};
6
+ for (const { routeName } of routeMappings) {
7
+ const importPath = config.output;
8
+ if (!importPath) {
9
+ throw new Error('Output path is required');
10
+ }
11
+ if (!importsMap[importPath]) {
12
+ importsMap[importPath] = [];
13
+ }
14
+ importsMap[importPath].push(routeName);
15
+ }
16
+ return importsMap;
17
+ }
@@ -0,0 +1,3 @@
1
+ import type { OpenAPISpec } from '../../../types';
2
+ import type { Config } from '../../../config';
3
+ export declare function generateApp(openAPISpec: OpenAPISpec, config: Config): string;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateApp = generateApp;
4
+ const generate_docs_1 = require("../../openapi/docs/generate-docs");
5
+ const get_handler_imports_1 = require("../handler/import/get-handler-imports");
6
+ const get_route_maps_1 = require("./helper/get-route-maps");
7
+ const generate_import_handlers_1 = require("../handler/import/generate-import-handlers");
8
+ const generate_register_component_1 = require("../../openapi/components/generate-register-component");
9
+ const generate_import_routes_1 = require("./generators/generate-import-routes");
10
+ const generate_apply_openapi_routes_1 = require("./generators/generate-apply-openapi-routes");
11
+ const process_import_map_1 = require("./helper/process-import-map");
12
+ const OPENAPI_HONO_IMPORT = `import { OpenAPIHono } from '@hono/zod-openapi'`;
13
+ const SWAGGER_UI_IMPORT = `import { swaggerUI } from '@hono/swagger-ui'`;
14
+ const APP = 'const app = new OpenAPIHono()';
15
+ const ADD_TYPE = 'export type AddType = typeof api';
16
+ const EXPORT_APP = 'export default app';
17
+ function generateApp(openAPISpec, config) {
18
+ const routeMappings = (0, get_route_maps_1.getRouteMaps)(openAPISpec);
19
+ const importsMap = (0, process_import_map_1.processImportMap)(routeMappings, config);
20
+ const importRoutes = (0, generate_import_routes_1.generateImportRoutes)(importsMap);
21
+ const handlerImportsMap = (0, get_handler_imports_1.getHandlerImports)(routeMappings);
22
+ const importHandlers = (0, generate_import_handlers_1.generateImportHandlers)(handlerImportsMap, config);
23
+ const importHandlersCode = importHandlers.join('\n');
24
+ const applyOpenapiRoutes = (0, generate_apply_openapi_routes_1.generateApplyOpenapiRoutes)(routeMappings);
25
+ const openAPIHono = config.app?.basePath ? `${APP}.basePath('${config.app.basePath}')` : APP;
26
+ const app = `app${applyOpenapiRoutes}`;
27
+ const api = `const api = ${app}`;
28
+ const docs = (0, generate_docs_1.generateDocs)(openAPISpec);
29
+ const isDev = config?.app?.isDev
30
+ ? `const isDev = ${config.app.isDev} === 'development'`
31
+ : `const isDev = process.env.NODE_ENV === 'development'`;
32
+ const basePath = config?.app?.basePath ? `/${config.app.basePath}/doc` : '/doc';
33
+ const { components } = openAPISpec;
34
+ const registerComponent = components?.securitySchemes
35
+ ? (0, generate_register_component_1.generateRegisterComponent)(components.securitySchemes)
36
+ : '';
37
+ const swagger = `if(isDev){${registerComponent}\napp.doc('${'/doc'}',${JSON.stringify(docs)}).get('/ui',swaggerUI({url:'${basePath}'}))}`;
38
+ const sections = [
39
+ // 1. imports
40
+ [OPENAPI_HONO_IMPORT, SWAGGER_UI_IMPORT, importRoutes.join(''), importHandlersCode].join('\n'),
41
+ // 2. app initialization
42
+ openAPIHono,
43
+ // 3. api setup
44
+ api,
45
+ // 4. development settings
46
+ isDev,
47
+ // 5. swagger setup
48
+ swagger,
49
+ // 6. types and exports
50
+ ADD_TYPE,
51
+ // 7. export app
52
+ EXPORT_APP,
53
+ ];
54
+ return sections.join('\n\n');
55
+ }