hono-takibi 0.0.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 (88) hide show
  1. package/README.md +471 -0
  2. package/dist/core/schema/references/find-references.d.ts +35 -0
  3. package/dist/core/schema/references/find-references.js +42 -0
  4. package/dist/core/schema/references/get-camel-case-schema-name.d.ts +7 -0
  5. package/dist/core/schema/references/get-camel-case-schema-name.js +14 -0
  6. package/dist/core/schema/references/get-ref-name.d.ts +38 -0
  7. package/dist/core/schema/references/get-ref-name.js +47 -0
  8. package/dist/core/schema/references/resolve-schema-order.d.ts +30 -0
  9. package/dist/core/schema/references/resolve-schema-order.js +48 -0
  10. package/dist/core/schema/references/resolve-schema-references.d.ts +49 -0
  11. package/dist/core/schema/references/resolve-schema-references.js +61 -0
  12. package/dist/core/schema/references/resolve-schemas-dependencies.d.ts +49 -0
  13. package/dist/core/schema/references/resolve-schemas-dependencies.js +65 -0
  14. package/dist/core/schema/references/traverse_schema.d.ts +48 -0
  15. package/dist/core/schema/references/traverse_schema.js +70 -0
  16. package/dist/core/text/capitalize.d.ts +18 -0
  17. package/dist/core/text/capitalize.js +23 -0
  18. package/dist/core/text/decapitalize.d.ts +17 -0
  19. package/dist/core/text/decapitalize.js +22 -0
  20. package/dist/core/text/remove-zod-prefix.d.ts +8 -0
  21. package/dist/core/text/remove-zod-prefix.js +13 -0
  22. package/dist/core/validator/is-format-number.d.ts +2 -0
  23. package/dist/core/validator/is-format-number.js +6 -0
  24. package/dist/core/validator/is-format-string.d.ts +2 -0
  25. package/dist/core/validator/is-format-string.js +24 -0
  26. package/dist/core/validator/is-http-method.d.ts +9 -0
  27. package/dist/core/validator/is-http-method.js +19 -0
  28. package/dist/core/validator/is-operation.d.ts +15 -0
  29. package/dist/core/validator/is-operation.js +19 -0
  30. package/dist/core/zod/get-zod-string-format.d.ts +30 -0
  31. package/dist/core/zod/get-zod-string-format.js +66 -0
  32. package/dist/generators/hono/generate-hono.d.ts +9 -0
  33. package/dist/generators/hono/generate-hono.js +29 -0
  34. package/dist/generators/openapi/components/generate-components-code.d.ts +46 -0
  35. package/dist/generators/openapi/components/generate-components-code.js +79 -0
  36. package/dist/generators/openapi/paths/generate-create-route.d.ts +58 -0
  37. package/dist/generators/openapi/paths/generate-create-route.js +61 -0
  38. package/dist/generators/openapi/paths/generate-route-code.d.ts +53 -0
  39. package/dist/generators/openapi/paths/generate-route-code.js +85 -0
  40. package/dist/generators/openapi/paths/generate-route-name.d.ts +30 -0
  41. package/dist/generators/openapi/paths/generate-route-name.js +48 -0
  42. package/dist/generators/openapi/paths/generate-route.d.ts +51 -0
  43. package/dist/generators/openapi/paths/generate-route.js +73 -0
  44. package/dist/generators/openapi/paths/generate-schemas-export.d.ts +11 -0
  45. package/dist/generators/openapi/paths/generate-schemas-export.js +18 -0
  46. package/dist/generators/request/body/generate-insert-request-body.d.ts +32 -0
  47. package/dist/generators/request/body/generate-insert-request-body.js +37 -0
  48. package/dist/generators/request/body/generate-request-body.d.ts +18 -0
  49. package/dist/generators/request/body/generate-request-body.js +23 -0
  50. package/dist/generators/request/object/generate-format-request-object.d.ts +29 -0
  51. package/dist/generators/request/object/generate-format-request-object.js +34 -0
  52. package/dist/generators/request/params/generate-params-object.d.ts +62 -0
  53. package/dist/generators/request/params/generate-params-object.js +93 -0
  54. package/dist/generators/request/params/generate-request-parameter.d.ts +49 -0
  55. package/dist/generators/request/params/generate-request-parameter.js +79 -0
  56. package/dist/generators/request/params/generate-request-params-array.d.ts +37 -0
  57. package/dist/generators/request/params/generate-request-params-array.js +56 -0
  58. package/dist/generators/request/params/generate-request-params.d.ts +34 -0
  59. package/dist/generators/request/params/generate-request-params.js +39 -0
  60. package/dist/generators/response/schemas/generate-response-schema.d.ts +59 -0
  61. package/dist/generators/response/schemas/generate-response-schema.js +83 -0
  62. package/dist/generators/zod/generate-zod-array.d.ts +31 -0
  63. package/dist/generators/zod/generate-zod-array.js +36 -0
  64. package/dist/generators/zod/generate-zod-coerce.d.ts +10 -0
  65. package/dist/generators/zod/generate-zod-coerce.js +17 -0
  66. package/dist/generators/zod/generate-zod-integer-schema.d.ts +15 -0
  67. package/dist/generators/zod/generate-zod-integer-schema.js +24 -0
  68. package/dist/generators/zod/generate-zod-number-schema.d.ts +16 -0
  69. package/dist/generators/zod/generate-zod-number-schema.js +26 -0
  70. package/dist/generators/zod/generate-zod-object-schema.d.ts +36 -0
  71. package/dist/generators/zod/generate-zod-object-schema.js +43 -0
  72. package/dist/generators/zod/generate-zod-properties-schema.d.ts +50 -0
  73. package/dist/generators/zod/generate-zod-properties-schema.js +60 -0
  74. package/dist/generators/zod/generate-zod-property-schema.d.ts +25 -0
  75. package/dist/generators/zod/generate-zod-property-schema.js +47 -0
  76. package/dist/generators/zod/generate-zod-record-schema.d.ts +34 -0
  77. package/dist/generators/zod/generate-zod-record-schema.js +37 -0
  78. package/dist/generators/zod/generate-zod-schema-definition.d.ts +22 -0
  79. package/dist/generators/zod/generate-zod-schema-definition.js +27 -0
  80. package/dist/generators/zod/generate-zod-schema.d.ts +59 -0
  81. package/dist/generators/zod/generate-zod-schema.js +136 -0
  82. package/dist/generators/zod/generate-zod-string-schema.d.ts +46 -0
  83. package/dist/generators/zod/generate-zod-string-schema.js +54 -0
  84. package/dist/index.d.ts +20 -0
  85. package/dist/index.js +85 -0
  86. package/dist/types/index.d.ts +170 -0
  87. package/dist/types/index.js +2 -0
  88. package/package.json +47 -0
