Skip to content

Commit d239fca

Browse files
Merge pull request #425 from openapi-ui/main
chore: merge main to release
2 parents 8f28b18 + 2d2925a commit d239fca

30 files changed

+1587
-1577
lines changed

.changeset/red-cups-sniff.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openapi-ts-request': patch
3+
---
4+
5+
perf: typeName upperFist

src/generator/serviceGenarator.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
isFunction,
1313
isObject,
1414
keys,
15+
lowerFirst,
1516
map,
1617
upperFirst,
1718
} from 'lodash';
@@ -238,9 +239,10 @@ export default class ServiceGenerator {
238239
}
239240
}
240241

242+
const tagTypeName = resolveTypeName(tag);
241243
const tagKey = this.config.isCamelCase
242-
? camelCase(resolveTypeName(tag))
243-
: resolveTypeName(tag);
244+
? camelCase(tagTypeName)
245+
: lowerFirst(tagTypeName);
244246

245247
if (!this.apiData[tagKey]) {
246248
this.apiData[tagKey] = [];
@@ -610,7 +612,7 @@ export default class ServiceGenerator {
610612

611613
if (this.config.isGenJsonSchemas) {
612614
this.schemaList.push({
613-
typeName: `$${resolveTypeName(schemaKey)}`,
615+
typeName: `$${lowerFirst(resolveTypeName(schemaKey))}`,
614616
type: JSON.stringify(
615617
patchSchema<SchemaObject>(
616618
schema,
@@ -933,7 +935,9 @@ export default class ServiceGenerator {
933935
const typeName =
934936
this.config?.hook?.customTypeName?.(data) || this.getFunctionName(data);
935937

936-
return resolveTypeName(`${namespace}${typeName ?? data.operationId}Params`);
938+
return upperFirst(
939+
resolveTypeName(`${namespace}${typeName ?? data.operationId}Params`)
940+
);
937941
}
938942

939943
private getBodyTP(requestBody: RequestBodyObject, namespace?: string) {

src/generator/util.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
isUndefined,
1515
keys,
1616
map,
17+
upperFirst,
1718
} from 'lodash';
1819
import ReservedDict from 'reserved-words';
1920
import pinyin from 'tiny-pinyin';
@@ -97,12 +98,12 @@ export function resolveTypeName(typeName: string) {
9798
}
9899

99100
if (!/[\u3220-\uFA29]/.test(name) && !/^\d$/.test(name)) {
100-
return name;
101+
return upperFirst(name);
101102
}
102103

103104
const noBlankName = name.replace(/ +/g, '');
104105

105-
return pinyin.convertToPinyin(noBlankName, '', true);
106+
return upperFirst(pinyin.convertToPinyin(noBlankName, '', true));
106107
}
107108

108109
export function getRefName(refObject: ReferenceObject | string) {

test/__snapshots__/common/小驼峰命名文件和请求函数.snap

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export async function petPetIdUsingGet({
6767
options,
6868
}: {
6969
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
70-
params: API.petPetIdUsingGetParams;
70+
params: API.PetPetIdUsingGetParams;
7171
options?: { [key: string]: unknown };
7272
}) {
7373
const { petId: param0, ...queryParams } = params;
@@ -85,7 +85,7 @@ export async function petPetIdUsingPost({
8585
options,
8686
}: {
8787
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
88-
params: API.petPetIdUsingPostParams;
88+
params: API.PetPetIdUsingPostParams;
8989
options?: { [key: string]: unknown };
9090
}) {
9191
const { petId: param0, ...queryParams } = params;
@@ -105,7 +105,7 @@ export async function petPetIdUsingDelete({
105105
options,
106106
}: {
107107
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
108-
params: API.petPetIdUsingDeleteParams;
108+
params: API.PetPetIdUsingDeleteParams;
109109
options?: { [key: string]: unknown };
110110
}) {
111111
const { petId: param0, ...queryParams } = params;
@@ -124,7 +124,7 @@ export async function petPetIdUploadImageUsingPost({
124124
options,
125125
}: {
126126
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
127-
params: API.petPetIdUploadImageUsingPostParams;
127+
params: API.PetPetIdUploadImageUsingPostParams;
128128
body: API.PetPetIdUploadImageUsingPostBody;
129129
options?: { [key: string]: unknown };
130130
}) {
@@ -149,7 +149,7 @@ export async function petFindByStatusUsingGet({
149149
options,
150150
}: {
151151
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
152-
params: API.petFindByStatusUsingGetParams;
152+
params: API.PetFindByStatusUsingGetParams;
153153
options?: { [key: string]: unknown };
154154
}) {
155155
return request<API.Pet[]>('/pet/findByStatus', {
@@ -169,7 +169,7 @@ export async function petFindByTagsUsingGet({
169169
options,
170170
}: {
171171
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
172-
params: API.petFindByTagsUsingGetParams;
172+
params: API.PetFindByTagsUsingGetParams;
173173
options?: { [key: string]: unknown };
174174
}) {
175175
return request<API.Pet[]>('/pet/findByTags', {
@@ -222,7 +222,7 @@ export async function storeOrderOrderIdUsingGet({
222222
options,
223223
}: {
224224
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
225-
params: API.storeOrderOrderIdUsingGetParams;
225+
params: API.StoreOrderOrderIdUsingGetParams;
226226
options?: { [key: string]: unknown };
227227
}) {
228228
const { orderId: param0, ...queryParams } = params;
@@ -240,7 +240,7 @@ export async function storeOrderOrderIdUsingDelete({
240240
options,
241241
}: {
242242
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
243-
params: API.storeOrderOrderIdUsingDeleteParams;
243+
params: API.StoreOrderOrderIdUsingDeleteParams;
244244
options?: { [key: string]: unknown };
245245
}) {
246246
const { orderId: param0, ...queryParams } = params;
@@ -285,36 +285,36 @@ export type Pet = {
285285
status?: 'available' | 'pending' | 'sold';
286286
};
287287

288-
export type petFindByStatusUsingGetParams = {
288+
export type PetFindByStatusUsingGetParams = {
289289
/** Status values that need to be considered for filter */
290290
status?: 'available' | 'pending' | 'sold';
291291
};
292292

293-
export type petFindByTagsUsingGetParams = {
293+
export type PetFindByTagsUsingGetParams = {
294294
/** Tags to filter by */
295295
tags?: string[];
296296
};
297297

298298
export type PetPetIdUploadImageUsingPostBody = string;
299299

300-
export type petPetIdUploadImageUsingPostParams = {
300+
export type PetPetIdUploadImageUsingPostParams = {
301301
/** ID of pet to update */
302302
petId: number;
303303
/** Additional Metadata */
304304
additionalMetadata?: string;
305305
};
306306

307-
export type petPetIdUsingDeleteParams = {
307+
export type PetPetIdUsingDeleteParams = {
308308
/** Pet id to delete */
309309
petId: number;
310310
};
311311

312-
export type petPetIdUsingGetParams = {
312+
export type PetPetIdUsingGetParams = {
313313
/** ID of pet to return */
314314
petId: number;
315315
};
316316

317-
export type petPetIdUsingPostParams = {
317+
export type PetPetIdUsingPostParams = {
318318
/** ID of pet that needs to be updated */
319319
petId: number;
320320
/** Name of pet that needs to be updated */
@@ -339,12 +339,12 @@ export enum StatusEnum2 {
339339

340340
export type IStatusEnum2 = keyof typeof StatusEnum2;
341341

342-
export type storeOrderOrderIdUsingDeleteParams = {
342+
export type StoreOrderOrderIdUsingDeleteParams = {
343343
/** ID of the order that needs to be deleted */
344344
orderId: number;
345345
};
346346

347-
export type storeOrderOrderIdUsingGetParams = {
347+
export type StoreOrderOrderIdUsingGetParams = {
348348
/** ID of order that needs to be fetched */
349349
orderId: number;
350350
};
@@ -368,24 +368,24 @@ export type User = {
368368

369369
export type UserCreateWithListUsingPostBody = User[];
370370

371-
export type userLoginUsingGetParams = {
371+
export type UserLoginUsingGetParams = {
372372
/** The user name for login */
373373
username?: string;
374374
/** The password for login in clear text */
375375
password?: string;
376376
};
377377

378-
export type userUsernameUsingDeleteParams = {
378+
export type UserUsernameUsingDeleteParams = {
379379
/** The name that needs to be deleted */
380380
username: string;
381381
};
382382

383-
export type userUsernameUsingGetParams = {
383+
export type UserUsernameUsingGetParams = {
384384
/** The name that needs to be fetched. Use user1 for testing. */
385385
username: string;
386386
};
387387

388-
export type userUsernameUsingPutParams = {
388+
export type UserUsernameUsingPutParams = {
389389
/** name that needs to be updated */
390390
username: string;
391391
};
@@ -419,7 +419,7 @@ export async function userUsernameUsingGet({
419419
options,
420420
}: {
421421
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
422-
params: API.userUsernameUsingGetParams;
422+
params: API.UserUsernameUsingGetParams;
423423
options?: { [key: string]: unknown };
424424
}) {
425425
const { username: param0, ...queryParams } = params;
@@ -438,7 +438,7 @@ export async function userUsernameUsingPut({
438438
options,
439439
}: {
440440
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
441-
params: API.userUsernameUsingPutParams;
441+
params: API.UserUsernameUsingPutParams;
442442
body: API.User;
443443
options?: { [key: string]: unknown };
444444
}) {
@@ -461,7 +461,7 @@ export async function userUsernameUsingDelete({
461461
options,
462462
}: {
463463
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
464-
params: API.userUsernameUsingDeleteParams;
464+
params: API.UserUsernameUsingDeleteParams;
465465
options?: { [key: string]: unknown };
466466
}) {
467467
const { username: param0, ...queryParams } = params;
@@ -497,7 +497,7 @@ export async function userLoginUsingGet({
497497
options,
498498
}: {
499499
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
500-
params: API.userLoginUsingGetParams;
500+
params: API.UserLoginUsingGetParams;
501501
options?: { [key: string]: unknown };
502502
}) {
503503
return request<string>('/user/login', {

0 commit comments

Comments
 (0)