Skip to content

Commit 0c41c2b

Browse files
committed
Refactor type imports and move schema types to types.d.ts
Moved all schema-related type definitions from utils.ts to types.d.ts for better separation and maintainability. Updated imports in index.ts and plugin.ts to reference types from types.d.ts. Bumped package version to 0.5.8.
1 parent 5a50da4 commit 0c41c2b

File tree

5 files changed

+85
-72
lines changed

5 files changed

+85
-72
lines changed

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {JSONSchemaFaker} from 'json-schema-faker'
22
import type { Schema} from 'json-schema-faker'
3-
import type { BuilderOptions } from './utils'
3+
import type { BuilderOptions } from './types'
44

55
export interface JSFOptions {
66
useDefaultValue?: boolean

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hey-api-builders",
3-
"version": "0.5.7",
3+
"version": "0.5.8",
44
"description": "A custom plugin for @hey-api/openapi-ts that wraps JSON Schema Faker to generate builders.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { collectSchemas, generateWithMethods } from './utils';
2-
import type { BuildersHandler } from './utils';
2+
import type { BuildersHandler } from './types';
33
import type { IR } from '@hey-api/openapi-ts';
44

55
export const handler: BuildersHandler = ({ plugin }) => {

types.d.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {DefinePlugin} from "@hey-api/openapi-ts";
2+
import type { IR } from '@hey-api/openapi-ts';
3+
import type { Schema } from 'json-schema-faker';
24

35
export interface Config {
46
/**
@@ -20,3 +22,72 @@ export interface Config {
2022
}
2123

2224
export type BuildersPlugin = DefinePlugin<Config>
25+
26+
// Schema-related types moved from utils.ts
27+
export interface BuilderOptions {
28+
useDefault?: boolean;
29+
useExamples?: boolean;
30+
alwaysIncludeOptionals?: boolean;
31+
optionalsProbability?: number | false;
32+
omitNulls?: boolean;
33+
}
34+
35+
export interface GeneratedSchemaMeta {
36+
typeName: string;
37+
constName: string;
38+
isEnum: boolean;
39+
schema: Schema;
40+
isObject: boolean;
41+
}
42+
43+
export interface EnumSchemaObject {
44+
enum?: JsonValue[];
45+
type?: string | 'enum';
46+
items?: EnumItem[] | IR.SchemaObject | IR.SchemaObject[];
47+
nullable?: boolean;
48+
$ref?: string;
49+
properties?: Record<string, IR.SchemaObject>;
50+
required?: string[];
51+
additionalProperties?: boolean | IR.SchemaObject;
52+
allOf?: IR.SchemaObject[];
53+
anyOf?: IR.SchemaObject[];
54+
oneOf?: IR.SchemaObject[];
55+
[key: string]: unknown;
56+
}
57+
58+
export interface EnumItem {
59+
const: JsonValue;
60+
description?: string;
61+
}
62+
63+
export type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };
64+
65+
export interface ExtendedSchema {
66+
type?: 'null' | 'boolean' | 'object' | 'array' | 'number' | 'string' | 'integer' | Array<'null' | 'boolean' | 'object' | 'array' | 'number' | 'string' | 'integer'>;
67+
properties?: Record<string, Schema>;
68+
required?: string[];
69+
additionalProperties?: boolean | Schema;
70+
items?: Schema | Schema[];
71+
allOf?: Schema[];
72+
anyOf?: Schema[];
73+
oneOf?: Schema[];
74+
enum?: JsonValue[];
75+
nullable?: boolean;
76+
[key: string]: unknown;
77+
}
78+
79+
export interface NormalizedSchemaNode {
80+
type?: 'null' | 'boolean' | 'object' | 'array' | 'number' | 'string' | 'integer' | 'enum' | Array<'null' | 'boolean' | 'object' | 'array' | 'number' | 'string' | 'integer'>;
81+
items?: NormalizedSchemaNode | NormalizedSchemaNode[];
82+
properties?: Record<string, NormalizedSchemaNode>;
83+
additionalProperties?: boolean | NormalizedSchemaNode;
84+
allOf?: NormalizedSchemaNode[];
85+
anyOf?: NormalizedSchemaNode[];
86+
oneOf?: NormalizedSchemaNode[];
87+
enum?: JsonValue[];
88+
logicalOperator?: string;
89+
const?: JsonValue;
90+
[key: string]: unknown;
91+
}
92+
93+
export type BuildersHandler = BuildersPlugin['Handler'];

utils.ts

Lines changed: 11 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,16 @@
11
import type { IR } from '@hey-api/openapi-ts';
2-
import type { BuildersPlugin } from './types';
32
import type { Schema } from 'json-schema-faker';
4-
5-
export interface BuilderOptions {
6-
useDefault?: boolean;
7-
useExamples?: boolean;
8-
alwaysIncludeOptionals?: boolean;
9-
optionalsProbability?: number | false;
10-
omitNulls?: boolean;
11-
}
12-
13-
export interface GeneratedSchemaMeta {
14-
typeName: string;
15-
constName: string;
16-
isEnum: boolean;
17-
schema: Schema;
18-
isObject: boolean;
19-
}
20-
21-
interface EnumSchemaObject {
22-
enum?: JsonValue[];
23-
type?: string | 'enum';
24-
items?: EnumItem[] | IR.SchemaObject | IR.SchemaObject[];
25-
nullable?: boolean;
26-
$ref?: string;
27-
properties?: Record<string, IR.SchemaObject>;
28-
required?: string[];
29-
additionalProperties?: boolean | IR.SchemaObject;
30-
allOf?: IR.SchemaObject[];
31-
anyOf?: IR.SchemaObject[];
32-
oneOf?: IR.SchemaObject[];
33-
[key: string]: unknown;
34-
}
35-
36-
interface EnumItem {
37-
const: JsonValue;
38-
description?: string;
39-
}
40-
41-
type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };
42-
43-
interface ExtendedSchema {
44-
type?: 'null' | 'boolean' | 'object' | 'array' | 'number' | 'string' | 'integer' | Array<'null' | 'boolean' | 'object' | 'array' | 'number' | 'string' | 'integer'>;
45-
properties?: Record<string, Schema>;
46-
required?: string[];
47-
additionalProperties?: boolean | Schema;
48-
items?: Schema | Schema[];
49-
allOf?: Schema[];
50-
anyOf?: Schema[];
51-
oneOf?: Schema[];
52-
enum?: JsonValue[];
53-
nullable?: boolean;
54-
[key: string]: unknown;
55-
}
56-
57-
interface NormalizedSchemaNode {
58-
type?: 'null' | 'boolean' | 'object' | 'array' | 'number' | 'string' | 'integer' | 'enum' | Array<'null' | 'boolean' | 'object' | 'array' | 'number' | 'string' | 'integer'>;
59-
items?: NormalizedSchemaNode | NormalizedSchemaNode[];
60-
properties?: Record<string, NormalizedSchemaNode>;
61-
additionalProperties?: boolean | NormalizedSchemaNode;
62-
allOf?: NormalizedSchemaNode[];
63-
anyOf?: NormalizedSchemaNode[];
64-
oneOf?: NormalizedSchemaNode[];
65-
enum?: JsonValue[];
66-
logicalOperator?: string;
67-
const?: JsonValue;
68-
[key: string]: unknown;
69-
}
3+
import type {
4+
BuildersPlugin,
5+
BuilderOptions,
6+
GeneratedSchemaMeta,
7+
EnumSchemaObject,
8+
EnumItem,
9+
JsonValue,
10+
ExtendedSchema,
11+
NormalizedSchemaNode,
12+
BuildersHandler
13+
} from './types';
7014

7115
export function irToSchema(
7216
ir: IR.SchemaObject,
@@ -307,5 +251,3 @@ export function generateWithMethods(schema: Schema, typeName: string): string {
307251
.map(p => ` with${toPascal(p)}(value: types.${typeName}["${p}"]): this { this.overrides["${p}"] = value; return this; }`)
308252
.join('\n');
309253
}
310-
311-
export type BuildersHandler = BuildersPlugin['Handler'];

0 commit comments

Comments
 (0)