hono-takibi 0.6.5 → 0.6.6
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/config/index.d.ts +18 -0
- package/dist/core/helper/get-camel-case-schema-name-helper.d.ts +6 -0
- package/dist/core/helper/get-pascal-case-schema-name-helper.d.ts +6 -0
- package/dist/core/helper/get-to-safe-identifier-helper.d.ts +6 -0
- package/dist/core/helper/get-variable-name-helper.d.ts +8 -0
- package/dist/core/helper/get-variable-schema-name-helper.d.ts +8 -0
- package/dist/core/schema/references/extract-refs.d.ts +7 -0
- package/dist/core/schema/references/find-references.d.ts +25 -0
- package/dist/core/schema/references/get-ref-name.d.ts +33 -0
- package/dist/core/schema/references/get-ref-schema-name.d.ts +10 -0
- package/dist/core/schema/references/resolve-schemas-dependencies.d.ts +59 -0
- package/dist/core/schema/references/traverse-schema-dependencies.d.ts +10 -0
- package/dist/core/schema/references/traverse-schema.d.ts +45 -0
- package/dist/core/text/capitalize.d.ts +16 -0
- package/dist/core/text/decapitalize.d.ts +15 -0
- package/dist/core/text/escape-str.d.ts +6 -0
- package/dist/core/text/regex-pattern.d.ts +6 -0
- package/dist/core/text/remove-zod-prefix.d.ts +6 -0
- package/dist/core/validator/is-all-optional.d.ts +6 -0
- package/dist/core/validator/is-array-with-schema-reference.d.ts +7 -0
- package/dist/core/validator/is-format-number.d.ts +7 -0
- package/dist/core/validator/is-format-string.d.ts +7 -0
- package/dist/core/validator/is-http-method.d.ts +7 -0
- package/dist/core/validator/is-nullable-schema.d.ts +7 -0
- package/dist/core/validator/is-operation.d.ts +13 -0
- package/dist/core/validator/is-ref-object.d.ts +11 -0
- package/dist/core/validator/is-schema-reference.d.ts +7 -0
- package/dist/core/validator/is-unique-content-schema.d.ts +8 -0
- package/dist/core/zod/get-zod-string-format.d.ts +30 -0
- package/dist/format/index.d.ts +6 -0
- package/dist/generator/zod/generate-zod-array.d.ts +22 -0
- package/dist/generator/zod/generate-zod-coerce.d.ts +7 -0
- package/dist/generator/zod/generate-zod-default.d.ts +7 -0
- package/dist/generator/zod/generate-zod-enum.d.ts +7 -0
- package/dist/generator/zod/generate-zod-gt.d.ts +6 -0
- package/dist/generator/zod/generate-zod-infer.d.ts +7 -0
- package/dist/generator/zod/generate-zod-integer-schema.d.ts +19 -0
- package/dist/generator/zod/generate-zod-intersection.d.ts +6 -0
- package/dist/generator/zod/generate-zod-length.d.ts +9 -0
- package/dist/generator/zod/generate-zod-lt.d.ts +6 -0
- package/dist/generator/zod/generate-zod-max.d.ts +6 -0
- package/dist/generator/zod/generate-zod-min.d.ts +9 -0
- package/dist/generator/zod/generate-zod-nullable.d.ts +7 -0
- package/dist/generator/zod/generate-zod-number.d.ts +21 -0
- package/dist/generator/zod/generate-zod-object-schema.d.ts +33 -0
- package/dist/generator/zod/generate-zod-object.d.ts +9 -0
- package/dist/generator/zod/generate-zod-partial-schema.d.ts +6 -0
- package/dist/generator/zod/generate-zod-passthrough.d.ts +6 -0
- package/dist/generator/zod/generate-zod-record.d.ts +29 -0
- package/dist/generator/zod/generate-zod-regex.d.ts +6 -0
- package/dist/generator/zod/generate-zod-string.d.ts +44 -0
- package/dist/generator/zod/generate-zod-union.d.ts +9 -0
- package/dist/generator/zod/generate-zod.d.ts +48 -0
- package/dist/generator/zod/helper/strip-max-if-lt-exist-helper.d.ts +7 -0
- package/dist/generator/zod/helper/strip-min-if-gt-exist-helper.d.ts +7 -0
- package/dist/generator/zod/helper/strip-min-max-exist-helper.d.ts +8 -0
- package/dist/generator/zod/openapi/generate-zod-to-openapi-schema-definition.d.ts +19 -0
- package/dist/generator/zod/openapi/generate-zod-to-openapi.d.ts +9 -0
- package/dist/generator/zod/property/generate-zod-properties-schema.d.ts +45 -0
- package/dist/generator/zod/property/generate-zod-property-schema.d.ts +30 -0
- package/dist/generator/zod/reference/generate-array-reference-schema.d.ts +9 -0
- package/dist/generator/zod/reference/generate-reference-schema.d.ts +9 -0
- package/dist/generator/zod/sub/generate-zod-schema-from-sub-schema.d.ts +9 -0
- package/dist/generator/zod-openapi-hono/app/docs/generate-docs.d.ts +13 -0
- package/dist/generator/zod-openapi-hono/app/generate-app-route-handler.d.ts +7 -0
- package/dist/generator/zod-openapi-hono/app/generators/generate-apply-openapi-routes.d.ts +12 -0
- package/dist/generator/zod-openapi-hono/app/generators/generate-import-routes.d.ts +10 -0
- package/dist/generator/zod-openapi-hono/app/helper/get-route-maps.d.ts +11 -0
- package/dist/generator/zod-openapi-hono/app/helper/process-import-map.d.ts +14 -0
- package/dist/generator/zod-openapi-hono/app/index.d.ts +12 -0
- package/dist/generator/zod-openapi-hono/app/register-component/generate-register-component.d.ts +7 -0
- package/dist/generator/zod-openapi-hono/handler/generate-handler-name.d.ts +7 -0
- package/dist/generator/zod-openapi-hono/handler/generate-handler.d.ts +7 -0
- package/dist/generator/zod-openapi-hono/handler/generate-zod-openapi-hono-handler.d.ts +16 -0
- package/dist/generator/zod-openapi-hono/handler/helper/group-handlers-by-file-name-helper.d.ts +7 -0
- package/dist/generator/zod-openapi-hono/handler/import/generate-import-handlers.d.ts +10 -0
- package/dist/generator/zod-openapi-hono/handler/import/get-handler-imports.d.ts +12 -0
- package/dist/generator/zod-openapi-hono/openapi/component/allof/generate-allof-code.d.ts +9 -0
- package/dist/generator/zod-openapi-hono/openapi/component/allof/process/process-alllof.d.ts +14 -0
- package/dist/generator/zod-openapi-hono/openapi/component/anyof/generate-anyof-code.d.ts +9 -0
- package/dist/generator/zod-openapi-hono/openapi/component/generate-components-code.d.ts +17 -0
- package/dist/generator/zod-openapi-hono/openapi/component/not/generate-not-code.d.ts +7 -0
- package/dist/generator/zod-openapi-hono/openapi/component/oneof/generate-oneof-code.d.ts +9 -0
- package/dist/generator/zod-openapi-hono/openapi/generate-zod-openapi-hono.d.ts +9 -0
- package/dist/generator/zod-openapi-hono/openapi/route/generate-create-route.d.ts +56 -0
- package/dist/generator/zod-openapi-hono/openapi/route/generate-route-code.d.ts +20 -0
- package/dist/generator/zod-openapi-hono/openapi/route/generate-route-name.d.ts +15 -0
- package/dist/generator/zod-openapi-hono/openapi/route/generate-route.d.ts +23 -0
- package/dist/generator/zod-openapi-hono/openapi/route/params/generate-params-object.d.ts +14 -0
- package/dist/generator/zod-openapi-hono/openapi/route/params/generate-request-parameter.d.ts +20 -0
- package/dist/generator/zod-openapi-hono/openapi/route/params/generate-request-params-array.d.ts +7 -0
- package/dist/generator/zod-openapi-hono/openapi/route/params/generate-request-params.d.ts +6 -0
- package/dist/generator/zod-openapi-hono/openapi/route/request/body/generate-insert-request-body.d.ts +7 -0
- package/dist/generator/zod-openapi-hono/openapi/route/request/body/generate-request-body.d.ts +9 -0
- package/dist/generator/zod-openapi-hono/openapi/route/request/object/generate-format-request-object.d.ts +25 -0
- package/dist/generator/zod-openapi-hono/openapi/route/response/generate-response-schema.d.ts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/types/index.d.ts +215 -0
- package/dist/vite-plugin/index.d.ts +5 -0
- package/dist/vite-plugin/index.js +2 -2
- package/dist/vite-plugin/vite-mode.d.ts +7 -0
- package/package.json +2 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type Config = {
|
|
2
|
+
schema: {
|
|
3
|
+
name: 'PascalCase' | 'camelCase';
|
|
4
|
+
export: boolean;
|
|
5
|
+
};
|
|
6
|
+
type: {
|
|
7
|
+
name: 'PascalCase' | 'camelCase';
|
|
8
|
+
export: boolean;
|
|
9
|
+
};
|
|
10
|
+
input?: string;
|
|
11
|
+
output?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const DEFAULT_CONFIG: Config;
|
|
14
|
+
/**
|
|
15
|
+
* Loads the configuration from the `hono-takibi.json` file or returns the default configuration.
|
|
16
|
+
* @returns { Config } The configuration object.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getConfig(): Config;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a PascalCase schema name from a given schema name.
|
|
3
|
+
* @param { string } schemaName - The original schema name.
|
|
4
|
+
* @returns { string } The PascalCase schema name.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getPascalCaseSchemaNameHelper(schemaName: string): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Config } from '../../config/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generates a variable name from a given name and config.
|
|
4
|
+
* @param { string } name - The name of the schema.
|
|
5
|
+
* @param { Config } config - The config of the schema.
|
|
6
|
+
* @returns { string } The variable name.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getVariableNameHelper(name: string, config: Config): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Config } from '../../config/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generates a variable schema name from a given name and config.
|
|
4
|
+
* @param { string } name - The name of the schema.
|
|
5
|
+
* @param { Config } config - The config of the schema.
|
|
6
|
+
* @returns { string } The variable schema name.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getVariableSchemaNameHelper(name: string, config: Config): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Schema } from '../../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts all references from a given schema
|
|
4
|
+
* @param { Schema } schema - The schema to extract references from
|
|
5
|
+
* @returns { string[] } An array of reference names
|
|
6
|
+
*/
|
|
7
|
+
export declare function extractRefs(schema: Schema): string[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Schema } from '../../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Collects all $ref references from an OpenAPI schema by recursively traversing it
|
|
4
|
+
* @param { Schema } schema - The schema to search for references
|
|
5
|
+
* @returns { Set<string> } A Set of strings containing all schema names referenced via $ref
|
|
6
|
+
* @example
|
|
7
|
+
* const schema = {
|
|
8
|
+
* type: 'object',
|
|
9
|
+
* properties: {
|
|
10
|
+
* tags: {
|
|
11
|
+
* type: 'array',
|
|
12
|
+
* items: {
|
|
13
|
+
* $ref: '#/components/schemas/Tag'
|
|
14
|
+
* }
|
|
15
|
+
* },
|
|
16
|
+
* category: {
|
|
17
|
+
* $ref: '#/components/schemas/Category'
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* const refs = findReferences(schema)
|
|
23
|
+
* // refs contains: Set { 'Tag', 'Category' }
|
|
24
|
+
*/
|
|
25
|
+
export declare function findReferences(schema: Schema): Set<string>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the type name from an OpenAPI schema reference ($ref)
|
|
3
|
+
* @param { string } ref - OpenAPI schema reference path (e.g., '#/components/schemas/Address')
|
|
4
|
+
* @returns { string | undefined } The referenced type name, or undefined if the reference is invalid
|
|
5
|
+
* @example
|
|
6
|
+
* // Basic usage with Address schema
|
|
7
|
+
* getRefName('#/components/schemas/Address')
|
|
8
|
+
* // Returns: 'Address'
|
|
9
|
+
*
|
|
10
|
+
* // Nested Address schema
|
|
11
|
+
* getRefName('#/components/schemas/Location/Address')
|
|
12
|
+
* // Returns: 'Address'
|
|
13
|
+
*
|
|
14
|
+
* // Complex Address reference
|
|
15
|
+
* getRefName('#/components/schemas/Shipping/Address/Details')
|
|
16
|
+
* // Returns: 'Details'
|
|
17
|
+
*
|
|
18
|
+
* // Invalid path
|
|
19
|
+
* getRefName('')
|
|
20
|
+
* // Returns: undefined
|
|
21
|
+
*
|
|
22
|
+
* - Expects standard OpenAPI reference paths (e.g., '#/components/schemas/Address')
|
|
23
|
+
* - Extracts the last segment of the path as the type name
|
|
24
|
+
* - Returns undefined for empty strings or invalid paths
|
|
25
|
+
* - Used when processing Address and other schema references in OpenAPI
|
|
26
|
+
*
|
|
27
|
+
* Processes OpenAPI $ref strings to extract schema type names.
|
|
28
|
+
* For example, when processing an Address schema reference:
|
|
29
|
+
* Input: '#/components/schemas/Address'
|
|
30
|
+
* Process: Splits by '/' -> ['#', 'components', 'schemas', 'Address']
|
|
31
|
+
* Output: Returns 'Address'
|
|
32
|
+
*/
|
|
33
|
+
export declare function getRefName(ref: string): string | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Config } from '../../../config/index.js';
|
|
2
|
+
import type { Schema } from '../../../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves the referenced schema name from a schema object.
|
|
5
|
+
* @param { Schema } schema - The schema object
|
|
6
|
+
* @param { Config } config - The configuration object
|
|
7
|
+
* @returns { string } The referenced schema name
|
|
8
|
+
* @throws { Error } Will throw an error if the $ref property or the reference name is not found
|
|
9
|
+
*/
|
|
10
|
+
export declare function getRefSchemaName(schema: Schema, config: Config): string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Schema } from '../../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves dependencies between schemas and returns them in topological order for safe processing
|
|
4
|
+
* @param { Record<string, Schema> } schemas - Record mapping schema names to their Schema objects
|
|
5
|
+
* @returns { string[] } Array of schema names ordered by their dependencies
|
|
6
|
+
* @example
|
|
7
|
+
* const schemas: Record<string, Schema> = {
|
|
8
|
+
* A: {
|
|
9
|
+
* type: 'object',
|
|
10
|
+
* properties: {
|
|
11
|
+
* b: {
|
|
12
|
+
* $ref: '#/components/schemas/B',
|
|
13
|
+
* },
|
|
14
|
+
* c: {
|
|
15
|
+
* $ref: '#/components/schemas/C',
|
|
16
|
+
* },
|
|
17
|
+
* },
|
|
18
|
+
* required: ['b', 'c'],
|
|
19
|
+
* },
|
|
20
|
+
* B: {
|
|
21
|
+
* type: 'object',
|
|
22
|
+
* properties: {
|
|
23
|
+
* id: {
|
|
24
|
+
* type: 'string',
|
|
25
|
+
* description: 'Identifier for schema B',
|
|
26
|
+
* },
|
|
27
|
+
* message: {
|
|
28
|
+
* type: 'string',
|
|
29
|
+
* description: 'Message from schema B',
|
|
30
|
+
* },
|
|
31
|
+
* required: ['id'],
|
|
32
|
+
* },
|
|
33
|
+
* C: {
|
|
34
|
+
* type: 'object',
|
|
35
|
+
* properties: {
|
|
36
|
+
* count: {
|
|
37
|
+
* type: 'integer',
|
|
38
|
+
* description: 'Count value',
|
|
39
|
+
* },
|
|
40
|
+
* flag: {
|
|
41
|
+
* type: 'boolean',
|
|
42
|
+
* description: 'A boolean flag',
|
|
43
|
+
* },
|
|
44
|
+
* },
|
|
45
|
+
* },
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* const orderedSchemas = resolveSchemasDependencies(schemas)
|
|
50
|
+
* // Returns: ['B', 'C', 'A']
|
|
51
|
+
*
|
|
52
|
+
* - Performs topological sorting of schemas based on their dependencies
|
|
53
|
+
* - Ensures each schema appears after all its dependencies
|
|
54
|
+
* - Handles multi-level dependency chains correctly
|
|
55
|
+
* - Essential for generating valid code where dependent types must be defined first
|
|
56
|
+
* - Uses depth-first search for dependency resolution
|
|
57
|
+
* - Automatically handles circular dependencies by preventing infinite recursion
|
|
58
|
+
*/
|
|
59
|
+
export declare function resolveSchemasDependencies(schemas: Record<string, Schema>): string[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Schema } from '../../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Traverses the schema dependencies and returns them in topological order
|
|
4
|
+
* @param { string } schemaName - The name of the schema to traverse
|
|
5
|
+
* @param { Record<string, Schema> } schemas - The schemas to traverse
|
|
6
|
+
* @param { Set<string> } visited - The visited schemas
|
|
7
|
+
* @param { Set<string> } recursionStack - The recursion stack
|
|
8
|
+
* @param { string[] } orderedSchemas - The ordered schemas
|
|
9
|
+
*/
|
|
10
|
+
export declare function traverseSchemaDependencies(schemaName: string, schemas: Record<string, Schema>, visited: Set<string>, recursionStack: Set<string>, orderedSchemas: string[]): void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Schema } from '../../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Recursively traverses an OpenAPI schema to collect all $ref references
|
|
4
|
+
* @param { Schema } schema - The OpenAPI schema object to traverse
|
|
5
|
+
* @param { Set<string> } refs - Set to collect found reference names
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const refs = new Set<string>()
|
|
9
|
+
* const schema = {
|
|
10
|
+
* type: 'object',
|
|
11
|
+
* properties: {
|
|
12
|
+
* user: {
|
|
13
|
+
* $ref: '#/components/schemas/User'
|
|
14
|
+
* },
|
|
15
|
+
* orders: {
|
|
16
|
+
* type: 'array',
|
|
17
|
+
* items: {
|
|
18
|
+
* $ref: '#/components/schemas/Order'
|
|
19
|
+
* }
|
|
20
|
+
* },
|
|
21
|
+
* address: {
|
|
22
|
+
* type: 'object',
|
|
23
|
+
* properties: {
|
|
24
|
+
* country: {
|
|
25
|
+
* $ref: '#/components/schemas/Country'
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* traverseSchema(schema, refs)
|
|
33
|
+
* // refs contains: Set { 'User', 'Order', 'Country' }
|
|
34
|
+
*
|
|
35
|
+
* - Mutates the provided refs Set by adding found references
|
|
36
|
+
* - Handles nested references in:
|
|
37
|
+
* - Object properties
|
|
38
|
+
* - Array items
|
|
39
|
+
* - Nested objects
|
|
40
|
+
* - Skips invalid or non-object schemas
|
|
41
|
+
* - Extracts only the schema name from $ref paths
|
|
42
|
+
* (e.g., '#/components/schemas/User' → 'User')
|
|
43
|
+
* - Performs depth-first traversal of the schema structure
|
|
44
|
+
*/
|
|
45
|
+
export declare function traverseSchema(schema: Schema, refs: Set<string>): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capitalize the first letter of a string
|
|
3
|
+
* @param { string } str - String to capitalize
|
|
4
|
+
* @returns { string } String with first letter capitalized
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* capitalize('posts') // Returns: 'Posts'
|
|
8
|
+
* capitalize('user') // Returns: 'User'
|
|
9
|
+
* capitalize('api') // Returns: 'Api'
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* - Leaves rest of the string unchanged
|
|
13
|
+
* - Returns empty string if input is empty
|
|
14
|
+
* - Commonly used for generating type names and class names
|
|
15
|
+
*/
|
|
16
|
+
export declare function capitalize(str: string): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decapitalize the first letter of a string
|
|
3
|
+
* @param { string } str - String to decapitalize
|
|
4
|
+
* @returns { string } String with the first letter in lowercase
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* decapitalize('Posts') // Returns: 'posts'
|
|
8
|
+
* decapitalize('User') // Returns: 'user'
|
|
9
|
+
* decapitalize('Api') // Returns: 'api'
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* - Leaves the rest of the string unchanged
|
|
13
|
+
* - Returns an empty string if the input is empty
|
|
14
|
+
*/
|
|
15
|
+
export declare function decapitalize(str: string): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if all properties in the object are optional
|
|
3
|
+
* @param { string[] } objectProperties - An array of strings representing the object properties
|
|
4
|
+
* @returns { boolean } A boolean indicating if all properties are optional
|
|
5
|
+
*/
|
|
6
|
+
export declare function isAllOptional(objectProperties: string[]): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Schema } from '../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Check if an array has a schema reference
|
|
4
|
+
* @param { Schema } schema - The schema to check
|
|
5
|
+
* @returns { boolean } A boolean indicating if the array has a schema reference
|
|
6
|
+
*/
|
|
7
|
+
export declare function isArrayWithSchemaReference(schema: Schema): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Format, FormatNumber } from '../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Check if the format is a number type
|
|
4
|
+
* @param {Format} format - OpenAPI format type
|
|
5
|
+
* @returns {boolean} true if the format is a number type, false otherwise
|
|
6
|
+
*/
|
|
7
|
+
export declare function isFormatNumber(format: Format): format is FormatNumber;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Format, FormatString } from '../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Check if the format is a string type
|
|
4
|
+
* @param { Format } format - OpenAPI format type
|
|
5
|
+
* @returns { boolean } true if the format is a string type, false otherwise
|
|
6
|
+
*/
|
|
7
|
+
export declare function isFormatString(format: Format): format is FormatString;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HttpMethod } from '../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Check if a string is a valid HTTP method
|
|
4
|
+
* @param { string } method - The string to check against valid HTTP methods
|
|
5
|
+
* @returns { boolean } True if the string is a valid HTTP method, with type narrowing to HttpMethod
|
|
6
|
+
*/
|
|
7
|
+
export declare function isHttpMethod(method: string): method is HttpMethod;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Schema } from '../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Check if a given sub-schema is `nullable`
|
|
4
|
+
* @param { Schema } schema - The sub-schema to evaluate
|
|
5
|
+
* @returns { boolean } `true` if `nullable` is set to `true` and it is the only key in the schema, otherwise `false`
|
|
6
|
+
*/
|
|
7
|
+
export declare function isNullableSchema(schema: Schema): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Operation } from '../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Check if an object is an Operation
|
|
4
|
+
* @param { Operation } obj - The object to check
|
|
5
|
+
* @returns { boolean } True if the object is an Operation, with type narrowing support
|
|
6
|
+
*
|
|
7
|
+
* Consider using `unknown` type instead of `Operation` for better type guarding:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* function isOperation(obj: unknown): obj is Operation
|
|
10
|
+
* ```
|
|
11
|
+
* This would provide more strict type checking for arbitrary values.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isOperation(obj: Operation): obj is Operation;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type RefObject = {
|
|
2
|
+
$ref?: string;
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Check if the value is a reference object
|
|
7
|
+
* @param { unknown } value - The value to check
|
|
8
|
+
* @returns { boolean } true if the value is a reference object, false otherwise
|
|
9
|
+
*/
|
|
10
|
+
export declare function isRefObject(value: unknown): value is RefObject;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Schema } from '../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Check if the schema is a reference
|
|
4
|
+
* @param { Schema } schema - The schema to check
|
|
5
|
+
* @returns { boolean } A boolean indicating if the schema is a reference
|
|
6
|
+
*/
|
|
7
|
+
export declare function isSchemaReference(schema: Schema): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Content } from '../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Get unique content schema
|
|
4
|
+
* @param { string[] } contentTypes - Content types
|
|
5
|
+
* @param { Content } content - Content
|
|
6
|
+
* @returns { boolean } Unique content schema
|
|
7
|
+
*/
|
|
8
|
+
export declare function isUniqueContentSchema(contentTypes: string[], content: Content): boolean;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { FormatString } from '../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Converts OpenAPI format to Zod validation method
|
|
4
|
+
*
|
|
5
|
+
* @function getZodFormatString
|
|
6
|
+
* @param format - OpenAPI format type
|
|
7
|
+
* @returns Zod validation method string
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // String validations
|
|
11
|
+
* getZodFormatString('email') // Returns: '.email()'
|
|
12
|
+
* getZodFormatString('uri') // Returns: '.url()'
|
|
13
|
+
* getZodFormatString('uuid') // Returns: '.uuid()'
|
|
14
|
+
* getZodFormatString('date-time') // Returns: '.datetime()'
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Number types
|
|
18
|
+
* getZodFormatString('int32') // Returns: 'z.number()'
|
|
19
|
+
* getZodFormatString('float') // Returns: 'z.number()'
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Unknown format
|
|
23
|
+
* getZodFormatString('unknown') // Returns: ''
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* - Returns the corresponding Zod validation method for known formats
|
|
27
|
+
* - Returns empty string for unrecognized formats
|
|
28
|
+
* - Used in schema generation for request/response validation
|
|
29
|
+
*/
|
|
30
|
+
export declare function getZodFormatString(format: FormatString): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a Zod array schema with the specified schema type
|
|
3
|
+
* @param { string } zodSchema - Schema type for array elements (e.g., 'Address', 'z.string().min(3)')
|
|
4
|
+
* @returns { string } Zod array schema string wrapped with z.array()
|
|
5
|
+
* @example
|
|
6
|
+
* // With type reference
|
|
7
|
+
* generateZodArray('Address')
|
|
8
|
+
* // Returns: 'z.array(Address)'
|
|
9
|
+
*
|
|
10
|
+
* // With primitive Zod schema
|
|
11
|
+
* generateZodArray('z.string()')
|
|
12
|
+
* // Returns: 'z.array(z.string())'
|
|
13
|
+
*
|
|
14
|
+
* // With complex Zod schema
|
|
15
|
+
* generateZodArray('z.string().min(3).max(10)')
|
|
16
|
+
* // Returns: 'z.array(z.string().min(3).max(10))'
|
|
17
|
+
*
|
|
18
|
+
* // With nested schema
|
|
19
|
+
* generateZodArray('z.object({ name: z.string() })')
|
|
20
|
+
* // Returns: 'z.array(z.object({ name: z.string() }))'
|
|
21
|
+
*/
|
|
22
|
+
export declare function generateZodArray(zodSchema: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a zod pipe function to coerce a value to a zod schema.
|
|
3
|
+
* @param { string } z - The zod schema to coerce to.
|
|
4
|
+
* @param { string } zodSchema - The zod schema to coerce.
|
|
5
|
+
* @returns { string } Generated zod pipe function to coerce a value to a zod schema.
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateZodCoerce(z: string, zodSchema: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DefaultValue } from '../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generates a Zod default validation string
|
|
4
|
+
* @param { DefaultValue } defaultValue - The default value to set
|
|
5
|
+
* @returns { string } Generated Zod default validation string
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateZodDefault(defaultValue: DefaultValue): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a TypeScript type definition for an inferred Zod schema.
|
|
3
|
+
* @param { string } typeVariableName - The name of the TypeScript type variable.
|
|
4
|
+
* @param { string } schemaName - The name of the Zod schema to infer.
|
|
5
|
+
* @returns { string } Generated TypeScript type definition string
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateZodInfer(typeVariableName: string, schemaName: string): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DefaultValue, ExampleValue } from '../../types/index.js';
|
|
2
|
+
type GenerateZodIntegerSchemaParams = {
|
|
3
|
+
pattern?: string;
|
|
4
|
+
minLength?: number;
|
|
5
|
+
maxLength?: number;
|
|
6
|
+
minimum?: number;
|
|
7
|
+
maximum?: number;
|
|
8
|
+
default?: DefaultValue;
|
|
9
|
+
example?: ExampleValue;
|
|
10
|
+
paramName?: string;
|
|
11
|
+
isPath?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Generates a zod schema for an integer.
|
|
15
|
+
* @param { GenerateZodIntegerSchemaParams } args - The parameters to generate the zod schema.
|
|
16
|
+
* @returns { string } Generated Zod integer schema string
|
|
17
|
+
*/
|
|
18
|
+
export declare function generateZodIntegerSchema(args: GenerateZodIntegerSchemaParams): string;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a Zod length validation string
|
|
3
|
+
* @param { number } length - The length value to validate against
|
|
4
|
+
* @returns { string } Generated Zod length validation string
|
|
5
|
+
* @example
|
|
6
|
+
* const lengthValidation = generateZodLength(10)
|
|
7
|
+
* // Returns: 'length(10)'
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateZodLength(length: number): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate Zod min validation
|
|
3
|
+
* @param { number } min - The minimum value
|
|
4
|
+
* @returns { string } Generated Zod min validation string
|
|
5
|
+
* @example
|
|
6
|
+
* generateZodMin(1) -> ".min(1)"
|
|
7
|
+
* generateZodMin(10) -> ".min(10)"
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateZodMin(min: number): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DefaultValue, ExampleValue } from '../../types/index.js';
|
|
2
|
+
type GenerateZodNumberParams = {
|
|
3
|
+
pattern?: string;
|
|
4
|
+
minLength?: number;
|
|
5
|
+
maxLength?: number;
|
|
6
|
+
minimum?: number;
|
|
7
|
+
maximum?: number;
|
|
8
|
+
exclusiveMinimum?: boolean;
|
|
9
|
+
exclusiveMaximum?: boolean;
|
|
10
|
+
default?: DefaultValue;
|
|
11
|
+
example?: ExampleValue;
|
|
12
|
+
paramName?: string;
|
|
13
|
+
isPath?: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Generates a Zod number schema string
|
|
17
|
+
* @param { GenerateZodNumberParams } args - The parameters to generate the zod number schema.
|
|
18
|
+
* @returns { string } Generated Zod number schema string
|
|
19
|
+
*/
|
|
20
|
+
export declare function generateZodNumber(args: GenerateZodNumberParams): string;
|
|
21
|
+
export {};
|