czh-api 1.0.6 → 1.0.7
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/CHANGELOG.md +49 -39
- package/dist/core/parser.js +11 -5
- package/package.json +1 -1
- package/src/core/parser.ts +146 -140
package/CHANGELOG.md
CHANGED
|
@@ -1,44 +1,54 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
-
所有重要的版本更新都会记录在此文件中。
|
|
4
|
-
|
|
5
|
-
## [1.0.
|
|
6
|
-
|
|
7
|
-
### 修复
|
|
8
|
-
-
|
|
9
|
-
- 修复
|
|
10
|
-
|
|
11
|
-
### 改进
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
-
|
|
19
|
-
- 修复 `
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
3
|
+
所有重要的版本更新都会记录在此文件中。
|
|
4
|
+
|
|
5
|
+
## [1.0.7] - 2026-05-19
|
|
6
|
+
|
|
7
|
+
### 修复
|
|
8
|
+
- 修复解析 Swagger 2.0 文档(如 Petstore)时报 `Cannot read properties of undefined (reading 'anyOf')` 的崩溃问题。
|
|
9
|
+
- 修复 Swagger 2.0 中 query/path 参数缺少 `schema` 属性时,属性值被存为 `undefined` 导致后续遍历异常的问题。
|
|
10
|
+
|
|
11
|
+
### 改进
|
|
12
|
+
- 兼容 Swagger 2.0 参数格式:当参数无 `schema` 字段时,自动从参数对象的 `type`/`format` 构造 schema,保留类型信息。
|
|
13
|
+
- 在 `extractJsdocParamsFromSchema` 中增加属性空值保护,避免异常 schema 结构导致整个构建流程中断。
|
|
14
|
+
|
|
15
|
+
## [1.0.6] - 2026-04-14
|
|
16
|
+
|
|
17
|
+
### 修复
|
|
18
|
+
- 修复部分模块在 schema 编译阶段因嵌套字段 `title` 含中文标点、空值或数字开头而生成非法类型别名的问题(如 `export type = ...`、`export type 12 = ...`)。
|
|
19
|
+
- 修复 `expert/groups`、`expert/customers` 等模块在同步解析时出现 `Declaration or statement expected` / `'{` expected` 报错的问题。
|
|
20
|
+
|
|
21
|
+
### 改进
|
|
22
|
+
- 在类型编译前新增 schema 预处理:递归移除嵌套 schema 的 `title`,仅保留顶层 schema 名称作为类型名来源,避免无效标识符影响 `json-schema-to-typescript` 生成结果。
|
|
23
|
+
|
|
24
|
+
## [1.0.5] - 2026-03-19
|
|
25
|
+
|
|
26
|
+
### 修复
|
|
27
|
+
- 修复 FastAPI 场景下返回类型字段被错误降级为 `any` 的问题(如 `items.$ref`、`anyOf`、`oneOf`、`allOf` 组合场景)。
|
|
28
|
+
- 修复数组响应与嵌套对象类型在 fallback 生成流程中丢失字段的问题,避免出现仅有 `{ [key: string]: any }` 的空壳接口。
|
|
29
|
+
- 修复 `group_ids` 等多层结构类型解析不完整的问题,支持递归解析到更深层级(如 `number[] | null`)。
|
|
30
|
+
- 修复类型增强阶段对复杂类型名(数组、联合类型)处理不稳定导致的类型声明异常问题。
|
|
31
|
+
|
|
32
|
+
### 改进
|
|
33
|
+
- 增强 fallback 类型生成策略:优先基于 `module.schemas` 还原字段结构,再回退到 `any`,生成结果更可用。
|
|
34
|
+
- 增强类型依赖收集能力:从字段类型表达式中提取嵌套引用类型并自动补齐声明。
|
|
35
|
+
- 完善 README 模板示例并与当前默认模板保持一致(`api.hbs`、`index.hbs`、`types.hbs`)。
|
|
36
|
+
|
|
37
|
+
## [1.0.4] - 2026-03-19
|
|
38
|
+
|
|
39
|
+
### 修复
|
|
40
|
+
- 修复响应最外层为数组(如 `type: array` + `items.$ref`)时类型生成异常的问题,避免出现非法接口声明(如 `export interface Xxx[]`)。
|
|
41
|
+
- 修复仅在“数组响应”中被引用的实体类型可能退化为 `{ [key: string]: any }` 的问题,增强该场景下的类型补全稳定性。
|
|
42
|
+
- 修复类型增强阶段对 `export interface` 的替换逻辑在存在内联对象字段时可能截断内容的问题,避免生成残留字段到接口外。
|
|
43
|
+
- 修复部分 OpenAPI `$ref` 路径在类型编译阶段解析不一致导致的类型降级问题(兼容 `#/components/schemas/*` 场景)。
|
|
44
|
+
|
|
45
|
+
### 改进
|
|
46
|
+
- 优化数组响应类型推导策略:当响应为 `$ref` 数组时优先生成 `ItemType[]`,减少中间响应类型噪音。
|
|
47
|
+
- 增强类型生成兜底逻辑的类型名合法性校验,避免对泛型/数组等复杂类型名误生成 `interface`。
|
|
48
|
+
|
|
49
|
+
## [1.0.3] - 2026-03-17
|
|
50
|
+
|
|
51
|
+
### 新增
|
|
42
52
|
- 添加 `pathPrefixes` 配置项,支持自定义路径前缀分组和二级分包
|
|
43
53
|
- 支持配置多个路径前缀,每个前缀可指定自定义包名或自动驼峰命名
|
|
44
54
|
- 自动按路径前缀后的第一级路径进行二级分包
|
package/dist/core/parser.js
CHANGED
|
@@ -148,7 +148,7 @@ function resolveSchemaToTypeScript(schema, allSchemas) {
|
|
|
148
148
|
return `${baseType}${nullable}`;
|
|
149
149
|
}
|
|
150
150
|
function extractJsdocParamsFromSchema(schema, allSchemas) {
|
|
151
|
-
var _a, _b;
|
|
151
|
+
var _a, _b, _c;
|
|
152
152
|
const params = [];
|
|
153
153
|
if (!schema)
|
|
154
154
|
return params;
|
|
@@ -163,9 +163,13 @@ function extractJsdocParamsFromSchema(schema, allSchemas) {
|
|
|
163
163
|
if (targetSchema === null || targetSchema === void 0 ? void 0 : targetSchema.properties) {
|
|
164
164
|
for (const propName in targetSchema.properties) {
|
|
165
165
|
const prop = targetSchema.properties[propName];
|
|
166
|
+
if (!prop) {
|
|
167
|
+
params.push({ name: propName, type: 'any', description: '', required: (_a = targetSchema.required) === null || _a === void 0 ? void 0 : _a.includes(propName) });
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
166
170
|
let propType = resolveSchemaToTypeScript(prop, allSchemas);
|
|
167
171
|
const propDescription = isReferenceObject(prop)
|
|
168
|
-
? (((
|
|
172
|
+
? (((_b = allSchemas[getSchemaName(prop.$ref)]) === null || _b === void 0 ? void 0 : _b.description) || '')
|
|
169
173
|
: ((prop === null || prop === void 0 ? void 0 : prop.description) || '');
|
|
170
174
|
// 处理 anyOf 数组 (FastAPI 常用的联合类型)
|
|
171
175
|
if (false && prop.anyOf && Array.isArray(prop.anyOf)) {
|
|
@@ -231,7 +235,7 @@ function extractJsdocParamsFromSchema(schema, allSchemas) {
|
|
|
231
235
|
name: propName,
|
|
232
236
|
type: propType || 'any',
|
|
233
237
|
description: propDescription,
|
|
234
|
-
required: (
|
|
238
|
+
required: (_c = targetSchema.required) === null || _c === void 0 ? void 0 : _c.includes(propName)
|
|
235
239
|
});
|
|
236
240
|
}
|
|
237
241
|
}
|
|
@@ -381,7 +385,8 @@ const processApi = (api, excludePaths = [], includePaths = [], pathPrefixes = []
|
|
|
381
385
|
// Collect params for the FormData body type
|
|
382
386
|
if (!formDataSchema.properties)
|
|
383
387
|
formDataSchema.properties = {};
|
|
384
|
-
|
|
388
|
+
const paramSchema = (param.schema || { type: param.type || 'string', format: param.format, description: param.description });
|
|
389
|
+
formDataSchema.properties[param.name] = paramSchema;
|
|
385
390
|
if (param.required) {
|
|
386
391
|
if (!formDataSchema.required)
|
|
387
392
|
formDataSchema.required = [];
|
|
@@ -392,7 +397,8 @@ const processApi = (api, excludePaths = [], includePaths = [], pathPrefixes = []
|
|
|
392
397
|
// Always collect path params
|
|
393
398
|
if (!paramsSchema.properties)
|
|
394
399
|
paramsSchema.properties = {};
|
|
395
|
-
|
|
400
|
+
const paramSchema = (param.schema || { type: param.type || 'string', format: param.format, description: param.description });
|
|
401
|
+
paramsSchema.properties[param.name] = paramSchema;
|
|
396
402
|
if (param.required) {
|
|
397
403
|
if (!paramsSchema.required)
|
|
398
404
|
paramsSchema.required = [];
|
package/package.json
CHANGED
package/src/core/parser.ts
CHANGED
|
@@ -111,7 +111,7 @@ function getModuleName(path: string, pathPrefixes: Array<{ path: string; package
|
|
|
111
111
|
return parts[0] || 'default';
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
function convertOpenApiTypeToTypeScript(openApiType: string | undefined): string {
|
|
114
|
+
function convertOpenApiTypeToTypeScript(openApiType: string | undefined): string {
|
|
115
115
|
if (!openApiType) return 'any';
|
|
116
116
|
|
|
117
117
|
switch (openApiType) {
|
|
@@ -125,88 +125,88 @@ function convertOpenApiTypeToTypeScript(openApiType: string | undefined): string
|
|
|
125
125
|
return 'boolean';
|
|
126
126
|
case 'string':
|
|
127
127
|
return 'string';
|
|
128
|
-
case 'number':
|
|
129
|
-
return 'number';
|
|
130
|
-
default:
|
|
131
|
-
return openApiType;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function resolveSchemaToTypeScript(
|
|
136
|
-
schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined,
|
|
137
|
-
allSchemas: { [key: string]: any }
|
|
138
|
-
): string {
|
|
139
|
-
if (!schema) return 'any';
|
|
140
|
-
|
|
141
|
-
if (isReferenceObject(schema)) {
|
|
142
|
-
return getSchemaName(schema.$ref) || 'any';
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (schema.anyOf && Array.isArray(schema.anyOf) && schema.anyOf.length > 0) {
|
|
146
|
-
const unionTypes = schema.anyOf
|
|
147
|
-
.map(item => resolveSchemaToTypeScript(item as OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject, allSchemas))
|
|
148
|
-
.filter(Boolean);
|
|
149
|
-
if (unionTypes.length > 0) {
|
|
150
|
-
return [...new Set(unionTypes)].join(' | ');
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (schema.oneOf && Array.isArray(schema.oneOf) && schema.oneOf.length > 0) {
|
|
155
|
-
const unionTypes = schema.oneOf
|
|
156
|
-
.map(item => resolveSchemaToTypeScript(item as OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject, allSchemas))
|
|
157
|
-
.filter(Boolean);
|
|
158
|
-
if (unionTypes.length > 0) {
|
|
159
|
-
return [...new Set(unionTypes)].join(' | ');
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (schema.allOf && Array.isArray(schema.allOf) && schema.allOf.length > 0) {
|
|
164
|
-
const intersectionTypes = schema.allOf
|
|
165
|
-
.map(item => resolveSchemaToTypeScript(item as OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject, allSchemas))
|
|
166
|
-
.filter(Boolean);
|
|
167
|
-
if (intersectionTypes.length > 0) {
|
|
168
|
-
return [...new Set(intersectionTypes)].join(' & ');
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (schema.type === 'array') {
|
|
173
|
-
const itemType = resolveSchemaToTypeScript(
|
|
174
|
-
schema.items as OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined,
|
|
175
|
-
allSchemas
|
|
176
|
-
);
|
|
177
|
-
return `${itemType || 'any'}[]`;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (schema.type === 'object') {
|
|
181
|
-
if (schema.properties && Object.keys(schema.properties).length > 0) {
|
|
182
|
-
const requiredSet = new Set(schema.required || []);
|
|
183
|
-
const inlineFields = Object.entries(schema.properties).map(([key, value]) => {
|
|
184
|
-
const fieldType = resolveSchemaToTypeScript(
|
|
185
|
-
value as OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject,
|
|
186
|
-
allSchemas
|
|
187
|
-
);
|
|
188
|
-
const optional = requiredSet.has(key) ? '' : '?';
|
|
189
|
-
return `${key}${optional}: ${fieldType || 'any'}`;
|
|
190
|
-
});
|
|
191
|
-
return `{ ${inlineFields.join('; ')} }`;
|
|
192
|
-
}
|
|
193
|
-
if (schema.additionalProperties) {
|
|
194
|
-
if (schema.additionalProperties === true) {
|
|
195
|
-
return 'Record<string, any>';
|
|
196
|
-
}
|
|
197
|
-
const valueType = resolveSchemaToTypeScript(
|
|
198
|
-
schema.additionalProperties as OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject,
|
|
199
|
-
allSchemas
|
|
200
|
-
);
|
|
201
|
-
return `Record<string, ${valueType || 'any'}>`;
|
|
202
|
-
}
|
|
203
|
-
return 'any';
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const baseType = convertOpenApiTypeToTypeScript(schema.type);
|
|
207
|
-
const nullable = schema.nullable ? ' | null' : '';
|
|
208
|
-
return `${baseType}${nullable}`;
|
|
209
|
-
}
|
|
128
|
+
case 'number':
|
|
129
|
+
return 'number';
|
|
130
|
+
default:
|
|
131
|
+
return openApiType;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function resolveSchemaToTypeScript(
|
|
136
|
+
schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined,
|
|
137
|
+
allSchemas: { [key: string]: any }
|
|
138
|
+
): string {
|
|
139
|
+
if (!schema) return 'any';
|
|
140
|
+
|
|
141
|
+
if (isReferenceObject(schema)) {
|
|
142
|
+
return getSchemaName(schema.$ref) || 'any';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (schema.anyOf && Array.isArray(schema.anyOf) && schema.anyOf.length > 0) {
|
|
146
|
+
const unionTypes = schema.anyOf
|
|
147
|
+
.map(item => resolveSchemaToTypeScript(item as OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject, allSchemas))
|
|
148
|
+
.filter(Boolean);
|
|
149
|
+
if (unionTypes.length > 0) {
|
|
150
|
+
return [...new Set(unionTypes)].join(' | ');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (schema.oneOf && Array.isArray(schema.oneOf) && schema.oneOf.length > 0) {
|
|
155
|
+
const unionTypes = schema.oneOf
|
|
156
|
+
.map(item => resolveSchemaToTypeScript(item as OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject, allSchemas))
|
|
157
|
+
.filter(Boolean);
|
|
158
|
+
if (unionTypes.length > 0) {
|
|
159
|
+
return [...new Set(unionTypes)].join(' | ');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (schema.allOf && Array.isArray(schema.allOf) && schema.allOf.length > 0) {
|
|
164
|
+
const intersectionTypes = schema.allOf
|
|
165
|
+
.map(item => resolveSchemaToTypeScript(item as OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject, allSchemas))
|
|
166
|
+
.filter(Boolean);
|
|
167
|
+
if (intersectionTypes.length > 0) {
|
|
168
|
+
return [...new Set(intersectionTypes)].join(' & ');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (schema.type === 'array') {
|
|
173
|
+
const itemType = resolveSchemaToTypeScript(
|
|
174
|
+
schema.items as OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined,
|
|
175
|
+
allSchemas
|
|
176
|
+
);
|
|
177
|
+
return `${itemType || 'any'}[]`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (schema.type === 'object') {
|
|
181
|
+
if (schema.properties && Object.keys(schema.properties).length > 0) {
|
|
182
|
+
const requiredSet = new Set(schema.required || []);
|
|
183
|
+
const inlineFields = Object.entries(schema.properties).map(([key, value]) => {
|
|
184
|
+
const fieldType = resolveSchemaToTypeScript(
|
|
185
|
+
value as OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject,
|
|
186
|
+
allSchemas
|
|
187
|
+
);
|
|
188
|
+
const optional = requiredSet.has(key) ? '' : '?';
|
|
189
|
+
return `${key}${optional}: ${fieldType || 'any'}`;
|
|
190
|
+
});
|
|
191
|
+
return `{ ${inlineFields.join('; ')} }`;
|
|
192
|
+
}
|
|
193
|
+
if (schema.additionalProperties) {
|
|
194
|
+
if (schema.additionalProperties === true) {
|
|
195
|
+
return 'Record<string, any>';
|
|
196
|
+
}
|
|
197
|
+
const valueType = resolveSchemaToTypeScript(
|
|
198
|
+
schema.additionalProperties as OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject,
|
|
199
|
+
allSchemas
|
|
200
|
+
);
|
|
201
|
+
return `Record<string, ${valueType || 'any'}>`;
|
|
202
|
+
}
|
|
203
|
+
return 'any';
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const baseType = convertOpenApiTypeToTypeScript(schema.type);
|
|
207
|
+
const nullable = schema.nullable ? ' | null' : '';
|
|
208
|
+
return `${baseType}${nullable}`;
|
|
209
|
+
}
|
|
210
210
|
|
|
211
211
|
function extractJsdocParamsFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject, allSchemas: { [key: string]: any }): Required<Endpoint>['jsdocParams'] {
|
|
212
212
|
const params: Required<Endpoint>['jsdocParams'] = [];
|
|
@@ -222,15 +222,19 @@ function extractJsdocParamsFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3
|
|
|
222
222
|
|
|
223
223
|
if (targetSchema?.properties) {
|
|
224
224
|
for (const propName in targetSchema.properties) {
|
|
225
|
-
const prop = targetSchema.properties[propName] as OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject;
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
225
|
+
const prop = targetSchema.properties[propName] as OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject;
|
|
226
|
+
if (!prop) {
|
|
227
|
+
params.push({ name: propName, type: 'any', description: '', required: targetSchema.required?.includes(propName) });
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
let propType = resolveSchemaToTypeScript(prop, allSchemas);
|
|
231
|
+
const propDescription = isReferenceObject(prop)
|
|
232
|
+
? ((allSchemas[getSchemaName(prop.$ref)] as OpenAPIV3.SchemaObject | undefined)?.description || '')
|
|
233
|
+
: (prop?.description || '');
|
|
230
234
|
|
|
231
235
|
// 处理 anyOf 数组 (FastAPI 常用的联合类型)
|
|
232
|
-
if (false && (prop as OpenAPIV3.SchemaObject).anyOf && Array.isArray((prop as OpenAPIV3.SchemaObject).anyOf)) {
|
|
233
|
-
const types = (prop as OpenAPIV3.SchemaObject).anyOf!.map(item => {
|
|
236
|
+
if (false && (prop as OpenAPIV3.SchemaObject).anyOf && Array.isArray((prop as OpenAPIV3.SchemaObject).anyOf)) {
|
|
237
|
+
const types = (prop as OpenAPIV3.SchemaObject).anyOf!.map(item => {
|
|
234
238
|
if (isReferenceObject(item)) {
|
|
235
239
|
return getSchemaName(item.$ref);
|
|
236
240
|
} else {
|
|
@@ -251,8 +255,8 @@ function extractJsdocParamsFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3
|
|
|
251
255
|
}
|
|
252
256
|
}
|
|
253
257
|
// 处理 oneOf 数组
|
|
254
|
-
else if (false && (prop as OpenAPIV3.SchemaObject).oneOf && Array.isArray((prop as OpenAPIV3.SchemaObject).oneOf)) {
|
|
255
|
-
const types = (prop as OpenAPIV3.SchemaObject).oneOf!.map(item => {
|
|
258
|
+
else if (false && (prop as OpenAPIV3.SchemaObject).oneOf && Array.isArray((prop as OpenAPIV3.SchemaObject).oneOf)) {
|
|
259
|
+
const types = (prop as OpenAPIV3.SchemaObject).oneOf!.map(item => {
|
|
256
260
|
if (isReferenceObject(item)) {
|
|
257
261
|
return getSchemaName(item.$ref);
|
|
258
262
|
} else {
|
|
@@ -273,26 +277,26 @@ function extractJsdocParamsFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3
|
|
|
273
277
|
}
|
|
274
278
|
}
|
|
275
279
|
// 处理普通类型
|
|
276
|
-
else if (false && (prop as OpenAPIV3.SchemaObject).type) {
|
|
277
|
-
const propSchema: any = prop as any;
|
|
278
|
-
if (propSchema.type === 'array' && propSchema.items) {
|
|
279
|
-
if (isReferenceObject(propSchema.items)) {
|
|
280
|
-
propType = `${getSchemaName(propSchema.items.$ref)}[]`;
|
|
281
|
-
} else {
|
|
282
|
-
const itemType = convertOpenApiTypeToTypeScript((propSchema.items as OpenAPIV3.SchemaObject).type);
|
|
283
|
-
propType = `${itemType}[]`;
|
|
284
|
-
}
|
|
285
|
-
} else {
|
|
286
|
-
propType = convertOpenApiTypeToTypeScript(propSchema.type);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
params.push({
|
|
291
|
-
name: propName,
|
|
292
|
-
type: propType || 'any',
|
|
293
|
-
description: propDescription,
|
|
294
|
-
required: targetSchema.required?.includes(propName)
|
|
295
|
-
});
|
|
280
|
+
else if (false && (prop as OpenAPIV3.SchemaObject).type) {
|
|
281
|
+
const propSchema: any = prop as any;
|
|
282
|
+
if (propSchema.type === 'array' && propSchema.items) {
|
|
283
|
+
if (isReferenceObject(propSchema.items)) {
|
|
284
|
+
propType = `${getSchemaName(propSchema.items.$ref)}[]`;
|
|
285
|
+
} else {
|
|
286
|
+
const itemType = convertOpenApiTypeToTypeScript((propSchema.items as OpenAPIV3.SchemaObject).type);
|
|
287
|
+
propType = `${itemType}[]`;
|
|
288
|
+
}
|
|
289
|
+
} else {
|
|
290
|
+
propType = convertOpenApiTypeToTypeScript(propSchema.type);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
params.push({
|
|
295
|
+
name: propName,
|
|
296
|
+
type: propType || 'any',
|
|
297
|
+
description: propDescription,
|
|
298
|
+
required: targetSchema.required?.includes(propName)
|
|
299
|
+
});
|
|
296
300
|
}
|
|
297
301
|
}
|
|
298
302
|
return params;
|
|
@@ -452,7 +456,8 @@ export const processApi = (api: OpenAPI.Document, excludePaths: string[] = [], i
|
|
|
452
456
|
} else if (isFormData && (param.in === 'query' || param.in === 'formData')) {
|
|
453
457
|
// Collect params for the FormData body type
|
|
454
458
|
if(!formDataSchema.properties) formDataSchema.properties = {};
|
|
455
|
-
|
|
459
|
+
const paramSchema = (param.schema || { type: (param as any).type || 'string', format: (param as any).format, description: param.description }) as OpenAPIV3.SchemaObject;
|
|
460
|
+
formDataSchema.properties[param.name] = paramSchema;
|
|
456
461
|
if(param.required) {
|
|
457
462
|
if(!formDataSchema.required) formDataSchema.required = [];
|
|
458
463
|
formDataSchema.required.push(param.name);
|
|
@@ -460,7 +465,8 @@ export const processApi = (api: OpenAPI.Document, excludePaths: string[] = [], i
|
|
|
460
465
|
} else if (param.in === 'path' || param.in === 'query') {
|
|
461
466
|
// Always collect path params
|
|
462
467
|
if(!paramsSchema.properties) paramsSchema.properties = {};
|
|
463
|
-
|
|
468
|
+
const paramSchema = (param.schema || { type: (param as any).type || 'string', format: (param as any).format, description: param.description }) as OpenAPIV3.SchemaObject;
|
|
469
|
+
paramsSchema.properties[param.name] = paramSchema;
|
|
464
470
|
if(param.required) {
|
|
465
471
|
if(!paramsSchema.required) paramsSchema.required = [];
|
|
466
472
|
paramsSchema.required.push(param.name);
|
|
@@ -558,31 +564,31 @@ export const processApi = (api: OpenAPI.Document, excludePaths: string[] = [], i
|
|
|
558
564
|
responseJsdocParams.push(...extractJsdocParamsFromSchema(schema, allSchemas));
|
|
559
565
|
} else if (schema && !isReferenceObject(schema)) {
|
|
560
566
|
const inlineSchema = schema as OpenAPIV3.SchemaObject;
|
|
561
|
-
if (inlineSchema.type === 'object' || inlineSchema.properties) {
|
|
562
|
-
// Generate a named type for inline response schema
|
|
563
|
-
const typeName = `${functionName.charAt(0).toUpperCase() + functionName.slice(1)}Response`;
|
|
564
|
-
responseTypeName = typeName;
|
|
565
|
-
modules[moduleName].schemas[typeName] = inlineSchema;
|
|
566
|
-
referencedTypes.push(typeName);
|
|
567
|
-
responseJsdocParams.push(...extractJsdocParamsFromSchema(inlineSchema, allSchemas));
|
|
568
|
-
} else if (inlineSchema.type === 'array' && inlineSchema.items) {
|
|
569
|
-
if (isReferenceObject(inlineSchema.items)) {
|
|
570
|
-
const itemSchemaName = getSchemaName(inlineSchema.items.$ref);
|
|
571
|
-
// Prefer direct `ItemType[]` for array responses to avoid unnecessary alias schema compilation.
|
|
572
|
-
responseTypeName = `${itemSchemaName}[]`;
|
|
573
|
-
referencedTypes.push(itemSchemaName);
|
|
574
|
-
addSchemaWithDependencies(itemSchemaName, modules[moduleName], allSchemas);
|
|
575
|
-
responseJsdocParams.push(...extractJsdocParamsFromSchema(inlineSchema.items, allSchemas));
|
|
576
|
-
} else {
|
|
577
|
-
const typeName = `${functionName.charAt(0).toUpperCase() + functionName.slice(1)}Response`;
|
|
578
|
-
responseTypeName = typeName;
|
|
579
|
-
modules[moduleName].schemas[typeName] = inlineSchema;
|
|
580
|
-
referencedTypes.push(typeName);
|
|
581
|
-
responseJsdocParams.push(...extractJsdocParamsFromSchema(inlineSchema, allSchemas));
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
567
|
+
if (inlineSchema.type === 'object' || inlineSchema.properties) {
|
|
568
|
+
// Generate a named type for inline response schema
|
|
569
|
+
const typeName = `${functionName.charAt(0).toUpperCase() + functionName.slice(1)}Response`;
|
|
570
|
+
responseTypeName = typeName;
|
|
571
|
+
modules[moduleName].schemas[typeName] = inlineSchema;
|
|
572
|
+
referencedTypes.push(typeName);
|
|
573
|
+
responseJsdocParams.push(...extractJsdocParamsFromSchema(inlineSchema, allSchemas));
|
|
574
|
+
} else if (inlineSchema.type === 'array' && inlineSchema.items) {
|
|
575
|
+
if (isReferenceObject(inlineSchema.items)) {
|
|
576
|
+
const itemSchemaName = getSchemaName(inlineSchema.items.$ref);
|
|
577
|
+
// Prefer direct `ItemType[]` for array responses to avoid unnecessary alias schema compilation.
|
|
578
|
+
responseTypeName = `${itemSchemaName}[]`;
|
|
579
|
+
referencedTypes.push(itemSchemaName);
|
|
580
|
+
addSchemaWithDependencies(itemSchemaName, modules[moduleName], allSchemas);
|
|
581
|
+
responseJsdocParams.push(...extractJsdocParamsFromSchema(inlineSchema.items, allSchemas));
|
|
582
|
+
} else {
|
|
583
|
+
const typeName = `${functionName.charAt(0).toUpperCase() + functionName.slice(1)}Response`;
|
|
584
|
+
responseTypeName = typeName;
|
|
585
|
+
modules[moduleName].schemas[typeName] = inlineSchema;
|
|
586
|
+
referencedTypes.push(typeName);
|
|
587
|
+
responseJsdocParams.push(...extractJsdocParamsFromSchema(inlineSchema, allSchemas));
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
586
592
|
|
|
587
593
|
// Convert path to template literal string for path parameters
|
|
588
594
|
const urlTemplate = path.replace(/\{(\w+)\}/g, '${params.$1}');
|
|
@@ -610,4 +616,4 @@ export const processApi = (api: OpenAPI.Document, excludePaths: string[] = [], i
|
|
|
610
616
|
}
|
|
611
617
|
|
|
612
618
|
return modules;
|
|
613
|
-
};
|
|
619
|
+
};
|