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.
- package/dist/cli/hono-takibi/index.d.ts +4 -0
- package/dist/cli/hono-takibi/index.js +37 -0
- package/dist/cli/{takibi.d.ts → hono-takibi/takibi.d.ts} +1 -1
- package/dist/cli/{takibi.js → hono-takibi/takibi.js} +7 -7
- package/dist/cli/hono-takibi/template-code.d.ts +3 -0
- package/dist/cli/{app.js → hono-takibi/template-code.js} +7 -7
- package/dist/cli/index.d.ts +1 -4
- package/dist/cli/index.js +1 -37
- package/dist/core/helper/get-camel-case-schema-name.js +1 -1
- package/dist/core/helper/get-pascal-case-schema-name.js +1 -1
- package/dist/core/helper/get-variable-name.d.ts +2 -3
- package/dist/core/helper/get-variable-name.js +4 -4
- package/dist/core/helper/get-variable-schema-name.d.ts +2 -3
- package/dist/core/helper/get-variable-schema-name.js +3 -5
- package/dist/core/helper/sanitize-identifier.d.ts +1 -0
- package/dist/core/helper/sanitize-identifier.js +3 -0
- package/dist/core/schema/references/get-ref-schema-name.d.ts +2 -3
- package/dist/core/schema/references/get-ref-schema-name.js +3 -3
- package/dist/core/{text/escape-str.d.ts → utils/escape-string-literal.d.ts} +1 -1
- package/dist/core/{text/escape-str.js → utils/escape-string-literal.js} +1 -1
- package/dist/core/utils/index.d.ts +6 -0
- package/dist/core/utils/index.js +6 -0
- package/dist/core/{text → utils}/regex-pattern.js +1 -2
- package/dist/core/utils/sanitizeIdentifier.d.ts +23 -0
- package/dist/core/utils/sanitizeIdentifier.js +25 -0
- package/dist/generator/zod/coerce.js +1 -1
- package/dist/generator/zod/object.js +6 -6
- package/dist/generator/zod/reference/generate-array-reference-schema.js +1 -1
- package/dist/generator/zod/reference/generate-reference-schema.js +1 -1
- package/dist/generator/zod/regex.js +1 -1
- package/dist/generator/zod/sub/generate-zod-schema-from-sub-schema.js +1 -1
- package/dist/generator/zod/zod.js +9 -9
- package/dist/generator/zod-openapi-hono/app/docs/index.d.ts +8 -0
- package/dist/generator/zod-openapi-hono/app/docs/index.js +9 -0
- package/dist/generator/zod-openapi-hono/app/{generators/generate-app-route-handler.d.ts → generator/app-route-handler.d.ts} +1 -1
- package/dist/generator/zod-openapi-hono/app/{generators/generate-app-route-handler.js → generator/app-route-handler.js} +1 -1
- package/dist/generator/zod-openapi-hono/app/{generators/generate-apply-openapi-routes.d.ts → generator/apply-openapi-routes.d.ts} +2 -2
- package/dist/generator/zod-openapi-hono/app/{generators/generate-apply-openapi-routes.js → generator/apply-openapi-routes.js} +4 -4
- package/dist/generator/zod-openapi-hono/app/{generators/generate-import-routes.d.ts → generator/import-routes.d.ts} +2 -2
- package/dist/generator/zod-openapi-hono/app/{generators/generate-import-routes.js → generator/import-routes.js} +2 -2
- package/dist/generator/zod-openapi-hono/app/generator/index.d.ts +3 -0
- package/dist/generator/zod-openapi-hono/app/generator/index.js +3 -0
- package/dist/generator/zod-openapi-hono/app/helper/get-route-maps.d.ts +3 -3
- package/dist/generator/zod-openapi-hono/app/helper/get-route-maps.js +3 -3
- package/dist/generator/zod-openapi-hono/app/index.d.ts +3 -3
- package/dist/generator/zod-openapi-hono/app/index.js +15 -13
- package/dist/generator/zod-openapi-hono/handler/import/get-handler-imports.js +1 -1
- package/dist/generator/zod-openapi-hono/handler/zod-openapi-hono-handler.d.ts +3 -3
- package/dist/generator/zod-openapi-hono/handler/zod-openapi-hono-handler.js +2 -5
- package/dist/generator/zod-openapi-hono/openapi/component/allof/{generate-allof-code.d.ts → all-of.d.ts} +1 -1
- package/dist/generator/zod-openapi-hono/openapi/component/allof/{generate-allof-code.js → all-of.js} +1 -1
- package/dist/generator/zod-openapi-hono/openapi/component/allof/index.d.ts +1 -0
- package/dist/generator/zod-openapi-hono/openapi/component/allof/index.js +1 -0
- package/dist/generator/zod-openapi-hono/openapi/component/anyof/{generate-anyof-code.d.ts → any-of.d.ts} +1 -1
- package/dist/generator/zod-openapi-hono/openapi/component/anyof/{generate-anyof-code.js → any-of.js} +4 -2
- package/dist/generator/zod-openapi-hono/openapi/component/anyof/index.d.ts +1 -0
- package/dist/generator/zod-openapi-hono/openapi/component/anyof/index.js +1 -0
- package/dist/generator/zod-openapi-hono/openapi/component/generate-components-code.js +1 -1
- package/dist/generator/zod-openapi-hono/openapi/component/not/index.d.ts +1 -0
- package/dist/generator/zod-openapi-hono/openapi/component/not/index.js +1 -0
- package/dist/generator/zod-openapi-hono/openapi/component/not/{generate-not-code.d.ts → not.d.ts} +1 -1
- package/dist/generator/zod-openapi-hono/openapi/component/not/{generate-not-code.js → not.js} +1 -1
- package/dist/generator/zod-openapi-hono/openapi/component/oneof/index.d.ts +1 -0
- package/dist/generator/zod-openapi-hono/openapi/component/oneof/index.js +1 -0
- package/dist/generator/zod-openapi-hono/openapi/component/oneof/{generate-oneof-code.d.ts → one-of.d.ts} +1 -1
- package/dist/generator/zod-openapi-hono/openapi/component/oneof/{generate-oneof-code.js → one-of.js} +4 -2
- package/dist/generator/zod-openapi-hono/openapi/route/generate-route-name.js +1 -1
- package/dist/generator/zod-openapi-hono/openapi/route/generate-route.js +3 -3
- package/dist/generator/zod-openapi-hono/openapi/route/response/generate-response-schema.js +3 -3
- package/dist/generator/zod-openapi-hono/openapi/zod-openapi-hono.d.ts +3 -3
- package/dist/generator/zod-openapi-hono/openapi/zod-openapi-hono.js +4 -9
- package/dist/generator/zod-to-openapi/defining/generate-zod-to-openapi-schema-definition.js +7 -9
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/parse-openapi.d.ts +3 -3
- package/dist/openapi/parse-openapi.js +1 -1
- package/dist/openapi/types.d.ts +4 -4
- package/package.json +2 -2
- package/dist/cli/app.d.ts +0 -3
- package/dist/core/text/index.d.ts +0 -5
- package/dist/core/text/index.js +0 -5
- package/dist/generator/zod-openapi-hono/app/docs/generate-docs.d.ts +0 -13
- package/dist/generator/zod-openapi-hono/app/docs/generate-docs.js +0 -14
- /package/dist/core/{text → utils}/capitalize.d.ts +0 -0
- /package/dist/core/{text → utils}/capitalize.js +0 -0
- /package/dist/core/{text → utils}/decapitalize.d.ts +0 -0
- /package/dist/core/{text → utils}/decapitalize.js +0 -0
- /package/dist/core/{text → utils}/regex-pattern.d.ts +0 -0
- /package/dist/core/{text → utils}/remove-zod-prefix.d.ts +0 -0
- /package/dist/core/{text → utils}/remove-zod-prefix.js +0 -0
|
@@ -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,12 +1,12 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { ok, asyncAndThen } from '
|
|
3
|
-
import { fmt } from '
|
|
4
|
-
import { parseOpenAPI } from '
|
|
5
|
-
import { zodOpenAPIHono } from '
|
|
6
|
-
import {
|
|
7
|
-
import { mkdir, writeFile } from '
|
|
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
|
|
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}`,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { ok,
|
|
3
|
-
import { readdir, writeFile } from '
|
|
4
|
-
import { fmt } from '
|
|
5
|
-
import { generateApp } from '
|
|
6
|
-
import { zodOpenapiHonoHandler } from '
|
|
7
|
-
export async function
|
|
8
|
-
if (!(template
|
|
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) => {
|
package/dist/cli/index.d.ts
CHANGED
package/dist/cli/index.js
CHANGED
|
@@ -1,37 +1 @@
|
|
|
1
|
-
|
|
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,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 {
|
|
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,
|
|
7
|
+
export declare function getVariableName(name: string, style?: 'camelCase' | 'PascalCase'): string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { capitalize, decapitalize } from '../
|
|
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 {
|
|
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,
|
|
9
|
-
return
|
|
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 {
|
|
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,
|
|
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 {
|
|
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,
|
|
9
|
-
return
|
|
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;
|
|
@@ -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 {
|
|
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,
|
|
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 {
|
|
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,
|
|
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,
|
|
18
|
+
return getVariableSchemaName(refName, style);
|
|
19
19
|
}
|
|
@@ -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
|
|
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';
|
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
import { record, passthrough } from './index.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
|
24
|
+
return allOf(schema, config);
|
|
25
25
|
}
|
|
26
26
|
if (schema.oneOf) {
|
|
27
|
-
return
|
|
27
|
+
return oneOf(schema, config);
|
|
28
28
|
}
|
|
29
29
|
if (schema.anyOf) {
|
|
30
|
-
return
|
|
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
|
}
|
|
@@ -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 {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
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
|
|
156
|
+
return oneOf(schema, config);
|
|
157
157
|
}
|
|
158
158
|
// anyOf
|
|
159
159
|
if (schema.anyOf) {
|
|
160
|
-
return
|
|
160
|
+
return anyOf(schema, config);
|
|
161
161
|
}
|
|
162
162
|
// allOf
|
|
163
163
|
if (schema.allOf) {
|
|
164
|
-
return
|
|
164
|
+
return allOf(schema, config);
|
|
165
165
|
}
|
|
166
166
|
// not
|
|
167
167
|
if (schema.not) {
|
|
168
|
-
return
|
|
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
|
+
};
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* @param { string } routeName - Route name
|
|
4
4
|
* @param { string } handlerName - Handler name
|
|
5
5
|
*/
|
|
6
|
-
export declare function
|
|
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
|
|
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
|
|
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
|
|
8
|
+
export declare function applyOpenapiRoutes(routeMappings: {
|
|
9
9
|
routeName: string;
|
|
10
10
|
handlerName: string;
|
|
11
11
|
path: string;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { appRouteHandler } from './index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Generates the application route handlers.
|
|
4
4
|
*
|
|
5
|
-
* @function
|
|
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
|
|
9
|
+
export function applyOpenapiRoutes(routeMappings) {
|
|
10
10
|
return routeMappings
|
|
11
11
|
.map(({ routeName, handlerName }) => {
|
|
12
|
-
return
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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));
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OpenAPI } from '../../../../openapi/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Get route maps
|
|
4
|
-
* @param {
|
|
4
|
+
* @param { openAPI } OpenAPI - OpenAPI spec
|
|
5
5
|
* @returns { { routeName: string, handlerName: string, path: string }[] } Route maps
|
|
6
6
|
*/
|
|
7
|
-
export declare function getRouteMaps(
|
|
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 {
|
|
5
|
+
* @param { openAPI } OpenAPI - OpenAPI spec
|
|
6
6
|
* @returns { { routeName: string, handlerName: string, path: string }[] } Route maps
|
|
7
7
|
*/
|
|
8
|
-
export function getRouteMaps(
|
|
9
|
-
const 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 {
|