package/README.md ADDED
@@ -0,0 +1,471 @@
1
+ ![img](assets/icon/hono-takibi.png)
2
+
3
+ # Hono Takibi
4
+
5
+ ![img](assets/img/hono-takibi.png)
6
+
7
+ ## Migrate Legacy APIs to Hono
8
+
9
+ **Hono Takibi** is an OpenAPI-to-Hono code generator, specifically developed to assist in migrating APIs from various programming languages to Hono. This tool automates the creation of type-safe Hono routes from your existing OpenAPI specifications, making it easier to transition from legacy systems (Ruby, Perl, PHP, etc.) to a modern Hono architecture.
10
+
11
+ ## What Problem Does It Solve?
12
+
13
+ Moving to [Zod OpenAPI Hono](https://hono.dev/examples/zod-openapi) requires:
14
+
15
+ * Manual conversion of OpenAPI paths to Hono routes
16
+ * Translation of OpenAPI schemas to Zod schemas
17
+ * Implementation of type-safe request/response handling
18
+
19
+ If you have OpenAPI specifications, Hono Takibi automates the conversion process to [@hono/zod-openapi](https://github.com/honojs/middleware/tree/main/packages/zod-openapi), allowing you to focus on implementing your business logic rather than dealing with boilerplate code. While we aim for full compatibility in the generated code, we're continuously working to improve the conversion accuracy and support more OpenAPI features. We welcome feedback and contributions to make this tool even better for the community.
20
+
21
+ **Hono Takibi** automates this process by:
22
+ - Converting OpenAPI schemas to Zod schemas
23
+ - Generating type-safe route definitions
24
+ - Creating proper variable names and exports
25
+
26
+ ```bash
27
+ npm add -D hono-takibi
28
+ ```
29
+
30
+ # Usage
31
+
32
+ ```bash
33
+ npx hono-takibi path/to/input.yaml -o path/to/output.ts
34
+ ```
35
+
36
+ # Example
37
+
38
+ ```bash
39
+ npx hono-takibi example/hono-rest-example.yaml -o routes/index.ts
40
+ ```
41
+
42
+ input:
43
+
44
+ ```yaml
45
+ openapi: 3.1.0
46
+ info:
47
+ title: Hono API
48
+ version: v1
49
+
50
+ components:
51
+ schemas:
52
+ Error:
53
+ type: object
54
+ properties:
55
+ message:
56
+ type: string
57
+ required:
58
+ - message
59
+ Post:
60
+ type: object
61
+ properties:
62
+ id:
63
+ type: string
64
+ format: uuid
65
+ description: Unique identifier of the post
66
+ post:
67
+ type: string
68
+ description: Content of the post
69
+ minLength: 1
70
+ maxLength: 140
71
+ createdAt:
72
+ type: string
73
+ format: date-time
74
+ description: Timestamp when the post was created
75
+ updatedAt:
76
+ type: string
77
+ format: date-time
78
+ description: Timestamp when the post was last updated
79
+ required:
80
+ - id
81
+ - post
82
+ - createdAt
83
+ - updatedAt
84
+
85
+ tags:
86
+ - name: Hono
87
+ description: Endpoints related to general Hono operations
88
+ - name: Post
89
+ description: Endpoints for creating, retrieving, updating, and deleting posts
90
+
91
+ paths:
92
+ /:
93
+ get:
94
+ tags:
95
+ - Hono
96
+ summary: Welcome message
97
+ description: Retrieve a simple welcome message from the Hono API.
98
+ responses:
99
+ '200':
100
+ description: Successful response with a welcome message.
101
+ content:
102
+ application/json:
103
+ schema:
104
+ type: object
105
+ properties:
106
+ message:
107
+ type: string
108
+ example: Hono🔥
109
+ required:
110
+ - message
111
+
112
+ /posts:
113
+ post:
114
+ tags:
115
+ - Post
116
+ summary: Create a new post
117
+ description: Submit a new post with a maximum length of 140 characters.
118
+ requestBody:
119
+ required: true
120
+ content:
121
+ application/json:
122
+ schema:
123
+ type: object
124
+ properties:
125
+ post:
126
+ type: string
127
+ description: Content of the post
128
+ minLength: 1
129
+ maxLength: 140
130
+ required:
131
+ - post
132
+ example:
133
+ post: "This is my first post!"
134
+ responses:
135
+ '201':
136
+ description: Post successfully created.
137
+ content:
138
+ application/json:
139
+ schema:
140
+ $ref: '#/components/schemas/Error'
141
+ example:
142
+ message: Created
143
+ '400':
144
+ description: Invalid request due to bad input.
145
+ content:
146
+ application/json:
147
+ schema:
148
+ $ref: '#/components/schemas/Error'
149
+ example:
150
+ message: Post content is required and must be between 1 and 140 characters.
151
+ '500':
152
+ description: Internal server error.
153
+ content:
154
+ application/json:
155
+ schema:
156
+ $ref: '#/components/schemas/Error'
157
+ example:
158
+ message: An unexpected error occurred. Please try again later.
159
+
160
+ get:
161
+ tags:
162
+ - Post
163
+ summary: Retrieve a list of posts
164
+ description: Retrieve a paginated list of posts. Specify the page number and the number of posts per page.
165
+ parameters:
166
+ - in: query
167
+ name: page
168
+ required: false
169
+ schema:
170
+ type: integer
171
+ minimum: 1
172
+ default: 1
173
+ description: The page number to retrieve. Must be a positive integer. Defaults to 1.
174
+ - in: query
175
+ name: rows
176
+ required: false
177
+ schema:
178
+ type: integer
179
+ minimum: 1
180
+ default: 10
181
+ description: The number of posts per page. Must be a positive integer. Defaults to 10.
182
+ responses:
183
+ '200':
184
+ description: Successfully retrieved a list of posts.
185
+ content:
186
+ application/json:
187
+ schema:
188
+ type: array
189
+ items:
190
+ $ref: '#/components/schemas/Post'
191
+ example:
192
+ - id: "123e4567-e89b-12d3-a456-426614174000"
193
+ post: "Hello world!"
194
+ createdAt: "2024-12-01T12:34:56Z"
195
+ updatedAt: "2024-12-02T14:20:00Z"
196
+ '400':
197
+ description: Invalid request due to bad input.
198
+ content:
199
+ application/json:
200
+ schema:
201
+ $ref: '#/components/schemas/Error'
202
+ example:
203
+ message: Invalid page or rows parameter. Both must be positive integers.
204
+ '500':
205
+ description: Internal server error.
206
+ content:
207
+ application/json:
208
+ schema:
209
+ $ref: '#/components/schemas/Error'
210
+ example:
211
+ message: An unexpected error occurred. Please try again later.
212
+
213
+ /posts/{id}:
214
+ put:
215
+ tags:
216
+ - Post
217
+ summary: Update an existing post
218
+ description: Update the content of an existing post identified by its unique ID.
219
+ parameters:
220
+ - in: path
221
+ name: id
222
+ required: true
223
+ schema:
224
+ type: string
225
+ format: uuid
226
+ description: Unique identifier of the post.
227
+ requestBody:
228
+ required: true
229
+ content:
230
+ application/json:
231
+ schema:
232
+ type: object
233
+ properties:
234
+ post:
235
+ type: string
236
+ description: Updated content for the post
237
+ minLength: 1
238
+ maxLength: 140
239
+ required:
240
+ - post
241
+ example:
242
+ post: "Updated post content."
243
+ responses:
244
+ '204':
245
+ description: Post successfully updated.
246
+ '400':
247
+ description: Invalid input.
248
+ content:
249
+ application/json:
250
+ schema:
251
+ $ref: '#/components/schemas/Error'
252
+ example:
253
+ message: Post content is required and must be between 1 and 140 characters.
254
+ '500':
255
+ description: Internal server error.
256
+ content:
257
+ application/json:
258
+ schema:
259
+ $ref: '#/components/schemas/Error'
260
+ example:
261
+ message: An unexpected error occurred. Please try again later.
262
+
263
+ delete:
264
+ tags:
265
+ - Post
266
+ summary: Delete a post
267
+ description: Delete an existing post identified by its unique ID.
268
+ parameters:
269
+ - in: path
270
+ name: id
271
+ required: true
272
+ schema:
273
+ type: string
274
+ format: uuid
275
+ description: Unique identifier of the post.
276
+ responses:
277
+ '204':
278
+ description: Post successfully deleted.
279
+ '400':
280
+ description: Invalid input.
281
+ content:
282
+ application/json:
283
+ schema:
284
+ $ref: '#/components/schemas/Error'
285
+ example:
286
+ message: Invalid post ID.
287
+ '500':
288
+ description: Internal server error.
289
+ content:
290
+ application/json:
291
+ schema:
292
+ $ref: '#/components/schemas/Error'
293
+ example:
294
+ message: An unexpected error occurred. Please try again later.
295
+ ```
296
+
297
+ output:
298
+
299
+ ```ts
300
+ import { createRoute, z } from '@hono/zod-openapi'
301
+
302
+ const errorSchema = z.object({ message: z.string() })
303
+
304
+ const postSchema = z.object({
305
+ id: z.string().uuid(),
306
+ post: z.string().min(1).max(140),
307
+ createdAt: z.string().datetime(),
308
+ updatedAt: z.string().datetime(),
309
+ })
310
+
311
+ export const schemas = {
312
+ errorSchema,
313
+ postSchema,
314
+ }
315
+
316
+ export const getRoute = createRoute({
317
+ tags: ['Hono'],
318
+ method: 'get',
319
+ path: '/',
320
+ description: 'Retrieve a simple welcome message from the Hono API.',
321
+ responses: {
322
+ 200: {
323
+ description: 'Successful response with a welcome message.',
324
+ content: { 'application/json': { schema: z.object({ message: z.string() }) } },
325
+ },
326
+ },
327
+ })
328
+
329
+ export const postPostsRoute = createRoute({
330
+ tags: ['Post'],
331
+ method: 'post',
332
+ path: '/posts',
333
+ description: 'Submit a new post with a maximum length of 140 characters.',
334
+ request: {
335
+ body: {
336
+ required: true,
337
+ content: { 'application/json': { schema: z.object({ post: z.string().min(1).max(140) }) } },
338
+ },
339
+ },
340
+ responses: {
341
+ 201: {
342
+ description: 'Post successfully created.',
343
+ content: { 'application/json': { schema: errorSchema } },
344
+ },
345
+ 400: {
346
+ description: 'Invalid request due to bad input.',
347
+ content: { 'application/json': { schema: errorSchema } },
348
+ },
349
+ 500: {
350
+ description: 'Internal server error.',
351
+ content: { 'application/json': { schema: errorSchema } },
352
+ },
353
+ },
354
+ })
355
+
356
+ export const getPostsRoute = createRoute({
357
+ tags: ['Post'],
358
+ method: 'get',
359
+ path: '/posts',
360
+ description:
361
+ 'Retrieve a paginated list of posts. Specify the page number and the number of posts per page.',
362
+ request: {
363
+ query: z.object({
364
+ page: z.string().pipe(z.coerce.number().int().min(0)).optional(),
365
+ rows: z.string().pipe(z.coerce.number().int().min(0)).optional(),
366
+ }),
367
+ },
368
+ responses: {
369
+ 200: {
370
+ description: 'Successfully retrieved a list of posts.',
371
+ content: { 'application/json': { schema: z.array(postSchema) } },
372
+ },
373
+ 400: {
374
+ description: 'Invalid request due to bad input.',
375
+ content: { 'application/json': { schema: errorSchema } },
376
+ },
377
+ 500: {
378
+ description: 'Internal server error.',
379
+ content: { 'application/json': { schema: errorSchema } },
380
+ },
381
+ },
382
+ })
383
+
384
+ export const putPostsIdRoute = createRoute({
385
+ tags: ['Post'],
386
+ method: 'put',
387
+ path: '/posts/{id}',
388
+ description: 'Update the content of an existing post identified by its unique ID.',
389
+ request: {
390
+ body: {
391
+ required: true,
392
+ content: { 'application/json': { schema: z.object({ post: z.string().min(1).max(140) }) } },
393
+ },
394
+ params: z.object({ id: z.string().uuid() }),
395
+ },
396
+ responses: {
397
+ 204: { description: 'Post successfully updated.' },
398
+ 400: {
399
+ description: 'Invalid input.',
400
+ content: { 'application/json': { schema: errorSchema } },
401
+ },
402
+ 500: {
403
+ description: 'Internal server error.',
404
+ content: { 'application/json': { schema: errorSchema } },
405
+ },
406
+ },
407
+ })
408
+
409
+ export const deletePostsIdRoute = createRoute({
410
+ tags: ['Post'],
411
+ method: 'delete',
412
+ path: '/posts/{id}',
413
+ description: 'Delete an existing post identified by its unique ID.',
414
+ request: { params: z.object({ id: z.string().uuid() }) },
415
+ responses: {
416
+ 204: { description: 'Post successfully deleted.' },
417
+ 400: {
418
+ description: 'Invalid input.',
419
+ content: { 'application/json': { schema: errorSchema } },
420
+ },
421
+ 500: {
422
+ description: 'Internal server error.',
423
+ content: { 'application/json': { schema: errorSchema } },
424
+ },
425
+ },
426
+ })
427
+ ```
428
+
429
+ ## ⚠️ Development Status
430
+
431
+ 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:
432
+
433
+ We welcome feedback and contributions to improve the tool!
434
+
435
+ ### Current Limitations
436
+
437
+ 1. **Schema Naming Convention**
438
+ - Only generates camelCase schema names
439
+ - Example: `Post` in OpenAPI becomes `postSchema` in generated code
440
+ - No support for custom naming conventions yet
441
+
442
+ 2. **OpenAPI Support**
443
+ - Not all OpenAPI features are supported
444
+ - Complex schemas might not convert correctly
445
+ - Limited support for certain response types
446
+ - Some OpenAPI validations may not be perfectly converted to Zod validations
447
+
448
+ ### 🙏 Seeking Advice
449
+
450
+ As a relatively new developer, I would greatly appreciate feedback on:
451
+
452
+ - Code architecture and best practices
453
+ - Error handling approaches
454
+ - Testing strategies
455
+ - Performance improvements
456
+ - Security considerations
457
+ - Naming convention flexibility
458
+ - OpenAPI to Zod conversion strategies
459
+
460
+ I welcome any feedback, suggestions, or contributions that could help make this tool more robust and reliable. Feel free to:
461
+ - Open issues for bugs or suggestions
462
+ - Submit PRs with improvements
463
+ - Share your experience using the tool
464
+ - Provide guidance on better coding practices
465
+ - Report any conversion inconsistencies you find
466
+
467
+ Let's make this tool better together! 🔥
468
+
469
+ ## License
470
+
471
+ Distributed under the MIT License. See [LICENSE](https://github.com/nakita-Ypm/hono-takibi?tab=MIT-1-ov-file) for more information.
@@ -0,0 +1,35 @@
1
+ import type { Schema } from '../../../types';
2
+ /**
3
+ * Collects all $ref references from an OpenAPI schema by recursively traversing it
4
+ *
5
+ * @function findReferences
6
+ * @param schema - The OpenAPI schema to search for references
7
+ * @returns A Set of strings containing all schema names referenced via $ref
8
+ *
9
+ * @example
10
+ * const schema = {
11
+ * type: 'object',
12
+ * properties: {
13
+ * tags: {
14
+ * type: 'array',
15
+ * items: {
16
+ * $ref: '#/components/schemas/Tag'
17
+ * }
18
+ * },
19
+ * category: {
20
+ * $ref: '#/components/schemas/Category'
21
+ * }
22
+ * }
23
+ * }
24
+ *
25
+ * const refs = findReferences(schema)
26
+ * // refs contains: Set { 'Tag', 'Category' }
27
+ *
28
+ * @note
29
+ * - Extracts only the schema name from $ref paths
30
+ * e.g., '#/components/schemas/Tag' becomes 'Tag'
31
+ * - Recursively traverses all properties in the schema
32
+ * - Automatically deduplicates references via Set
33
+ * - Handles nested references in arrays and objects
34
+ */
35
+ export declare function findReferences(schema: Schema): Set<string>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findReferences = findReferences;
4
+ const traverse_schema_1 = require("./traverse_schema");
5
+ /**
6
+ * Collects all $ref references from an OpenAPI schema by recursively traversing it
7
+ *
8
+ * @function findReferences
9
+ * @param schema - The OpenAPI schema to search for references
10
+ * @returns A Set of strings containing all schema names referenced via $ref
11
+ *
12
+ * @example
13
+ * const schema = {
14
+ * type: 'object',
15
+ * properties: {
16
+ * tags: {
17
+ * type: 'array',
18
+ * items: {
19
+ * $ref: '#/components/schemas/Tag'
20
+ * }
21
+ * },
22
+ * category: {
23
+ * $ref: '#/components/schemas/Category'
24
+ * }
25
+ * }
26
+ * }
27
+ *
28
+ * const refs = findReferences(schema)
29
+ * // refs contains: Set { 'Tag', 'Category' }
30
+ *
31
+ * @note
32
+ * - Extracts only the schema name from $ref paths
33
+ * e.g., '#/components/schemas/Tag' becomes 'Tag'
34
+ * - Recursively traverses all properties in the schema
35
+ * - Automatically deduplicates references via Set
36
+ * - Handles nested references in arrays and objects
37
+ */
38
+ function findReferences(schema) {
39
+ const refs = new Set();
40
+ (0, traverse_schema_1.traverseSchema)(schema, refs);
41
+ return refs;
42
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Generates a camelCase schema name from a given schema name.
3
+ *
4
+ * @param schemaName - The original schema name.
5
+ * @returns The camelCase schema name.
6
+ */
7
+ export declare function getCamelCaseSchemaName(schemaName: string): string;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCamelCaseSchemaName = getCamelCaseSchemaName;
4
+ const decapitalize_1 = require("../../text/decapitalize");
5
+ /**
6
+ * Generates a camelCase schema name from a given schema name.
7
+ *
8
+ * @param schemaName - The original schema name.
9
+ * @returns The camelCase schema name.
10
+ */
11
+ function getCamelCaseSchemaName(schemaName) {
12
+ const decapitalizedSchemaName = (0, decapitalize_1.decapitalize)(schemaName);
13
+ return `${decapitalizedSchemaName}Schema`;
14
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Extracts the type name from an OpenAPI schema reference ($ref)
3
+ *
4
+ * @function getRefName
5
+ * @param ref - OpenAPI schema reference path (e.g., '#/components/schemas/Address')
6
+ * @returns The referenced type name, or undefined if the reference is invalid
7
+ *
8
+ * @example
9
+ * // Basic usage with Address schema
10
+ * getRefName('#/components/schemas/Address')
11
+ * // Returns: 'Address'
12
+ *
13
+ * // Nested Address schema
14
+ * getRefName('#/components/schemas/Location/Address')
15
+ * // Returns: 'Address'
16
+ *
17
+ * // Complex Address reference
18
+ * getRefName('#/components/schemas/Shipping/Address/Details')
19
+ * // Returns: 'Details'
20
+ *
21
+ * // Invalid path
22
+ * getRefName('')
23
+ * // Returns: undefined
24
+ *
25
+ * @note
26
+ * - Expects standard OpenAPI reference paths (e.g., '#/components/schemas/Address')
27
+ * - Extracts the last segment of the path as the type name
28
+ * - Returns undefined for empty strings or invalid paths
29
+ * - Used when processing Address and other schema references in OpenAPI
30
+ *
31
+ * @description
32
+ * Processes OpenAPI $ref strings to extract schema type names.
33
+ * For example, when processing an Address schema reference:
34
+ * Input: '#/components/schemas/Address'
35
+ * Process: Splits by '/' -> ['#', 'components', 'schemas', 'Address']
36
+ * Output: Returns 'Address'
37
+ */
38
+ export declare function getRefName(ref: string): string | undefined;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRefName = getRefName;
4
+ /**
5
+ * Extracts the type name from an OpenAPI schema reference ($ref)
6
+ *
7
+ * @function getRefName
8
+ * @param ref - OpenAPI schema reference path (e.g., '#/components/schemas/Address')
9
+ * @returns The referenced type name, or undefined if the reference is invalid
10
+ *
11
+ * @example
12
+ * // Basic usage with Address schema
13
+ * getRefName('#/components/schemas/Address')
14
+ * // Returns: 'Address'
15
+ *
16
+ * // Nested Address schema
17
+ * getRefName('#/components/schemas/Location/Address')
18
+ * // Returns: 'Address'
19
+ *
20
+ * // Complex Address reference
21
+ * getRefName('#/components/schemas/Shipping/Address/Details')
22
+ * // Returns: 'Details'
23
+ *
24
+ * // Invalid path
25
+ * getRefName('')
26
+ * // Returns: undefined
27
+ *
28
+ * @note
29
+ * - Expects standard OpenAPI reference paths (e.g., '#/components/schemas/Address')
30
+ * - Extracts the last segment of the path as the type name
31
+ * - Returns undefined for empty strings or invalid paths
32
+ * - Used when processing Address and other schema references in OpenAPI
33
+ *
34
+ * @description
35
+ * Processes OpenAPI $ref strings to extract schema type names.
36
+ * For example, when processing an Address schema reference:
37
+ * Input: '#/components/schemas/Address'
38
+ * Process: Splits by '/' -> ['#', 'components', 'schemas', 'Address']
39
+ * Output: Returns 'Address'
40
+ */
41
+ function getRefName(ref) {
42
+ // split('/'): Split a string into an array using slashes
43
+ // 1. ["#", "components", "schemas", "Address"]
44
+ // pop() to get the last element
45
+ // 2. "Address"
46
+ return ref.split('/').pop();
47
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Resolves the order of schema processing based on their dependencies using depth-first search
3
+ *
4
+ * @function resolveSchemaOrder
5
+ * @param name - The name of the current schema to process
6
+ * @param dependencies - Map of schema names to their dependent schema names
7
+ * @param visited - Set of schema names that have been processed
8
+ * @param ordered - Array to store the resolved order of schema names
9
+ * @returns void
10
+ *
11
+ * @example
12
+ * const dependencies = new Map([
13
+ * ['User', new Set(['Address'])],
14
+ * ['Address', new Set(['Country'])],
15
+ * ['Country', new Set()]
16
+ * ])
17
+ *
18
+ * const visited = new Set<string>()
19
+ * const ordered: string[] = []
20
+ *
21
+ * resolveSchemaOrder('User', dependencies, visited, ordered)
22
+ * // ordered will be: ['Country', 'Address', 'User']
23
+ *
24
+ * @note
25
+ * - Uses depth-first search to resolve dependencies
26
+ * - Prevents circular references by tracking visited schemas
27
+ * - Ensures dependent schemas appear before schemas that depend on them
28
+ * - Modifies the ordered array in-place to build the final sequence
29
+ */
30
+ export declare function resolveSchemaOrder(name: string, dependencies: Map<string, Set<string>>, visited: Set<string>, ordered: string[]): void;